Skip to content

docs(sorts): add complexity analysis to bubble_sort.py docstrings#14759

Open
ltianyi992 wants to merge 1 commit into
TheAlgorithms:masterfrom
ltianyi992:fix/issue-14593-bubble-sort-docstring
Open

docs(sorts): add complexity analysis to bubble_sort.py docstrings#14759
ltianyi992 wants to merge 1 commit into
TheAlgorithms:masterfrom
ltianyi992:fix/issue-14593-bubble-sort-docstring

Conversation

@ltianyi992
Copy link
Copy Markdown

Closes #14593

Description

Improves the docstrings in sorts/bubble_sort.py to include time and space complexity analysis, making the implementation more educational and consistent with the repository's goal as a learning resource.

Changes

bubble_sort_iterative:

  • Added a brief description of how the algorithm works
  • Added Time Complexity: O(n) best case (early exit), O(n²) average/worst
  • Added Space Complexity: O(1) — in-place
  • Added Stable: Yes

bubble_sort_recursive:

  • Added a brief description of the recursive approach
  • Added Time Complexity: O(n²) all cases (no early exit due to call stack)
  • Added Space Complexity: O(n) — recursive call stack
  • Added Stable: Yes

Checklist

  • I have read CONTRIBUTING.md
  • This PR only changes one file
  • Documentation change only
  • All existing doctests pass (python3 -m doctest sorts/bubble_sort.py — 40 tests, all pass)

@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve docstrings in sorts/bubble_sort.py to include complexity analysis

1 participant