Skip to content

Commit dd66eab

Browse files
improve docstrings in insertion_sort.py to include complexity analysis
1 parent e3b01ec commit dd66eab

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

sorts/insertion_sort.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def insertion_sort[T: Comparable](collection: MutableSequence[T]) -> MutableSequ
3030
:param collection: some mutable ordered collection with heterogeneous
3131
comparable items inside
3232
:return: the same collection ordered by ascending
33+
34+
Time Complexity: O(n^2) - worst and average case
35+
Time Complexity: O(n) - best case (already sorted, inner while never runs)
36+
Space Complexity: O(1) - sorts in place, no extra memory used
3337
3438
Examples:
3539
>>> insertion_sort([0, 5, 3, 2, 2])

0 commit comments

Comments
 (0)