DM>> Quicksort, by definition, requires random access. Many methods,
DM>> such as insertion sort, IIRC, can use bidirectional access (being
DM>> able to move forward and backward one at a time) or even
DM>> unidirectional access (although usually at the cost of increased
DM>> stack space). Quicksort needs to be able to quickly find arbitrary
DM>> nodes and swap them.
DN> There is a minor variant of Quicksort, called Mergesort, for sorting
DN> linked lists using Hoare's algorithm.
I'd hardly class Merge Sort as a "minor variant of Quick Sort". First, Merge
Sort predates Quick Sort. And second, Merge Sort operates in the opposite
direction to Quick Sort (as Sedgewick says, the latter is "conquer and
divide", whilst the former is "divide and conquer").
The above notwithstanding, I don't see how Merge Sort is any more appropriate
for linked lists than Quick Sort. They both require speedy access to the
N/2th element (for median of three partitioning in the case of Quick sort,
for the initial recursion in the case of Merge sort), something which is
possible in "O(1)" time with arrays, but which is O(N) with a linked list.
¯ JdeBP ®
--- FleetStreet 1.19 NR
---------------
* Origin: JdeBP's point, using Squish (2:440/4.3)
|