Question: 7. If f(n) is a function that gives the run time for an algorithm on inputs of size n, it's natural to assume that f(n)

 7. If f(n) is a function that gives the run time

7. If f(n) is a function that gives the run time for an algorithm on inputs of size n, it's natural to assume that f(n) is increasing, that is, bigger inputs take more time to process. But not all functions are increasing. Suppose we define f(n) = 1 when n is even and f(n) =n2 when n is odd. If you look at the sequence of values of f, they would be: 12,1,3, 1,5, 1,7,1,9-, 1.,... a) Explain why f(n) = 0(n2), using the definition of Big O. b) Explain why f(n) (n2), using the definition. (That is, it is not possible to find a positive constant c such that f(n) 2 en2 for all large enough values of n, no matter how small you make c.) c) write a function, int g(int n), whose run time for n > 0 is (f(n), where f(n) is the function given above. Your function doesn't need to do ahything interesting. (Note that since f(n) (n2) but f(n)(n2), it is also true that f(n) 6(). According to the definition on page 39 of the textbook, this means that f(n)

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!