Algorithms | Divide and Conquer | Question 5

Consider a situation where you don’t have function to calculate power (pow() function in C) and you need to calculate x^n where x can be any number and n is a positive integer. What can be the best possible time complexity of your power function?
(A) O(n)
(B) O(nLogn)
(C) O(LogLogn)
(D) O(Logn)


Answer: (D)

Explanation: We can calculate power using divide and conquer in O(Logn) time. See https://www.geeksforgeeks.org/write-a-c-program-to-calculate-powxn/.


Quiz of this Question

My Personal Notes arrow_drop_up