4 ms·
> Sure both are time O{n log n}. Nope. Quicksort is much worse: time O(n^2). See [1]. [1] https://en.wikipedia.org/wiki/Quicksort#Worst-case_analysis https://
by amelius 10y ago
> Sure both are time O{n log n}.
Nope. Quicksort is much worse: time O(n^2). See [1].
[1] https://en.wikipedia.org/wiki/Quicksort#Worst-case_analysis https://en.wikipedia.org/wiki/Quicksort#Worst-case_analysis
- brudgers 10y agoBecause it uses a randomized pivot, the worst case for Hoare's implementation has a probability on the order 1/n!. With twenty inputs, that's 1/(2.4 * 10^18). Probabalistic analysis [1] is the difference between theory and practice. Hoare knew what he was doing and it's no accident was recognized with a Turing Award. [1] https://www.cs.cmu.edu/afs/cs/academic/class/15451-s07/www/lecture_notes/lect0123.pdf https://www.cs.cmu.edu/afs/cs/academic/class/15451-s07/www/l...