The Insertion sort is another simple sorting algorithm, which can be used to sort any linear data structure like an array or linked list.
It is a simple sorting algorithm that builds the final sorted array one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.
Every repetition of insertion sort removes an element from the input data, inserting it into the correct position in the already-sorted list, until no input elements remain.
The choice of which element to remove from the input is arbitrary, and can be made using almost any choice algorithm.
Time Complexity :
Worst case performance : О(n2) comparisons, swaps
Best case performance : O(n) comparisons, O(1) swaps
Average case performance : О(n2) comparisons, swaps
Here is the source code of the Java Program to perform Insertion Sort. The Java program is successfully compiled and run on a Windows system. The program output is also shown below :
SOURCE CODE : :
OUTPUT : :
need an explanation for this answer? contact us directly to get an explanation for this answer