Question: The file contains a bucket sort algorithm. However, it works only for non-negative numbers. def bucket Sort Positive (arr, k): n = len(arr) #

The file contains a bucket sort algorithm. However, it works only for

The file contains a bucket sort algorithm. However, it works only for non-negative numbers. def bucket Sort Positive (arr, k): n = len(arr) # find max and min MAX = max(arr) MIN = min (arr) # create k empty buckets buckets = list([] for i in range(k)) #put elements into different buckets for i in range(n): bi = int((arr[i] - MIN) buckets [bi].append(arr[i]) (k-1) / (MAX MIN)) # index of the bucket #sort individually for i in range(k): buckets[i] = insertionSort (buckets[1]) #concatenate all buckets into arr arr = list() for i in range(k): arr + buckets[i] return arr bucket = bucketSortPositive (testCase, 50) print("" 100) print(check (bucket)) print("Bucket sorti ", bucket) pass - Complete the bucketSort function to make a bucket sort that works for all numbers. def bucketSort (arr, k): bucket = bucket Sort (testCase, 50) print("" 100) print(check (bucket)) print("Bucket sort: ", bucket)

Step by Step Solution

3.52 Rating (152 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To modify the bucketSort function to handle both negative and nonnegative numbers we need to adjust ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithms Questions!