Algorithm: Insertion Sort
Goal: Sort an array of numbers in ascending order using Insertion Sort.
Steps:
- Start
- Input
n(number of elements in the array). - Input the array
arr[0…n-1]. - For
i = 1ton-1:- Set
key = arr[i]. - Set
j = i - 1. - While
j >= 0andarr[j] > key:- Set
arr[j+1] = arr[j]. - Decrement
j = j - 1.
- Set
- Set
arr[j+1] = key.
- Set
- Print the sorted array.
- Stop.
Flowchart: Insertion Sort

Post Comment