The Gateway to Computer Science Excellence
0 votes
18 views
COUNTING-SORT(A, B, k)
1      let C[0,…,k] be a new array
2      for i = 0 to k
3      C[i] = 0
4      for j = 1 to A.length
5      C[A[j]] = C[A[j]] + 1
6      // C[i] now contains the number of elements equal to i .
7      for i =1 to k
8      C[i] = C[i] + C[i-1]
9      // C[i] now contains the number of elements less than or equal to i .
10    for j = A.length downto 1
11     B[C[A[j]]] = A[j]
12     C[A[j]] = C[A[j]] – 1

illustrate the operation of COUNTING-SORT on the array $A=\langle 6,0,2,0,1,3,4,6,1,3,2 \rangle $

in Algorithms by Boss (41.9k points) | 18 views

Please log in or register to answer this question.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,647 questions
56,492 answers
195,439 comments
100,696 users