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

Function bubble_sort

sorting_algos.py:51–62  ·  view source on GitHub ↗

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

(arr: list)

Source from the content-addressed store, hash-verified

49
50
51def bubble_sort(arr: list) -> list:
52 """TC : O(n^2)
53 SC : O(1)"""
54 n = len(arr)
55 flag = True
56 while flag:
57 flag = False
58 for i in range(1, n):
59 if arr[i - 1] > arr[i]:
60 flag = True
61 arr[i - 1], arr[i] = arr[i], arr[i - 1]
62 return arr
63
64
65def insertion_sort(arr: list) -> list:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected