This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: time will be bn. e. COUNTINGSORT(A, B, k) 1 for i 0 to k 2 do C[i] 0 3 for j 1 to length[A] 4 do C[A[j]] C[A[j]] + 1 5 C[i] now contains the number of elements equal to i. 6 for i 1 to k 7 do C[i] C[i] + C[i  1] 8 C[i] now contains the number of elements less than or equalto i. 9 for j length[A] downto 1 10 do Repeatedly move the displaced element (b = A[j]) to its sorted position (k). 11 b A[j] 12 k C[b] 13 C[b] C[b] 1 14 A[j] a Now b must be moved to its sorted position 15 a b 16 j k 17 A[j] a...
View
Full
Document
This note was uploaded on 11/09/2010 for the course CS 11841 taught by Professor Dr.ayman during the Spring '09 term at Alexandria University.
 Spring '09
 Dr.Ayman
 Algorithms, Sort

Click to edit the document details