0% found this document useful (0 votes)
7 views6 pages

Merge

Merge Sort is a Divide and Conquer algorithm that divides an input array into two halves, recursively sorts them, and then merges the sorted halves using the merge() function. The process continues until the array is fully sorted, starting from individual elements and merging them back together. An example illustrates the recursive division and merging of the array {38, 27, 43, 3, 9, 82, 10}.

Uploaded by

abhinavsrivas3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

Merge

Merge Sort is a Divide and Conquer algorithm that divides an input array into two halves, recursively sorts them, and then merges the sorted halves using the merge() function. The process continues until the array is fully sorted, starting from individual elements and merging them back together. An example illustrates the recursive division and merging of the array {38, 27, 43, 3, 9, 82, 10}.

Uploaded by

abhinavsrivas3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Merge Sort

Definition
• Like Quick Sort, Merge Sort is a Divide and
Conquer algorithm.
• It divides input array in two halves, calls itself for
the two halves and then merges the two sorted
halves.
• The merge() function is used for merging two
halves.
Steps
• Find the middle index of the array to divide it in two
halves: m = (l+r)/2.
• Call MergeSort for first half: mergeSort(array, l, m)
• Call mergeSort for second half: mergeSort(array, m+1,
r)
• Recursively, merge the two halves in a sorted manner,
so that only one sorted array is left:
Example
• The following diagram shows the complete merge sort
process for an example array {38, 27, 43, 3, 9, 82, 10}. If we
take a closer look at the diagram, we can see that the array
is recursively divided in two halves till the size becomes 1.
Once the size becomes 1, the merge processes comes into
action and starts merging arrays back till the complete array
is merged.
Made By :- AKTU WALA ( Satyam Sahu )

You might also like