hw1-practice-sol

# hw1-practice-sol - Supplement to A Practical Guide to Data...

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

Supplement to A Practical Guide to Data Structures and Algorithms Using Java Practice Problems Solutions for Homework Exercise 1 Sally A. Goldman and Kenneth J. Goldman 1. Here is a summary of the correct answers. T 1 ( n ) T 2 ( n ) Is T 1 ( n ) = O ( T 2 ( n ))? Is T 1 ( n ) = Ω( T 2 ( n ))? Is T 1 ( n ) = Θ( T 2 ( n ))? Which is best? a 25 n ln n +5 n 1 2 n log 2 n yes yes yes A 2 b 1 2 n 2 + n log 2 n 5 n log 2 n no yes no A 2 c n (log 2 n ) n yes no no A 1 d 2 log 2 n 2 n 2 yes no no A 1 e n n n 1 . 4 no yes no A 2 Here are the justiﬁcations. When taking the limit only the fastest growing term (which will dominate) is used. If needed the limit approach could be used to determine which term in the sum is the fastest growing, or by using the entire expression (including the low order terms). (a) Recall that log 2 n = ln n ln 2 . Hence lim n →∞ 25 n ln n 1 2 n log 2 n = lim n →∞ ± 25 n ln n n ln n/ (2 ln 2) ² = lim n →∞ (50 ln 2) = 50 ln 2 35. They grow at the same asymptotic growth rate, however A 2 is almost 35 times faster and hence is the preferred algorithm. (b) lim n →∞ 1 / 2 n 2 5 n log 2 n = lim n →∞ n 10 n log 2 n = and hence T 1 is asymptotically faster growing and so A 2 is the preferred algorithm. (c) lim n →∞ n log 2 n n = lim n →∞ log 2 n n = 0 and hence T 2 is asymptotically faster growing and so A 1 is the preferred algorithm. (d) 2 log 2 n = n . Hence lim n →∞ T 1 ( n ) /T 2 ( n ) = lim n →∞ 1 / (2 n ) = 0. Hence T 1 ( n ) is asymptoti- cally slower growing and thus A 1 is the preferred algorithm. (e) Note that

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/19/2011 for the course CSE 241 taught by Professor Cse241 during the Spring '08 term at Washington University in St. Louis.

### Page1 / 3

hw1-practice-sol - Supplement to A Practical Guide to Data...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online