End of Term Review 2.1

End of Term Review 2.1 - The Quick-Sort Algorithm Algorithm...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: The Quick-Sort Algorithm Algorithm QuickSort(S) if S.size() > 1 (L, E, G) = Partition(S) QuickSort(L) QuickSort(G) S = (L, E, G) CSE 2011 Prof. J. Elder - 51 - Last Updated: 4/1/10 2:37 PM In-Place Quick-Sort Note: Use the lecture slides here instead of the textbook implementation (Section 11.2.2) Partition set into two using randomly chosen pivot 88 52 14 31 25 98 30 23 62 79 14 31 30 23 25 CSE 2011 Prof. J. Elder 88 52 - 52 - 62 98 79 Last Updated: 4/1/10 2:37 PM Maintaining Loop Invariant CSE 2011 Prof. J. Elder - 53 - Last Updated: 4/1/10 2:37 PM The In-Place Quick-Sort Algorithm Algorithm QuickSort(A, p, r) if p < r q = Partition(A, p, r) QuickSort(A, p, q - 1) QuickSort(A, q + 1, r) CSE 2011 Prof. J. Elder - 54 - Last Updated: 4/1/10 2:37 PM Summary of Comparison Sorts Algorithm Best Case Worst Case Average Case In Place Stable Comments Selection n2 n2 Yes Yes Bubble n n2 Yes Yes Insertion n n2 Yes Yes Good if often almost sorted Merge n log n n log n No Yes Good for very large datasets that require swapping to disk Heap n log n n log n Yes No Best if guaranteed n log n required Quick n log n n2 Yes No Usually fastest in practice CSE 2011 Prof. J. Elder n log n - 55 - Last Updated: 4/1/10 2:37 PM ...
View Full Document

Page1 / 5

End of Term Review 2.1 - The Quick-Sort Algorithm Algorithm...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online