18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

SHOW MORE
SHOW LESS

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

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

Lecture 5 - quicksort<br />

Listen To Part 5-10<br />

What have we shown?<br />

At most levels of decent partitions suffices to sort an array of n elements.<br />

But how often when we pick an arbitrary element as pivot will it generate a decent partition?<br />

Since any number ranked between n/4 and 3n/4 would make a decent pivot, we get one half the time on average.<br />

If we need levels of decent partitions to finish the job, and half of random partitions are decent, then on<br />

average the recursion tree to quicksort the array has levels.<br />

Since O(n) work is done partitioning on each level, the average time is .<br />

More careful analysis shows that the expected number of comparisons is .<br />

Listen To Part 5-11<br />

Average-Case Analysis of Quicksort<br />

To do a precise average-case analysis of quicksort, we formulate a recurrence given the exact expected time T(n):<br />

Each possible pivot p is selected with equal probability. <strong>The</strong> number of comparisons needed to do the partition is n-<br />

1.<br />

file:///E|/LEC/LECTUR17/NODE5.HTM (6 of 10) [19/1/2003 1:34:35]

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

Saved successfully!

Ooh no, something went wrong!