(Solved):Consider the following algorithm to answer the questions below. //Input: A nonnegative integer. //Output: Greatest common divisor of m and n S — 0 for i – 1 to n do S — S + i*i return S a. Wh… View Answer…

 

Question

Consider the following algorithm to answer the questions below.

//Input: A nonnegative integer.

//Output: Greatest common divisor of m and n

S <– 0

for i <- 1 to n do

    S <– S + i*i

return S

a. What does the algorithm compute?
b. What is its basic operation?
c. How many times is the basic operation executed?
d. What is the efficiency class of this algorithm?
e. Suggest an improvement, or a better algorithm altogether, and indicate

Scroll to top