TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DAVID NOON
from: JONATHAN DE BOYNE POLLARD
date: 1998-04-02 11:29:00
subject: Sorting Linked List

 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)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.