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.

492 Chap. 14 <strong>Analysis</strong> Techniques= 2(2T(n/4) + 5(n/2) 2 ) + 5n 2= 2(2(2T(n/8) + 5(n/4) 2 ) + 5(n/2) 2 ) + 5n 2( n) 2 ( n) 2= 2 k T(1) + 2 k−1 · 5 + · · · + 2 · 5 + 5n 22 k−1 .2This last expression can best be represented by a summation as follows:∑k−17n + 5 n 2 /2 ii=0∑k−1= 7n + 5n 2 1/2 i .i=0From Equation 2.6, we have:= 7n + 5n 2 ( 2 − 1/2 k−1)= 7n + 5n 2 (2 − 2/n)= 7n + 10n 2 − 10n= 10n 2 − 3n.This is the exact solution <strong>to</strong> the recurrence for n a power of two. At thispoint, we should use a simple induction proof <strong>to</strong> verify that our solution isindeed correct.Example 14.9 Our next example comes from the algorithm <strong>to</strong> build aheap. Recall from Section 5.5 that <strong>to</strong> build a heap, we first heapify the twosubheaps, then push down the root <strong>to</strong> its proper position. The cost is:f(n) ≤ 2f(n/2) + 2 log n.Let us find a closed form solution for this recurrence. We can exp<strong>and</strong>the recurrence a few times <strong>to</strong> see thatf(n) ≤ 2f(n/2) + 2 log n≤ 2[2f(n/4) + 2 log n/2] + 2 log n≤ 2[2(2f(n/8) + 2 log n/4) + 2 log n/2] + 2 log n

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

Saved successfully!

Ooh no, something went wrong!