Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Determine the equation for T(n) in both codes and explain how you got it. Then solve in terms of Big O notation O(n) and O(logn).

Determine the equation for T(n) in both codes and explain how you got it. Then solve in terms of Big O notation O(n) and O(logn). Show steps for solving for Big O notation.image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions