0% found this document useful (0 votes)
97 views2 pages

Distribution Counting Sort: A Sorting Algorithm Not Based On The Use of Comparisons and Achieve O (N) Time Complexity

Distribution counting sort is a sorting algorithm that takes advantage of the properties of integer data to achieve O(n) time complexity. It works by first counting the frequency of each unique value in the data, then using the counts to distribute the data into the correctly sorted order in the output array. Specifically, it works as follows: 1) Count the frequency of each unique value in the input array. 2) Use the counts to accumulate the distributions, which represent each value's starting index in the output array. 3) Distribute the data into the output array based on the distributions. This algorithm avoids comparisons, allowing it to achieve linear time complexity.

Uploaded by

d singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views2 pages

Distribution Counting Sort: A Sorting Algorithm Not Based On The Use of Comparisons and Achieve O (N) Time Complexity

Distribution counting sort is a sorting algorithm that takes advantage of the properties of integer data to achieve O(n) time complexity. It works by first counting the frequency of each unique value in the data, then using the counts to distribute the data into the correctly sorted order in the output array. Specifically, it works as follows: 1) Count the frequency of each unique value in the input array. 2) Use the counts to accumulate the distributions, which represent each value's starting index in the output array. 3) Distribute the data into the output array based on the distributions. This algorithm avoids comparisons, allowing it to achieve linear time complexity.

Uploaded by

d singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Distribution Counting Sort

Suppose we have an array of student


Address Calculating Sort records:
A sorting algorithm not S Tom Mary Jack Tim
……
Bob

based on the use of 99 73 56 73 82

comparisons and achieve


O(n) time complexity. Question: sort the array with respect to
s[i].grade

Proxmap Sort 2

Algorithm: Proximity Map Sort


Function Distribution_counting_sort(S, n){
Input: a student array S of n records Map a key to an array index
Output: a sorted array (wrt grade) NS
Compute hit counts
int count[101]; /*init to 0’s */
Convert hit counts to a proxmap
/* counting */
for (i = 0; i < n; i++) count[S[i].grade]++; Compute insertion location
/* accumulating */
count[0]--; Rearrange input array into ascending
for (i = 1; i < 101; i++) count[i] = count[i -1] + count[i]; sorted order
/* distribution */
for (i = 0; i < n; i++) NS[count[S[i].grade]--] = S[i];

Proxmap Sort 3 Proxmap Sort 4

Working with an Example (2):


Working with an Example (1): i 0 1 2 3 4 5 6 7 8 9 10 11 12
A[i] 6.7 5.9 8.4 1.2 7.3 3.7 11.5 1.1 4.8 0.4 10.5 6.1 1.8
i 0 1 2 3 4 5 6 7 8 9 10 11 12 H[i] 1 3 0 1 1 1 2 1 1 0 1 1 0
A[i] 6.7 5.9 8.4 1.2 7.3 3.7 11.5 1.1 4.8 0.4 10.5 6.1 1.8
/* Convert hit counts to proxmap */
RunningTotal = 0;
/* Compute hit counts */ for (i = 0; i < 13; i++)
for (i = 0; i < 13; i++) if (H[i] > 0){
P[i]= RunningTotal ;
j = Mapkey(A[i]);
RunningTotal + = H[i];
H[j]++; }
} }

i 0 1 2 3 4 5 6 7 8 9 10 11 12
i 0 1 2 3 4 5 6 7 8 9 10 11 12
A[i] 6.7 5.9 8.4 1.2 7.3 3.7 11.5 1.1 4.8 0.4 10.5 6.1 1.8
A[i] 6.7 5.9 8.4 1.2 7.3 3.7 11.5 1.1 4.8 0.4 10.5 6.1 1.8
H[i] 1 3 0 1 1 1 2 1 1 0 1 1 0
H[i] 1 3 0 1 1 1 2 1 1 0 1 1 0
P[i] 0 1 0 4 5 6 7 9 10 0 11 12 0

Proxmap Sort 5 Proxmap Sort 6

1
Working with an Example (3): Working with an Example (4):
i 0 1 2 3 4 5 6 7 8 9 10 11 12
i 0 1 2 3 4 5 6 7 8 9 10 11 12
A[i] 6.7 5.9 8.4 1.2 7.3 3.7 11.5 1.1 4.8 0.4 10.5 6.1 1.8
A[i] 6.7 5.9 8.4 1.2 7.3 3.7 11.5 1.1 4.8 0.4 10.5 6.1 1.8
H[i] 1 3 0 1 1 1 2 1 1 0 1 1 0
L[i] 7 6 10 1 9 4 12 1 5 0 11 7 1
P[i] 0 1 0 4 5 6 7 9 10 0 11 12 0

/* Distribute A to B, B init 0 */ elseif (B[k] <= v) k++;


for (i = 0; i < 13; i++){ else {
/* Compute insertion locations */
v = A[i]; temp = v;
for (i = 0; i < 13; i++)
k = L[i]; v = B[k];
L[i]= P[MapKey(A[i])];
while(1){ B[k] = temp;
}
if (B[k] == 0){ k++;
B[k] = v; }
i 0 1 2 3 4 5 6 7 8 9 10 11 12 break; }
A[i] 6.7 5.9 8.4 1.2 7.3 3.7 11.5 1.1 4.8 0.4 10.5 6.1 1.8 } }
i 0 1 2 3 4 5 6 7 8 9 10 11 12
P[i] 0 1 0 4 5 6 7 9 10 0 11 12 0

L[i] 7 6 10 1 9 4 12 1 5 0 11 7 1 A[i] 6.7 5.9 8.4 1.2 7.3 3.7 11.5 1.1 4.8 0.4 10.5 6.1 1.8

L[i] 7 6 10 1 9 4 12 1 5 0 11 7 1

B[i] 0.4 1.1 1.2 1.8 3.7 4.8 5.9 6.1 6.7 7.3 8.4 10.5 11.5

Proxmap Sort 7 Proxmap Sort 8

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy