Question: Prove the correctness of the below given algorithm. procedure CountingSort ( arr ) : # Find the maximum and minimum values in the input array
Prove the correctness of the below given algorithm.
procedure CountingSortarr:
# Find the maximum and minimum values in the input
array
maxval findMax arr
minval findMinarr
# Create an array to store the count of each element in
the input array
count array of size maxval minval
initialized with
# Count the occurrences of each element in the input
array
for num in arr:
countnum minval
# Update the count array to store the cumulative count
for i from to length count:
counti counti
# Create the output array
output array of size lengtharr
# Build the output array using the count array
for num in reversearr:
outputcountnum minval num
count num minval
return output
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
