Insertion Sort and Merge Sort in C++

Insertion Sort

The insertion sort algorithm puts a set of elements in a specific order. Every iteration of the insertion sort algorithm moves an element from the unsorted to the sorted portion of the list until all of the elements in the list are sorted.

Working of Insertion Sort

  • The first step is to compare the element with its neighboring element.
  • And if each comparison shows that the element can be inserted at a specific place, then space is made for it by relocating the other elements in one position to the right and inserting the element at the appropriate place.
  • The above process is continued until all of the elements in the array are in their proper location.

Merge Sort

Merge Sort is a popular sorting algorithm that is based on the Divide and Conquers Algorithm idea. A problem is broken into several sub-problems in this case. Each sub-problem is addressed separately. Sub-problems are then integrated to generate the final solution.

All the details discuss with code in the video below:

 

Recommended:

LEAVE A REPLY

Please enter your comment!
Please enter your name here