Skip to content

Commit 5303bcb

Browse files
author
Kcstring
committed
sorts: add complexity analysis to bubble sort docstrings
1 parent 791deb4 commit 5303bcb

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

sorts/bubble_sort.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]:
88
comparable items inside
99
:return: the same collection ordered in ascending order
1010
11+
Time Complexity:
12+
Best Case: O(n)
13+
Average Case: O(n^2)
14+
Worst Case: O(n^2)
15+
16+
Space Complexity: O(1)
17+
18+
Stable: Yes
19+
1120
Examples:
1221
>>> bubble_sort_iterative([0, 5, 2, 3, 2])
1322
[0, 2, 2, 3, 5]
@@ -66,6 +75,15 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]:
6675
:param collection: mutable ordered sequence of elements
6776
:return: the same list in ascending order
6877
78+
Time Complexity:
79+
Best Case: O(n)
80+
Average Case: O(n^2)
81+
Worst Case: O(n^2)
82+
83+
Space Complexity: O(n)
84+
85+
Stable: Yes
86+
6987
Examples:
7088
>>> bubble_sort_recursive([0, 5, 2, 3, 2])
7189
[0, 2, 2, 3, 5]

0 commit comments

Comments
 (0)