

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Sorting Algorithms
incomplete
2: Bubble Sort
incomplete
3: Bubble Sort Big O
incomplete
4: Why Bubble Sort?
incomplete
5: Merge Sort
incomplete
6: Merge Sort Big O
incomplete
7: Why Merge Sort?
incomplete
8: Insertion Sort
incomplete
9: Insertion Sort Big O
incomplete
10: Why Use Insertion Sort?
incomplete
11: Quick Sort
incomplete
12: Quick Sort Big O
incomplete
13: Fixing Quick Sort
incomplete
14: Why Use Quick Sort?
incomplete
15: Selection Sort
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Insertion sort has a Big O of O(n^2), because that is its worst case complexity.
The outer loop of insertion sort always executes n times, while the inner loop depends on the input.
O(n^2) because the inner loop will execute about half of the time.O(n^2) and the inner loop will execute every time.def insertion_sort(nums: list[int]) -> list[int]:
for i in range(len(nums)):
j = i
while j > 0 and nums[j - 1] > nums[j]:
nums[j], nums[j - 1] = nums[j - 1], nums[j]
j -= 1
return nums