Insertion Sort
This sorting algorithm works by repeatedly inserting elements into their correct position in an array.
Last updated
Was this helpful?
This sorting algorithm works by repeatedly inserting elements into their correct position in an array.
Last updated
Was this helpful?
Insertion sort is a simple sorting algorithm that works similarly to the way you sort playing cards in your hands. The array is virtually split into a sorted and an unsorted part. Values from the unsorted part are picked and placed in the correct position in the sorted part.
Question statement:
Notes:
Space Complexity:
constant O(1)
Time complexity:
O(n^2)
Best case:
Already Sorted = {1, 2, 3, 4,} T.C = O(n)
Worst Case:
Reversed Array = {4, 3, 2, 1} T.C = O(n^2)