Question

CountingSort(A, B, k) for i=1 to k C[i]= 0; for j=1 to n C[A[j]] += 1;...

CountingSort(A, B, k)

for i=1 to k

C[i]= 0;

for j=1 to n

C[A[j]] += 1;

for i=2 to k

C[i] = C[i] + C[i-1];

for j=n downto 1

B[C[A[j]]] = A[j];

C[A[j]] -= 1;

illustrate the operation of COUNTING-SORT on the array A = {6,0,2,0, 1, 3, 5, 6, 1, 3, 2}. Specifically, show the four arrays A, B, C, and C'.

Homework Answers

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1. Consider three vectors: ( 8 marks) C i j k B i j k A...
1. Consider three vectors: ( 8 marks) C i j k B i j k A i j k 0ˆ 3 ˆ 5 ˆ 2ˆ 7 ˆ 1ˆ 4ˆ 6 ˆ 2 ˆ = + + = + − = + − ! ! ! 1.1 Evaluate D= 2A+B? (2 marks) 1.2 Evaluate 2A•(-­‐B) (2 marks) 1.3 Find the angle between D and 2C using cross product method (4 marks
Suppose an array A stores n integers, each of which is in {0, 1, 2, ...,...
Suppose an array A stores n integers, each of which is in {0, 1, 2, ..., 99}. Which of the following sorting algorithms can sort A in O(n) time in the worst case? Question 16 options: A) merge sort B) counting sort C) quicksort D) None of these options is correct. E) insertion sort
PDA for {a^i b^j i != j} PDA for {a^i b^j c^k, i = j or...
PDA for {a^i b^j i != j} PDA for {a^i b^j c^k, i = j or j = k} PDA for # of a's = # of b's PDA for # b's = twice # of a's
int i,sum=0;   int array[8]={//You decide this};   int *a,*b,*c;   a = array;   b = &array[3];   c =...
int i,sum=0;   int array[8]={//You decide this};   int *a,*b,*c;   a = array;   b = &array[3];   c = &array[5];   c[-1] = 2;   array[1] = b[1]-1;   *(c+1) = (b[-1]=5) + 2;   sum += *(a+2) + *(b+2) + *(c+2);   printf("%d %d %d %d\n", sum, array[b-a], array[c-a], *a-*b); array[8]={ ?? }; what is array[8]?
Here are two relations: R(A,B): {(0, 1), (2,3), (0, 1), (2,4), (3,4)} S(B, C): {(0, 1),...
Here are two relations: R(A,B): {(0, 1), (2,3), (0, 1), (2,4), (3,4)} S(B, C): {(0, 1), (2, 4), (2, 5), (3, 4), (0, 2), (3, 4)} Compute the following: a) 11'A+B.A2,B2(R); b) 71'B+l,C-l(S); c) TB,A(R); d) TB,c(S); e) J(R); f) J(S); g) /A, SUM(Bj(R); h) IB.AVG(C)(S'); ! i) !A(R); ! j) IA,MAX(C)(R t:><1 S); k) R ~L S; I) R ~H S; m) R ~ S; n) R ~R.B<S.B S. I want to know the solution for j to m
Are the vectors a = i + j − k, b = i − j +...
Are the vectors a = i + j − k, b = i − j + k, and c = i + j + k coplanar?
(1) A square matrix with entries aj,k , j, k = 1, ..., n, is called...
(1) A square matrix with entries aj,k , j, k = 1, ..., n, is called diagonal if aj,k = 0 whenever j is not equal to k. Show that the product of two diagonal n × n-matrices is again diagonal.
For X1, ..., Xn iid Unif(0, 1): a) Show the conditional pdf X(i)|X(j) ∼ X(j)Beta(i, j...
For X1, ..., Xn iid Unif(0, 1): a) Show the conditional pdf X(i)|X(j) ∼ X(j)Beta(i, j − i) b Let n=5, find the joint pdf between X(2) and X(4).
Do a theta analysis and count the number of computations it performed in each function/method of...
Do a theta analysis and count the number of computations it performed in each function/method of the following code: import java.io.*; import java.util.Scanner; class sort { int a[]; int n; long endTime ; long totalTime; long startTime; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public sort(int nn) // Constructor { a = new int[nn]; n = nn; endTime= 0; totalTime =0; startTime =0; } public static void main(String args[]) throws IOException { System.out.print("\nEnter number of students: "); int nn =...
What is the vector product of A = 4 (i) - 3 (j) - 5 (k)...
What is the vector product of A = 4 (i) - 3 (j) - 5 (k) and B = 5 (i) - 4 (j) + 2 (k)? 22 9 (i) - 7 (j) - 3 (k) 14 (i) - 17 (j) - 1 (k) -26 (i) - 33 (j) - 1 (k) 20 (i) + 12 (j) - 10 (k))