Skip to content

Commit 4a4c084

Browse files
authored
Updated bucket_sort code to clear all checks.
1 parent afb695f commit 4a4c084

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

Python/sort/Bucket_sort.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# Bucket Sort
22
'''
3-
Bucket Sort is a sorting algorithm used to deal with input that is distributed over a range.
4-
It is a comparison sort algorithm.
5-
The elements of the list are distributed into a number of buckets(or bins).Each bucket is
6-
then sorted using any stable sorting algoritm.After sorting is complete, all the buckets are
7-
merged and we get a sorted list.
8-
Bucket Sort has a scatter-order-gather approach.
3+
Bucket Sort is a comparison sorting algorithm used to deal with input that is
4+
distributed over a range.
5+
The elements of the list are distributed into a number of buckets(or bins).
6+
Each bucket is then sorted using any stable sorting algoritm.After
7+
sorting is complete, all the buckets are merged and we get a sorted list.
8+
Bucket Sort uses a scatter-order-gather approach.
99
'''
1010

1111

1212
def bucket_sort(arr):
13-
# create a list containing n empty buckets where buckets are also list
13+
# create a list containing len(arr) empty buckets where buckets are also list
1414
bucket_list = []
1515
for i in enumerate(arr):
16-
bucket_list.append([])
16+
bucket_num = i[0]
17+
if bucket_num< len(arr):
18+
bucket_list.append([])
1719

1820
# numerical range of each bucket
1921
maximum = max(arr)
@@ -55,14 +57,12 @@ def main():
5557

5658

5759
# Sample I/O
58-
'''
59-
Enter sequence of comma separated numbers:
60-
6.3,12.5,7.7,2.6,1.2,4.0
61-
62-
Sorted List
63-
1.2 2.6 4.0 6.3 7.7 12.5
60+
# Enter sequence of comma separated numbers:
61+
# 6.3,12.5,7.7,2.6,1.2,4.0
6462

65-
Time Complexity -
63+
# Sorted List
64+
# 1.2 2.6 4.0 6.3 7.7 12.5
65+
''' Time Complexity -
6666
1. Best case - O(n+k)
6767
2. Average case - O(n+k)
6868
3. Worst case - O(n^2)

0 commit comments

Comments
 (0)