Today I learned the funniest thing about `qsort()`:
`qsort` is basically lying to your face.
The C/C++/POSIX standards do NOT require qsort() to actually use Quicksort. Not even a little.
And honestly? That makes sense, because raw Quicksort has a disgusting worst-case complexity of: O(n^2)
while Merge Sort / Heap Sort stay at: O(n log n)
What glibc actually does internally in qsort.c:
- defaults to Merge Sort
- uses indirect Merge Sort for large elements (to avoid expensive swaps/copies)
- falls back to Heap Sort if temp allocation fails / conditions aren’t suitable
Meaning the standard library implementation called qsort()… often does not quicksort anything at all 🙂
Only Neha was originally from India (she moved to the US in 2006, so she's a US citizen now).
Jay was born and brought up in the US, while Jun was born and brought up in China.