Question: Task: Explain why codes have time complexity of O(n) and O(logn). Also, explain why it does not have the other time complexities. Can use master

Task: Explain why codes have time complexity of O(n) and O(logn). Also, explain why it does not have the other time complexities. Can use master theorem to explain.Task: Explain why codes have time complexity of O(n) and O(logn). Also,explain why it does not have the other time complexities. Can use

C++ Java Python3 C# > /* Function to calculate x raised to the power y in O(logn)*/ int power(int x, unsigned int y) int temp if( y == @) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp* temp; else return x temp* temp; } o // This code is contributed by Shubhamsinghie Time Complexity of optimized solution: 0(logn) Let us extend the pow function to work for negative y and float x. // C++ program to calculate pow(x,n) #include using namespace std; class gfs { /* Function to calculate x raised to the power y */ public: int power(int x, unsigned int y) { if (y == 0) return 1; else if (y % 2 == 0) return power(x, y / 2) * power(x, y / 2); else return x. power(x, y / 2) * power(x, y / 2); } /* Driver code */ int main() { gfg gi int x = 2; unsigned int y = 3; cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!