Insertion sort is based on the idea that one element from the input elements is consumed in each iteration to find its correct position i.e, the position to which it belongs in a sorted array. It iterates the input elements by growing the sorted array at each iteration. It compares the current element with the largest value in the sorted array.
Insertion is a simple way or simple algorithm to sort a list. It is much more efficient than bubble sort. But for larger list Insertion sort is not suggested. For that we will study about merge sort and quick sort algorithms. But in this this tutorial we will learn INSERTION SORT algorithm and data structure.
ALGORITHM
1.) First of all take a list. Now compare the second element of the list with left hand side elements of the list i.e. the first element. If second element id greator than swap.
2.) Now take third element, compare it with the left hand side elements i.e. first and second element and place the element accordingly the first and second element.
3.) Go on until the last element, and compare the left hand side elements and place accordingly.
4.) Sorted list will be printed. So this was the simple algorithm.
DATA STRUCTURE in PYTHON
This was the the simple algorithm and data structure of the Insertion Sort. Hope you like this tutorial. Please share it with your friends. In the next tutorial, we will learn about SELECTION SORT algorithm and data structure.
Contact mail id - john.veer.utube@gmail.com
Contact us for any query.
Thank you !

Comments
Post a Comment