Back to Browse

Insertion Sort Technique in Data Structure Using C

11 views
Mar 25, 2021
30:02

Insertion sort is faster than Bubble sort. In this sorting technique we can compare first element to it next element, if first element greater than next element than swapping it. After second element compare to next element, if second element greater than it next element than swapping it and continue this process until we find than whole sorted list as sorting in ascending or descending order. In this technique we can’t find any largest element at the last element or the smaller element at the first element until sorted whole list. Assume that an array x content five elements. The bubble sort algorithm works as follows : 1. In the first iteration the 0th element 9 is compared with 1st element 7 and since 9 is greater than 7, they are interchanged. 2. Now the 1st element 9 is compared with 2nd element 5 and since 9 is grater than 5, they are interchanged. 3. Now the 2nd element 9 is compared with 3rd element 8 and since 9 is grater than 8, they are interchanged. 4. Now at last of the first iteration, 3rd 9 is compared with 4th element 3 and since 9 is greater than 3, they are interchanged. 5. These same processes apply on rest of other iterations. 6. This process is repeated until (N-2) element is compared with (N-1)th element. During the comparison if (N-2) element is found to be greater than the (N-1) ,then they are interchanged, otherwise not. 7. At the end of the first iteration, the (N-1) element hold the largest element. Advantages of Insertion sort are as follow: 1. It is very simple sorting technique. 2. It is very easy to implementation. Disadvantages of Insertion sort are as follow: 1. Large list can’t handle. 2. It’s not efficient sorting technique. 3. In this sorting technique we can not find first large or smaller element of array.

Download

0 formats

No download links available.

Insertion Sort Technique in Data Structure Using C | NatokHD