Computer Science, asked by shrihari28, 2 months ago

Can Anyone One Solve This

1. Consider the algorithm for the sorting problem that sorts an array by counting. for each of its elements, the number of smaller elements and then uses this information to put the element in its appropriate position in the sorted array

- ALGORITHM Comparison Counting Sort(A[0..n - 1])
//Sorts an array by comparison counting
//Input: Array A[O..n - 1] of orderable values
//Output: Array S[0..n - 1] of A's elements sorted
// Il in nondecreasing order
for i = 0 ton - 1 do
Count[i]=0
for i = 0 ton - 2 do
for j ti + 1 to n - 1 do
if A[i] < A[]
Count[] Count[j] +1
else Count[i] - Count[i]+1
for i = 0 to n - 1 do
S[Count[i]] + A[i]
return S IN
a. Apply this algorithm to sorting the list 60, 35, 81, 98, 14, 47,
b. Is this algorithm stable?
e. Is it in-place?

Answers

Answered by ranjanachas12
3

Answer:

Answer: a. after first for loop,the contents of array counts are : Count = <0,0,0,0,0,0,0,0> input Array A[0...7] is <6,3,8,3,9,1,3,9> length of the Count,A as well as S is 8 i.e. n=8. now we start with second for loop for(i =0 to n-1) step 1 : a) i =0,j=1 and A[i] > A[j] so the Count array content will be <1,0,0,0,0,0,0,0> b) i=0,j=2, here A[i] < A[j] so the Count array content will be <1,0,1,0,0,0,0,0> c) i=0,j=3 ,here A[i] > A[j] so the Count array content will be <2,0,1,0,0,0,0,0> d) i=0,j=4 ,here A[i]<A[j] so the Count array content will be <2,0,1,0,1,0,0,0> e) i=0,j=5 ,here A[i]>A[j] so the Count array content will be <3,0,1,0,1,0,0,0> f) i=0,j=6 ,here A[i]>A[j] so the Count array content will be <4,0,1,0,1,0,0,0> g) i=0,j=7 ,here A[i]<A[j] so the Count array content will be <4,0,1,0,1,0,0,1> Step 2: a) i=1,j=2 ,here A[i]<A[j] so the Count array content will be <4,0,2,0,1,0,0,1> b) i=1,j=3 ,here A[i] >=A[j] so the Count array content will be <4,1,2,0,1,0,0,1> c) i=1,j=4 ,here A[i]<A[j] so the Count array content will be <4,1,2,0,2,0,0,1> d) i=1,j=5 ,here A[i]>A[j] so the Count array content will be <4,2,2,0,2,0,0,1> e) i=1,j=6 ,here A[i] >= A[j] so the Count array content will be <4,3,2,0,2,0,0,1> f) i=1,j=7 ,here A[i] < A[j] so the Count array content will be <4,3,2,0,2,0,0,2> Step 3: a) i=

Answered by lunshikhiung94
0

Answer:

h

1.a 2.b 3.a 4.c so i dont know.

Similar questions