# 10-10 notes - 10-10-2011 Algorithms and data structures...

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

10-10-2011 Algorithms and data structures Partition Algorithm Quicksort 1. Partiotion input into high, low parts 2. Observe that all elements in high part are > any element in low part 3. Recursively sort two parts “A is sorted” == for all I, j, p <=i, j<= r, if A(i) != A(j) A(i) >= A(j) iff i>j Efficiency of Quicksort N = r – p +1 - Partition is θ(n) - Most unequal split o Partition element is 1 st or last element after partitioning (z= p or z=r) - Recursive calls of size n-1, 0 If A starts sorted, then this case occurs for each recursive call T(n) = cn + T(n-1) K T(n) work/node 0 T(n) Cn 1 T(n-1) C(n-1) 2 T(n-2) C(n-2) . . C(n-k) . n-1 T(1) Co Worst case: T(n) = Co + Cn(n-1) – C ((n-2)(n-1))/2 == θ(n 2 ) Randomized Algorithms Definition: A randomized algorithm uses random numbers that are independent of its input when computing its answer - Always produces the right answer - Running time depends on random choices [even for same input] RANDOMIZE QUICKSORT RQUICKSORT(A,p,r) If (p<r){ X random (p,r)

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 12/05/2011 for the course ENGINEERIN 131 taught by Professor Cytron during the Spring '11 term at Washington University in St. Louis.

### Page1 / 2

10-10 notes - 10-10-2011 Algorithms and data structures...

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

View Full Document
Ask a homework question - tutors are online