File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33
44def bubble_sort_iterative (collection : list [Any ]) -> list [Any ]:
55 """Pure implementation of bubble sort algorithm in Python.
6- Bubble sort repeatedly steps through the list, compares adjacent
7- elements, and swaps them if they are in the wrong order.
8- This process is repeated until the list is sorted.
9-
6+ Bubble sort repeatedly steps through the list, compares adjacent
7+ elements, and swaps them if they are in the wrong order.
8+ This process is repeated until the list is sorted.
9+
1010 Time Complexity:
1111 Worst Case: O(n^2)
1212 Average Case: O(n^2)
13- Best Case: O(n) (When the list is already sorted and
13+ Best Case: O(n) (When the list is already sorted and
1414 optimized with early stopping)
1515
1616 Space Complexity:
@@ -77,7 +77,7 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]:
7777 Time Complexity:
7878 Worst Case: O(n^2)
7979 Average Case: O(n^2)
80- Best Case: O(n^2) (no early stopping
80+ Best Case: O(n^2) (no early stopping
8181 optimization like iterative version)
8282
8383 Space Complexity:
You can’t perform that action at this time.
0 commit comments