πŸŽ“ Computer Science & Engineering Portal

Master Engineering Disciplines with Structured Notes

Comprehensive academic lecture notes, exam-oriented unit summaries, laboratory manuals, and previous year question papers designed strictly for university students.

πŸ“‘

University Syllabi

AKTU & AICTE aligned semester credit guidelines.

πŸ“

Exam Question Papers

Previous 5 years solved university semester papers.

πŸ’‘

Lab Manuals & Viva

Practical codes with outputs and interview questions.

πŸ“š All Topics & Units Directory

Click on any subject tag to open its genuine notes directly

Loading your subjects directory...

Merge Sort Algorithm

Merge sort is one of the most efficient sorting algorithms. It works on the principle of Divide and Conquer. Merge sort repeatedly breaks down a list into several sublists until each sublist consists of a single element and merging those sublists in a manner that results into a sorted list.

enter image description here

enter image description here

The top-down merge sort approach is the methodology which uses recursion mechanism. It starts at the Top and proceeds downwards, with each recursive turn asking the same question such as β€œWhat is required to be done to sort the array?” and having the answer as, β€œsplit the array into two, make a recursive call, and merge the results.”, until one gets to the bottom of the array-tree.

Example: Let us consider an example to understand the approach better.

  1. Divide the unsorted list into n sublists, each comprising 1 element (a list of 1 element is supposed sorted).

Working of Merge Sort

Top-down Implementation

  1. Repeatedly merge sublists to produce newly sorted sublists until there is only 1 sublist remaining. This will be the sorted list.

The first element of both lists is compared. If sorting in ascending order, the smaller element among two becomes a new element of the sorted list. This procedure is repeated until both the smaller sublists are empty and the newly combined sublist covers all the elements of both the sublists.

Merging Two Lists

Merging of two lists


Complexity:-


Labels: ,

Discussion & Queries (<$I18NNumComments$>):

<$CommentPager$>
<$I18NAtCommentTimeWithPermalink$>, <$I18NCommentAuthorSaid$>

<$BlogCommentBody$>

<$BlogCommentDeleteIcon$>
<$CommentPager$>