CS2
Week 5: Algorithm analysis,
searching, sorting
49
Mergesort vs. Quicksort
Both are divide-and-conquer sorting
algorithms
Both are optimal in general
n
Worst time is O(nlogn)
n
Best and average case
are both O(nlogn) also
n
Requires extra memory
n
Worst time is O(n
2
)
n
Best and average case
are both O(nlogn)
n
Doesn’t requires extra
memory
n
In average faster with
a pivot chosen
randomly