Skip to content

Commit 3cbb2b9

Browse files
shreya-learn-exploresShreyapre-commit-ci[bot]cclauss
authored
Improve insertion_sort docstring with complexity analysis (#14875)
* Improve insertion_sort docstring with complexity analysis * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix doctest formatting * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Apply suggestion from @cclauss --------- Co-authored-by: Shreya <youremail@example.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent 76895aa commit 3cbb2b9

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

sorts/pancake_sort.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def pancake_sort[T](arr: Sequence[T]) -> list[T]:
2525
[]
2626
>>> pancake_sort([-2, -5, -45])
2727
[-45, -5, -2]
28+
29+
Time Complexity: (O(n^2))
30+
Space Complexity: (O(n))
2831
"""
2932
cur = len(arr)
3033
while cur > 1:
@@ -39,6 +42,9 @@ def pancake_sort[T](arr: Sequence[T]) -> list[T]:
3942

4043

4144
if __name__ == "__main__":
45+
import doctest
46+
47+
doctest.testmod()
4248
user_input = input("Enter numbers separated by a comma:\n").strip()
4349
unsorted = [int(item) for item in user_input.split(",")]
44-
print(pancake_sort(unsorted))
50+
print(f"{pancake_sort(unsorted) = }")

0 commit comments

Comments
 (0)