Skip to content

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

Description

@jgohel9902

Feature description

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:

def bubble_sort(collection: list) -> list:
"""
Bubble Sort Algorithm.

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis PR modified some existing files

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions