How the insertion sort is done with the array?
3 years ago
Data Structure and Algorithm
It sorts a list of elements by inserting each successive element in the previously sorted sublist.
Consider an array to be sorted A[1],A[2],….A[n]
- Pass 1 : A[2] is compared with A[1] and placed them in sorted
- Pass 2 : A[3] is compared with both A[1] and A[2] and inserted at an appropriate This makes A[1], A[2],A[3] as a sorted sub array.
- Pass n-1 : A[n] is compared with each element in the sub array A[1],A[2],……A[n-1] and inserted at an appropriate
Sanisha Maharjan
Jan 23, 2022