As soon as we started programming, we found to our surprise that it wasn’t as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs. Maurice Wilkes

Insertion sort

Language Java | Level Intermediate | Category Algorithms | August 2, 2015 8:55 pm

Algorithm Problem Description

Insertion sort is a simple sorting algorithm that builds sorted array one item at a time. It is efficient for the small data set.

Insertion sort is best suitable for nearly sorted arrays and the small set of elements. It is similar to selection sort. The selection sort must scan all the elements to find the smallest element. But the insertion sort scans only the remaining elements in the array. The insertion sort can combine with divide and conquer based algorithm for better optimization.

Write a program to implement the insertion sort.



Unsorted array before sorting: [12, 34, 56, 23, 45, 78, 46]
Sorted array After Insertion Sort sorting: [12, 23, 34, 45, 46, 56, 78]



Please login to add comments.