Is Quicksort in-place or not? [duplicate]

Intro to Algorithms from MIT Press qualifies QuickSort as in-place – it sorts the elements within the array with at most a constant amount of them outside the array at any given time. At the end of the day, people will always have differing opinions (is Top-Down Memoization considered Dynamic Programming? Not to some “classical” … Read more

Worst case for QuickSort – when can it occur?

I think people are confusing Quicksort the partition-based sorting algorithm, and “qsort” the various library implementations. I prefer to see Quicksort the algorithm as having a pluggable pivot selection algorithm, which is quite essential in analyzing its behavior. If the first element is always chosen as the pivot, then an already sorted list is the … Read more

Python faster than compiled Haskell?

The Original Haskell Code There are two issues with the Haskell version: You’re using string IO, which builds linked lists of characters You’re using a non-quicksort that looks like quicksort. This program takes 18.7 seconds to run on my Intel Core2 2.5 GHz laptop. (GHC 7.4 using -O2) Daniel’s ByteString Version This is much improved, … Read more

Why does QuickSort use O(log(n)) extra space?

Correct, the extra space are the log(n) stack frames. From the Wikipedia article of Quicksort: There is a more complex version which […] can achieve the complete sort using O(log n) space (not counting the input) on average (for the call stack). While you could implement quicksort iteratively (i.e., using a loop instead of recursion), … Read more