Lecture09

# Lecture09 - CS2134 Lecture 9 Sorting D N W A s f o S F H n...

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

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

View Full Document

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

View Full Document

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.

Unformatted text preview: CS2134 Lecture 9: Sorting D N W A s f o S F H n n S w d W t s CS2134 Merge Sort 43 37 25 20 4 15 72 19 4 19 15 72 20 25 43 37 43 37 25 20 4 15 72 19 DIVIDE IN HALF SORT EACH HALF MERGE 4 19 15 72 20 25 43 37 CS2134 QuickSort 43 37 25 20 4 15 72 19 43 37 25 20 4 15 72 19 SELECT PIVOT; PARTITION SORT EACH PIECE (Recursively) 4 19 15 72 20 25 43 37 <= pivot pivot >= pivot done! CS2134 Quick Sort • Partition array into two pieces: – (elements <= pivot) , (elements >= pivot) • Conquer: – sort each half recursively • Analysis: – partition step can be done in linear time – Running time depends on choice of pivots at each stage – Equal sized piece situation similar to merge sort – Very unequal sizes poor performance CS2134 Running Time • Worst case: – suppose largest element is chosen as pivot on each call to Quicksort: – Quicksort(a, 0, n-1) calls Quicksort(a, 0, n-2) calls Quicksort(a, 0, n-3) calls .....
View Full Document

## This note was uploaded on 12/09/2009 for the course CS 2134 taught by Professor Hellerstein during the Spring '07 term at NYU Poly.

### Page1 / 13

Lecture09 - CS2134 Lecture 9 Sorting D N W A s f o S F H n...

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

View Full Document
Ask a homework question - tutors are online