Skip to content

Commit bdea44d

Browse files
committed
docs: add bubble sort complexity notes
1 parent e3b01ec commit bdea44d

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

sorts/bubble_sort.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]:
88
comparable items inside
99
:return: the same collection ordered in ascending order
1010
11+
Best case time complexity: O(n) when the collection is already sorted.
12+
Average and worst case time complexity: O(n^2).
13+
Space complexity: O(1).
14+
1115
Examples:
1216
>>> bubble_sort_iterative([0, 5, 2, 3, 2])
1317
[0, 2, 2, 3, 5]
@@ -66,6 +70,10 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]:
6670
:param collection: mutable ordered sequence of elements
6771
:return: the same list in ascending order
6872
73+
Best case time complexity: O(n) when the collection is already sorted.
74+
Average and worst case time complexity: O(n^2).
75+
Space complexity: O(n) because recursive calls use the call stack.
76+
6977
Examples:
7078
>>> bubble_sort_recursive([0, 5, 2, 3, 2])
7179
[0, 2, 2, 3, 5]

0 commit comments

Comments
 (0)