next up previous
Up: CSE 2320: Algorithms and Previous: Analysis

Stable Sort

Two elements having the same value appear in the same order in the sorted sequence as they did in the input sequence.



Counting Sort is a Stable Sort.



Array A:

5 (1) 7 3 (1) 5 (2) 2 1 4 3 (2)



Array B:

1 2 3 (1) 3 (2) 4 5 (1) 5 (2) 7



If we change line from

for j = length(A) downto 1
to
for j = 1 to length(A)



*
Would the algorithm still sort?
*
Would the algorithm still be a stable sort?


next up previous
Up: CSE 2320: Algorithms and Previous: Analysis
Copyright © 1998 The University of Texas at Arlington