Notes
Outline
Week 6
Divide and Conquer
Merge Sort
Quick Sort
Trees
Reading: Main p. 604-624, 435-464
Slide 2
Slide 3
Divide and Conquer
Divide and Conquer
Merge Sort
Slide 7
Merge Sort
Merge Sort
Slide 10
mergeList
mergeList
mergeList
mergeList
mergeList
mergeList
mergeList
mergeList
mergeList
mergeList
mergeList
mergeList
Quick Sort
Quick Sort
Quick Sort
Slide 26
Slide 27
Quick Sort
Quick Sort
Quick Sort
Quick Sort
Quick Sort
Partition: Checklist
Partition
Partition
Partition
Partition
Partition
Partition
Partition
Partition
Partition
Partition
Partition
Partition
Partition
Partition
Slide 48
Mergesort vs. Quicksort
Both are divide-and-conquer sorting algorithms
Both are optimal in general
Worst time is O(nlogn)
Best and average case are both O(nlogn) also
Requires extra memory
Worst time is O(n
2
)
Best and average case are both O(nlogn)
Doesn’t requires extra memory
In average faster with a pivot chosen randomly