hw3_solutions_final_withrubric

# Answer the measure is top bot in one of the recursive

This preview shows pages 3–5. Sign up to view the full content.

decreases by at least 1 with each recursive call. Answer The measure is top - bot . In one of the recursive calls it decreases to mid - bot = 3 bot +2 top 5 - bot = 2( top - bot ) 5 in the other to top - mid - 1 = top - 3 bot +2 top 5 - 1 = 3( top - bot ) 5 - 1. Observe that both 2( top - bot ) 5 and 3( top - bot ) 5 - 1 are at most top - bot - 1 when top - bot 1. When top - bot < 1 it’s the last recursive call anyway. (b) Analyze the code and give and give a Big-Oh characterization of the running time of twoThreeSearch . Explain your analysis. Answer This is like the analysis of binary in the lecture notes but the recurrence relation is a little different. To analyze the running time of aux , let n = top - bot and let T ( n ) be the running time of aux . In the worst case , the recursive call is always the one that then searches in the larger array portion, the one of size 3 n 5 . This sets up the following recurrence relation T ( n ) = T ( 3 n 5 ) + c Let ω = 5 3 . Just like in the lecture notes we assumed that n is a power of 2 we will assume here that n is a power of ω that is n = ω k We write T ( n ) = T ( n/ω ) + c T ( n/ω ) = T ( n/ω 2 ) + c · · · = · · · T ( ω ) = T (1) + c and when we add them up and simplify we get T ( n ) = T (1) + c k . Now T (1) is a constant (does not depend on n ). and k = log ω n = log n log ω . Therefore T ( n ) is O (log n ) and twoThreeSearch runs in O (log m ) where m is the size of its input array. This is the same asymptotic complexity as binary search. (a) - 7 points 4 points for a reasonable explanation 3 more points if mentioned ”measure” (b) - 13 points 4 points for correct recurrence relation 3 points for actually solving it 3 points for correct big-Oh bound 3 points for explanation Problem 3: 10 points In this problem you are NOT allowed to use the theorems about Big-Oh stated in the lecture notes. Your proof should follow just from the definition of Big-Oh. 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Prove that for any f ( n ) (as usual mapping nonnegative reals to strictly positive reals) if f ( n ) is O ( n n ) then log f ( n ) is O ( n log n ). Answer From f ( n ) is O ( n n ) it follows that there exist N, c > 0 such that for all n N we have f ( n ) cn n . Taking the log (which is monotone) we have log f ( n ) n log n + log c . Let’s take N 0 = max( N, c, 1). Then, for any n N 0 we have log f ( n ) n log n + log c n log n + log n n log n + n log n = 2 n log n so we can take c 0 = 2 and thus for all n N 0 we have log f ( n ) c 0 n log n . Therefore, log f ( n ) is O ( n log n ). 5 pts for general proof 3 pts for taking care of constants N and c 2 pts for starting with definition of Big O Problem 4: 20 points Prove that there exist two functions f ( n ) and g ( n ) that map nonnegative real numbers to positive real numbers such that neither f ( n ) is O ( g ( n )) nor f ( n ) is Ω( g ( n )) Answer Consider f ( n ) = 2 n and consider g ( n ) to be such that for any even natural number n , f ( n ) = n 2 , on all other real nonnegative arguments n we have g ( n ) = 1. Then we have that: f ( n ) is not O ( g ( n )) because for any N, c > 0 we can find an n 0 N that is not an even natural number such that 2 n 0 > c . For example, take n 0 to be an odd natural number bigger than N and strictly bigger than log c .
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern