Consider the bucket sort algorithm with the pseudo-code:
BucketSort(array A, int bucketSize) // Find the maximum value in A
maxVal = max(A) // Determine the number of buckets bucketCount = (maxVal / bucketSize) + 1
buckets = new Array[0..bucketCount - 1] of empty lists
// Assign each element of A to a bucket
for i = 0 to length(A) - 1
bucketIndex = A[i] / bucketSize
buckets[bucketIndex].append(A[i])
// Sort each bucket using insertion sort
for i = 0 to bucketCount - 1
insertionSort(buckets[i])
// Concatenate the sorted buckets into a single array
sortedArray = []
for i = 0 to bucketCount - 1
sortedArray.extend(buckets[i])
return sortedArray
a) (4 pts) What is the time complexity for the best and worst case for a bucket sort? Explain with examples
b) (4 pts) We can see we use a constant bucket size in the above code. But there are some scenarios where using different bucket sizes may be more effective. Explain the circumstances in which constant size versus different size should be used.
c) (2 pts) Refer to the pseudocode above, we utilize insertion sort to sort each individual bucket. Explain why the provided pseudocode above prefers Insertion sort as opposed to merge sort or quicksort?