You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve docstrings in sorts/bubble_sort.py to include complexity analysis #14593
The docstrings in sorts/bubble_sort.py are missing time and space complexity information, which is present in many other algorithm implementations across the repository.
Suggested improvement:
Add complexity analysis to the existing docstring:
Repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order.
Time Complexity:
- Best Case: O(n) — already sorted
- Average Case: O(n²)
- Worst Case: O(n²)
Space Complexity: O(1) — in-place sorting
Stable: Yes
>>> bubble_sort([4, 3, 2, 1])
[1, 2, 3, 4]
"""
This would make the implementation more educational and consistent with the repository's goal of being a learning resource.
Triage summary (issue + the 5 open PRs targeting it).
The issue is already resolved on master.sorts/bubble_sort.py was expanded with full time/space complexity for both functions in #14924 (merged 2026-07-31), and refined again in #15240 (2026-09-09). The current docstrings already document:
iterative — O(n) best (early-exit via swapped), O(n²) avg/worst; O(1) auxiliary.
recursive — O(n) best, O(n²) avg/worst; O(1) auxiliary for the sort itself, O(n) call-stack frames worst case.
That best-case nuance matters: bubble_sort_recursive ends with return collection if not swapped else bubble_sort_recursive(collection), so an already-sorted input does a single O(n) pass and stops — best case is O(n), not O(n²).
All five PRs were opened in May/June 2026, before#14924 merged, and are now superseded — each adds a subset of what master already documents, and none improves on it:
Recommendation: close #14593 as completed (already fixed by #14924/#15240), and close #14610, #14759, #14823, #14842, #14861 as superseded — with thanks to each contributor for the effort. No merge needed; merging any of them would only re-open the resolved diff (with conflicts against the current PEP 695-typed source) and, for #14610/#14759, introduce an inaccurate best-case claim.
Activity
dvanhu commentedon May 8, 2026
Hi, I would like to work on this issue. Please assign it to me if available.
sharanabasava-05 commentedon May 20, 2026
Hi, I would like to work on this issue . could you assign it to me ?
dhruv-gautam-dev commentedon Jun 25, 2026
Hi, I'd like to work on this issue. I'll add the complexity analysis to the docstrings.
cclauss commentedon Sep 10, 2026
@priya-sundaram-dev, please review this issue and five open pull requests.
priya-sundaram-dev commentedon Sep 10, 2026
Triage summary (issue + the 5 open PRs targeting it).
The issue is already resolved on
master.sorts/bubble_sort.pywas expanded with full time/space complexity for both functions in #14924 (merged 2026-07-31), and refined again in #15240 (2026-09-09). The current docstrings already document:swapped), O(n²) avg/worst; O(1) auxiliary.That best-case nuance matters:
bubble_sort_recursiveends withreturn collection if not swapped else bubble_sort_recursive(collection), so an already-sorted input does a single O(n) pass and stops — best case is O(n), not O(n²).All five PRs were opened in May/June 2026, before #14924 merged, and are now superseded — each adds a subset of what
masteralready documents, and none improves on it:master.Recommendation: close #14593 as completed (already fixed by #14924/#15240), and close #14610, #14759, #14823, #14842, #14861 as superseded — with thanks to each contributor for the effort. No merge needed; merging any of them would only re-open the resolved diff (with conflicts against the current PEP 695-typed source) and, for #14610/#14759, introduce an inaccurate best-case claim.
cclauss commentedon Sep 10, 2026
Fixed by