Non-comparative Sorting Algorithms
Non-comparative Sorting Algorithms
• Final sorted array: [2, 7, 13, 37, 75, 400, 1536, 4351]
i 0 1 2 3 4 5 6 7 8 9 10 11
arr[i] 4 1 2 3 2 1 0 5 4 1 6 1
0 1 2 3 4 5 6
Count 1 4 2 1 2 1 1
w 0 1 2 3 4 5 6 7 8 9 10 11
Sorted array S[w] 4
Step-by-Step Execution
Step 1: Find Maximum Element
• N = 12
• Maximum element, k = 8
Step 2: Create and Initialize Count Array of length k+1 with all elements 0
• Count array of length k+1=9, (index represents the number, value represents
frequency)
index 0 1 2 3 4 5 6 7 8
M.Count 1 3 4 6 6 6 6 10 12
index 0 1 2 3 4 5 6 7 8
M.Count 1 2 4 6 6 6 6 10 11
index 0 1 2 3 4 5 6 7 8
M.Count 1 2 4 6 6 6 6 9 11
0 1 2 3 4 5 6 7 8 9 10 11
Sorted array 1 6 7