categories: computer science
Hello everyone,
Below you will find a video with a detailed explanation of the insertion sort algorithm. Its operation, time complexity, and usefulness. Below you will also find ready-made code to copy if needed.
Code:
tab = [5, 8, 3, 1, 0, 9]
n = len(tab)
for i in range(1, n):
j = i - 1
porownujaca = tab[i]
while j > -1 and tab[j] > porownujaca:
tab[j + 1] = tab[j]
j -= 1
tab[j + 1] = porownujaca
for k in tab:
print(str(k), sep=" ", end=None)
Video:
Thank you for reading!
Read more