Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: element is equally likely This to be any of input elements. 31 Randomized Quicksort Randomized-Partition(A, p, r) 1. i ← Random(p, r) 1. 2. exchange A[r] ↔ A[i] 3. return Partition(A, p, r) return Randomized-Quicksort(A, p, r) 1. if p < r if 2. then q ← Randomized-Partition(A, p, r) then 3. Randomized-Quicksort(A, p , q-1) Randomized 4. Randomized-Quicksort(A, q+1, r) Randomized 32 Review: Analyzing Quicksort What will be the worst case for the algorithm? What Partition is always unbalanced What will be the best case for the algorithm? What Partition is balanced Which is more likely? Which The latter, by far, except... Will any particular input elicit the worst case? Will Yes: Already-sorted input 33...
View Full Document

This document was uploaded on 11/11/2013.

Ask a homework question - tutors are online