Daily iOS
CS fundamentals and algorithms

Sorting and Swift sort

Can you compare merge sort and quicksort: how each works, and their time and space complexity?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Merge sort is always O(n log n) with O(n) extra memory and stable; quicksort is O(n log n) on average, O(n²) worst case, in place, and unstable. Since Swift 5, sort() is a stable sort (Timsort family), documented as guaranteed only from 2023.

Share a question