File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33
44def bubble_sort_iterative (collection : list [Any ]) -> list [Any ]:
5- """Pure implementation of bubble sort algorithm in Python
5+ """Pure implementation of bubble sort algorithm in Python.
6+ Bubble sort repeatedly steps through the list, compares adjacent elements, and swaps them
7+ if they are in the wrong order. This process is repeated until the list is sorted.
8+
9+ Time COmplexity:
10+ Worst Case: O(n^2)
11+ Average Case: O(n^2)
12+ Best Case: O(n) (When the list is already sorted and optimized with early stopping)
13+
14+ Space Complexity:
15+ O(1) (in-place sorting)
616
717 :param collection: some mutable ordered collection with heterogeneous
818 comparable items inside
@@ -62,6 +72,13 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]:
6272
6373def bubble_sort_recursive (collection : list [Any ]) -> list [Any ]:
6474 """It is similar iterative bubble sort but recursive.
75+ Time Complexity:
76+ Worst Case: O(n^2)
77+ Average Case: O(n^2)
78+ Best Case: O(n^2) (no early stopping optimization like iterative version)
79+
80+ Space Complexity:
81+ O(n) due to recursion stac
6582
6683 :param collection: mutable ordered sequence of elements
6784 :return: the same list in ascending order
You can’t perform that action at this time.
0 commit comments