Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Steps to modify the bucketSort function to work with all number...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started