Skip to content

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

@jgohel9902

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis PR modified some existing files

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions