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 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:
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+
10+ Time Complexity:
1011 Worst Case: O(n^2)
1112 Average Case: O(n^2)
12- Best Case: O(n) (When the list is already sorted and optimized with early stopping)
13+ Best Case: O(n) (When the list is already sorted and
14+ optimized with early stopping)
1315
1416 Space Complexity:
1517 O(1) (in-place sorting)
@@ -75,7 +77,8 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]:
7577 Time Complexity:
7678 Worst Case: O(n^2)
7779 Average Case: O(n^2)
78- Best Case: O(n^2) (no early stopping optimization like iterative version)
80+ Best Case: O(n^2) (no early stopping
81+ optimization like iterative version)
7982
8083 Space Complexity:
8184 O(n) due to recursion stac
You can’t perform that action at this time.
0 commit comments