Skip to content

Commit 97a4f5c

Browse files
Add time and space complexity to bubble_sort docstrings
Enhanced documentation for bubble_sort_iterative and bubble_sort_recursive functions by adding: - Time Complexity: O(n^2) for both implementations - Space Complexity: O(1) for iterative, O(n) for recursive due to call stack This improves code readability and helps developers understand algorithm performance characteristics. Addresses issue #13948 about documentation inconsistencies.
1 parent a051ab5 commit 97a4f5c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

sorts/bubble_sort.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]:
77
:param collection: some mutable ordered collection with heterogeneous
88
comparable items inside
99
:return: the same collection ordered by ascending
10+
11+
Time Complexity: O(n^2) - where n is the number of elements
12+
Space Complexity: O(1) - only uses a constant amount of extra space
1013
1114
Examples:
1215
>>> bubble_sort_iterative([0, 5, 2, 3, 2])
@@ -59,6 +62,9 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]:
5962
6063
:param collection: mutable ordered sequence of elements
6164
:return: the same list in ascending order
65+
66+
Time Complexity: O(n^2) - where n is the number of elements
67+
Space Complexity: O(n) - due to recursive call stack
6268
6369
Examples:
6470
>>> bubble_sort_recursive([0, 5, 2, 3, 2])

0 commit comments

Comments
 (0)