Insertion Sort

00:00
EasySortingArrayComparison Sort
TCSWiproInfosys

Sort array using insertion sort: build sorted portion one element at a time by inserting each element into its correct position.

Examples

Input → [12,11,13,5,6]
Output → [5,6,11,12,13]
Input → [1,2,3,4,5]
Output → [1,2,3,4,5]
Note: already sorted, On
Input → [5,4,3,2,1]
Output → [1,2,3,4,5]
Note: worst case