12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

524 Chap. 15 Lower BoundsT(n) ≤ T(⌈ n − 5⌉) + T(⌈7n ⌉) + 6⌈ n 5 10 5 ⌉ + n − 1≤ r( n − 5+ 1) + r(7n + 1) + 6( n 5 105 + 1) + n − 1≤ ( r 5 + 7r10 + 11 3r)n +5 2 + 5≤9r + 22n +103r + 10.2This is true for r ≥ 23 <strong>and</strong> n ≥ 380. This provides a base case that allows us <strong>to</strong>use induction <strong>to</strong> prove that∀n ≥ 380, T(n) ≤ 23n.In reality, this algorithm is not practical because its constant fac<strong>to</strong>r costs are sohigh. So much work is being done <strong>to</strong> guarantee linear time performance that it ismore efficient on average <strong>to</strong> rely on chance <strong>to</strong> select the pivot, perhaps by pickingit at r<strong>and</strong>om or picking the middle value out of the current subarray.15.7 Optimal SortingWe conclude this section with an effort <strong>to</strong> find the sorting algorithm with the absolutefewest possible comparisons. It might well be that the result will not bepractical for a general-purpose sorting algorithm. But recall our analogy earlier <strong>to</strong>sports <strong>to</strong>urnaments. In sports, a “comparison” between two teams or individualsmeans doing a competition between the two. This is fairly expensive (at least compared<strong>to</strong> some minor book keeping in a computer), <strong>and</strong> it might be worth trading afair amount of book keeping <strong>to</strong> cut down on the number of games that need <strong>to</strong> beplayed. What if we want <strong>to</strong> figure out how <strong>to</strong> hold a <strong>to</strong>urnament that will give usthe exact ordering for all teams in the fewest number of <strong>to</strong>tal games? Of course,we are assuming that the results of each game will be “accurate” in that we assumenot only that the outcome of A playing B would always be the same (at least overthe time period of the <strong>to</strong>urnament), but that transitivity in the results also holds. Inpractice these are unrealistic assumptions, but such assumptions are implicitly par<strong>to</strong>f many <strong>to</strong>urnament organizations. Like most <strong>to</strong>urnament organizers, we can simplyaccept these assumptions <strong>and</strong> come up with an algorithm for playing the gamesthat gives us some rank ordering based on the results we obtain.Recall Insertion Sort, where we put element i in<strong>to</strong> a sorted sublist of the first i−1 elements. What if we modify the st<strong>and</strong>ard Insertion Sort algorithm <strong>to</strong> use binary

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!