Sortieren durch Zählen von Häufigkeiten

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]

*Folgendes Sortierverfahren findet sich im Band 3 des Werks ``The Art of Computer Programming'' von D. Knuth:
 
*Algorithm D (Distribution counting). Assuming that all keys are integers in the range u <= Kj <= v for 1 <= j <= N, this algorithm sorts the records R1, ..., RN by making use of an auxiliary table COUNT[u ], ..., COUNT[v ]. At the conclusion of the algorithm the records are moved to an output area S1, ..., SN in the desired order.

*[Clear COUNTs.] Set COUNT[u ] through COUNT[v ] all to zero.
 
*[Loop on j.] Perform step D3, for 1 <= j <= N; then go to step D4.
 
*[Increase COUNT[Kj].] Increase the value of COUNT[Kj] by 1.
 
*[Accumulate.] (At this point COUNT[i] is the number of keys that are equal to i.) Set COUNT[i ] <- COUNT[i ] + COUNT[i-1 ], for i = u + 1, u + 2, ..., v.
 
*[Loop on j.] (At this point COUNT[i] is the number of keys that are less than or equal to i; in particular, COUNT[v ] = N.) Perform step D6 for j = N, N-1, ..., 1; then terminate the algorithm.
 
*[Output Rj.] Set i <- COUNT[Kj ], Si <- Rj, and COUNT[Kj ] <- i-1.


 

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 2004, 2005 Andreas Borchert, in HTML konvertiert am 18.02.2005