This is python need help and please just do the code from my code given to you start at "START YOUR CODE" please def buc

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

This is python need help and please just do the code from my code given to you start at "START YOUR CODE" please def buc

Post by answerhappygod »

This is python need help and please just do the code from my
code given to you start at "START YOUR CODE" please
def bucket_sort_enhanced(arr):
"""
:param arr: list, input array
:return: list, the sorted array
"""
### START YOUR CODE ###
min_value = None
max_value = None
num_buckets = None # Calculate the number of buckets
buckets = None # Initialize buckets
### END YOUR CODE ###
### START YOUR CODE ###
# Place each element in arr to the correct bucket.
for i in range(len(arr)):
pass
### END YOUR CODE ###
### START YOUR CODE ###
# Concatenate all buckets together in order. Hint: You can use a
nested for loop or the `itertools` package to concatenate
buckets.
sorted_arr = None
### END YOUR CODE ###
return sorted_arr
Test Code:
np.random.seed(1)
arr = (np.random.rand(10) * 20 - 10).tolist()
arr_sorted = bucket_sort_enhanced(arr)
np.set_printoptions(precision=2)
print('arr:', np.array(arr))
print('arr sorted:', np.array(arr_sorted)
Expected output:
arr: [ -1.66 4.41 -10. -3.95 -7.06 -8.15 -6.27 -3.09 -2.06
0.78]
arr sorted: [-10. -8.15 -7.06 -6.27 -3.95 -3.09 -2.06 -1.66 0.78
4.41]
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply