{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw1solution

hw1solution - ∑ n i =1 logi log 2 = ∑ n i =1 log(2 i =...

This preview shows pages 1–2. Sign up to view the full content.

CSC 316 Data Structures Homework 1 ANSWERS 1. (10 points) Answer: * c is a real constant such that c > 0 and n 0 is an integer constant such that n 0 1 (a) c = 1, n 0 = 1 (b) c = 1, n 0 = 1 (c) c = 1, n 0 = 1 (d) c 0 = 2, n 0 = 2 n 2 2 * ( n 2 - 1) for n 2 c 00 = 1, n 0 = 1 n 2 1 * ( n 2 - 1) for n 1 (e) c = 1, n 0 = 1 2. (10 points) Answer: (a) False, if f ( n ) = n , g ( n ) = n 2 , then n = O ( n 2 ) but n 2 6 = O ( n ) (b) True. (c) False, if f ( n ) = 1 /n , then 1 /n 6 = O (1 /n 2 ) (d) True. (e) False, if f ( n ) = 4 n , then 4 n 6 = O (2 n ), so f ( n ) 6 = Θ( f ( n/ 2)). 3. (10 points) Answer: From faster to slower (1) 2 10 = O (1) (2) 3 n + 100 logn = O ( n ), 4 n = O ( n ), 2 logn = O ( n ) (3) nlogn = O ( nlogn ), 4 nlogn + 2 n = O ( nlogn ) (4) n 2 + 10 n = O ( n 2 ) (5) n 3 = O ( n 3 ) (6) 2 n = O (2 n ) 4. (10 points) Answer: (1) n 2 (2) N (3) Find2D is a linear-time algorithm since it depends on input size of N 1

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

View Full Document
5. (5 points) Answer: Since: lim n →∞ n 2 nlogn by using L’ Hopital’s Rule lim n →∞ 2 n ( logn + n * (1 /n )) = Hence: n 2 = Ω( nlogn ) 6. (5 points) Answer: ( n + 1) 5 = n 5 + 5 n 4 + 10 n 3 + 10 n 2 + 5 n + 1 Since n 5 + 5 n 4 + 10 n 3 + 10 n 2 + 5 n + 1 (1 + 5 + 10 + 10 + 5 + 1) n 5 , for n 1 Hence ( n + 1) 5 = O ( n 5 ) . Or Since lim n - >infinite ( n +1) 5 n 5 = 1 Hence: ( n + 1) 5 = Θ( n 5 ) Hence: ( n + 1) 5 = O ( n 5 ) 7. (5 points) Answer: n i =1 d log 2 i e ≤
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ∑ n i =1 ( logi + log 2) = ∑ n i =1 log (2 i ) = log 2 + log 4 + log 6 + ... + log 2 n ≤ nlog (2 n ) = nlog ( n ) + nlog 2 Hence : ∑ n i =1 d log 2 i e = O ( nlogn ) d x e give smallest integer larger than or equal to x . So ∑ n i =1 d log 2 i e is not always same as ∑ n i =1 log 2 i 8. (5 points) Answer: Since: d ( n ) ≤ c * f ( n ) for n ≥ n , c > 0, n ≥ 1 e ( n ) ≤ c * g ( n ) for n ≥ n , c > 0, n ≥ 1 Hence: d ( n ) + e ( n ) ≤ c * f ( n ) + c * g ( n ) for n ≥ max ( n ,n ) Assume: c 00 = max ( c,c ) ,n 00 = max ( n ,n ) Hence: d ( n ) + e ( n ) ≤ c 00 * ( f ( n ) + g ( n )) for n ≥ n 00 , c 00 > 0, n 00 ≥ 1 That is: d ( n ) + e ( n ) = O ( f ( n ) + g ( n )) 2...
View Full 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