Embed presentation
Download to read offline



![PSEUDOCODE
INSERTION-SORT(A)
for i = 1 to n
key ← A [i]
j ← i – 1
while j > = 0 and A[j] > key
A[j+1] ← A[j]
j ← j – 1
End while
A[j+1] ← key
End for](https://image.slidesharecdn.com/insertionsort-201218203515/75/Insertion-sort-4-2048.jpg)






Insertion sort is an algorithm that builds a sorted array one item at a time by taking each element and inserting it into the correct position in the sorted portion of the array. It works by comparing adjacent elements and swapping them if they are in the wrong order, similar to arranging a deck of cards. The algorithm iterates through the array, picking an element and inserting it into the sorted position by shifting greater elements over to make space.



![PSEUDOCODE
INSERTION-SORT(A)
for i = 1 to n
key ← A [i]
j ← i – 1
while j > = 0 and A[j] > key
A[j+1] ← A[j]
j ← j – 1
End while
A[j+1] ← key
End for](https://image.slidesharecdn.com/insertionsort-201218203515/75/Insertion-sort-4-2048.jpg)





