MCPcopy Create free account
hub / github.com/geekcomputers/Python / insertion_sort

Function insertion_sort

sorting_algos.py:65–75  ·  view source on GitHub ↗

TC : O(n^2) SC : O(1)

(arr: list)

Source from the content-addressed store, hash-verified

63
64
65def insertion_sort(arr: list) -> list:
66 """TC : O(n^2)
67 SC : O(1)"""
68 n = len(arr)
69 for i in range(1, n):
70 for j in range(i, 0, -1):
71 if arr[j - 1] > arr[j]:
72 arr[j - 1], arr[j] = arr[j], arr[j - 1]
73 else:
74 break
75 return arr
76
77
78def merge_sort(arr: list) -> list:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected