What is the running time of the following algorithm def surp
What is the running time of the following algorithm? def surprise(A, B): while (B! = 0): remainder = A % B A = B B = remainder return A Select one: O(log N) O(A%B) Incorrect O(1) O(N)
Solution
Answer:
a. O(logN)
As we divide the element and division takes logarithmic time. So the wile loop keep on checking the condition and it is running till the N value. So the operation A%B will take O(logN) time.
