Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sorts/insertion_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 8 additions & 3 deletions sorts/pancake_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
python pancake_sort.py
"""

from __future__ import annotations


def pancake_sort(arr):
"""Sort Array with Pancake Sort.
Expand All @@ -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:
Expand All @@ -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()