File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44def bubble_sort_iterative (collection : list [Any ]) -> list [Any ]:
55 """Pure implementation of bubble sort algorithm in Python
66
7+ Time Complexity: O(n^2) - worst and average case
8+ Time Complexity: O(n) - best case (already sorted, early exit via swapped flag)
9+ Space Complexity: O(1) - sorts in place, no extra memory used
10+
711 :param collection: some mutable ordered collection with heterogeneous
812 comparable items inside
913 :return: the same collection ordered in ascending order
@@ -62,6 +66,9 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]:
6266
6367def bubble_sort_recursive (collection : list [Any ]) -> list [Any ]:
6468 """It is similar iterative bubble sort but recursive.
69+ Time Complexity: O(n^2) - worst and average case
70+ Time Complexity: O(n) - best case (already sorted)
71+ Space Complexity: O(n) - recursive call stack uses extra memory
6572
6673 :param collection: mutable ordered sequence of elements
6774 :return: the same list in ascending order
You can’t perform that action at this time.
0 commit comments