Check ALL correct statments about the following algorithms. procedure double(n: positive integer) while n > 0 begin n := 2n end output(n)
A. When n=5 is the input, the while loop is infinite. B. When n=5 is the input, n=10 is the final output of the algorithm. C. This algorithm lacks finiteness.
procedure divide(n: positive integer) while begin m := 1/n n := n - 1 end output(m)
A. This algorithm lacks definateness since division by zero occurs. B. When n=1 is the input, on the second iteration of the while loop a division by zero occurs. C. When n=1 is the input, after the first iteration of the while loop we have m=1 and n=0. D. When n=1 is the input, the algorithm exits the while loop after the first iteration and outputs m=1. E. This algorithm works and always outputs 1. F. This algorithm works and outputs 1/n.
procedure sum(n: positive integer) sum := 0 while i < 10 begin sum := sum + i end output(sum)
A. If i is initialized to the value 1 in the begining of the algorithm, the algorithm works and outputs . B. If i is initialized to the value 1 in the begining of the algorithm, the algorithm works and outputs 1. C. If i is initialized to the value 1 in the begining of the algorithm, the algorithm is still not finite since it gets stuck in an infinite while loop. D. This algorithm does not seem to use the input n. E. This algorithm lacks preciseness since the value of i is not initialized. F. If i is initialized to the value 1 in the begining of the algorithm, the algorithm works and outputs .
You can earn partial credit on this problem.