Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Illustrate the operation of counting Sort ({2, 1, 5, 3, 1, 2, 5},6). Specifically, show the changes made to the arrays A, B, and

   

Illustrate the operation of counting Sort ({2, 1, 5, 3, 1, 2, 5},6). Specifically, show the changes made to the arrays A, B, and C for each pass through the for loop at line 16. Algorithm 1 int counting Sort (int A[1...n], int k) 1: //Precondition: The n values in A are all between 0 and k 2: Let C[0...k] be a new array 3: //We will store our sorted array in the array B. 4: Let B[1...n] be a new array 5: for i=0 to k do 6: C[i] = 0; 7: end for 8: for i = 1 ton do 9: C[A[i]] = C[A[i]] + 1; 10: end for 11: //C] now contains the # of elements in A equal to i 12: for 13: 1 to k do Ci] C[i]+C[i-1]; 14: end for 15: //C[] now contains the # of elements in A that are < to i 16: for in down to 1 do 17: 18: B[C[A[i]]] = A[i]; C[A[i]] = C[A[i]] - 1; 19: end for 20: return B;

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

Elements Of Chemical Reaction Engineering

Authors: H. Fogler

6th Edition

013548622X, 978-0135486221

More Books

Students also viewed these Computer Network questions