diff --git a/sorts/insertion_sort.py b/sorts/insertion_sort.py index 2e39be255df7..22767aaf2525 100644 --- a/sorts/insertion_sort.py +++ b/sorts/insertion_sort.py @@ -31,6 +31,14 @@ def insertion_sort[T: Comparable](collection: MutableSequence[T]) -> MutableSequ comparable items inside :return: the same collection ordered by ascending + Time Complexity: + Best Case: O(n) + Average Case: O(n²) + Worst Case: O(n²) + + Space Complexity: + O(1) - sorts in place + Examples: >>> insertion_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] diff --git a/sorts/pancake_sort.py b/sorts/pancake_sort.py index e5d600738435..c8ab9740972c 100644 --- a/sorts/pancake_sort.py +++ b/sorts/pancake_sort.py @@ -8,6 +8,8 @@ python pancake_sort.py """ +from __future__ import annotations + def pancake_sort(arr): """Sort Array with Pancake Sort. @@ -20,6 +22,9 @@ def pancake_sort(arr): [] >>> pancake_sort([-2, -5, -45]) [-45, -5, -2] + + Time Complexity: (O(n^2)) + Space Complexity: (O(n)) """ cur = len(arr) while cur > 1: @@ -34,6 +39,6 @@ def pancake_sort(arr): if __name__ == "__main__": - user_input = input("Enter numbers separated by a comma:\n").strip() - unsorted = [int(item) for item in user_input.split(",")] - print(pancake_sort(unsorted)) + import doctest + + doctest.testmod()