Link to home
Start Free TrialLog in
Avatar of Eindoofus
Eindoofus

asked on

What is the running time complexity of the given function?

The following question is one of the questions from an in-class homework assignment page that I don't believe we ever went over:

What is the running time complexity of the given function?
 
          int mystry(int n) {
                if  ( n == 0 ) return 0 ;
                return 1+ mystry(n/2) ;
          }

Open in new window


Could you please also give me a quick explanation of how this type of proplem is solved?
Avatar of d-glitch
d-glitch
Flag of United States of America image

You have to simulate the function processing by hand.

How many times do you execute the loop if n=8, 16, ... for example?
ASKER CERTIFIED SOLUTION
Avatar of phoffric
phoffric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial