Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

COUNTING - SORT ( A , n , k ) let B [ 1 : n ] and C [ 0 : k ] be

COUNTING-SORT (A,n,k)
let B[1:n] and C[0:k] be new arrays
for i=0 to k
C[i]=0
for j=1 to n
C[A[j]]=C[A[j]]+1
//C[i] now contains the number of elements equal to i.
for i=1 to k
C[i]=C[i]+C[i-1]
??C[i] now contains the number of elements less than or equal to i.
// Copy A to B, starting from the end of A.
for j=n downto 1
B[C[A[j]]]=A[j]
C[A[j]]=C[A[j]]-1,?? to handle duplicate values
return B
a. Following the algorithm above, illustrate the operation of COUNTING-SORT on the array A=
|~0,5,1,3,1~| by assuming k=5. Show all intermediate steps, including changes on array B and C.
b. Does the algorithm perform sorting in place? Justify your answer.
c. Is the algorithm stable? Justify your answer.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions