CS2
Week 5: Algorithm analysis, searching, sorting
49


Mergesort vs. Quicksort


Both are divide-and-conquer sorting algorithms
Both are optimal in general
nWorst time is O(nlogn)
nBest and average case are both O(nlogn) also
nRequires extra memory
nWorst time is O(n2)
nBest and average case are both O(nlogn) nDoesn’t requires extra memory nIn average faster with a pivot chosen randomly