I NEED THE ANSWERS FOR 10 AND 11 PLEASE SHOW WORK 10. Assume that you want to so
ID: 3724574 • Letter: I
Question
I NEED THE ANSWERS FOR 10 AND 11 PLEASE SHOW WORK 10. Assume that you want to sort an aay of n numbers,oh of whisdh u 2. 3, 4), A sample input for6isO, 1,0 3,43), De pseudo code or in English) to solve this problem andv fe of which is a mesher of ound on the worst-case running time that has the same order running time of your algorithm.(10 points) chat H is give a lower 11. Complete following Quicksort algorithm. (6 points) QS(A, 1, n)t if (n>D x=partition(A, 1, n); Partition(Array, s, e) Pivot = Array[s]; 1-5; for G-s+1 to e) f if (Array[i] S Pivot) return ???Explanation / Answer
Q10
n=6 {3,1,0,3,4,3}
as the numbers are in the range of 0 to 4. we can use counting sort algorithm to sort them. By this, we will get the complexity of O(n) in all cases of complexity.
Algorithm of counting sort
--------------------------------------------------------------------------------------------------------------------------------------------------
Counting_Sort(Arr,n)
// input: Array arr and n
// output: Sorted Array B
for i 0 to k
// k is largest element present in array
// create temp array C and initialize with zero
C[i]0
end for
forj1 to n
// find frequency of digit repeating
C[A[j]] C[A[j]] + 1
end for
for i 1 to k
// find cumulative frequency
C[i]C[i] +C[i–1]
end for
for jn to1
// add the element to B in sorted order
B[C[A[j]]]A[j]
C[A[j]]C[A[j]] – 1
end for
---------------------------------------------------------------------------------------------------------------------------------------------------
Complexity find and optimal checking
the first loop runs in O(k)
The 2nd loop runs in O(n)
The 3rd loop runs O(k)
The 4th loop runs in O(n)
so overall complexity is O(n+k) which is linear and optimal also.
------------------------------------------------------------------------------------------------------------------------------------------------------
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.