0% found this document useful (0 votes)
6 views

Sorting Merging Sort

Merge Sort is a popular sorting algorithm that utilizes the Divide and Conquer strategy to solve problems by breaking them into sub-problems, sorting each individually, and then combining the results. The algorithm repeatedly divides the array until it reaches subarrays of size one, after which it merges the sorted subarrays back together. The merge step specifically focuses on combining two sorted lists into a single sorted list.

Uploaded by

helper bisht
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Sorting Merging Sort

Merge Sort is a popular sorting algorithm that utilizes the Divide and Conquer strategy to solve problems by breaking them into sub-problems, sorting each individually, and then combining the results. The algorithm repeatedly divides the array until it reaches subarrays of size one, after which it merges the sorted subarrays back together. The merge step specifically focuses on combining two sorted lists into a single sorted list.

Uploaded by

helper bisht
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Sorting-Merging

Sort
Definition
• Merge Sort is one of the most popular sorting algorithms
that is based on the principle of
Divide and Conquer Algorithm.
• Here, a problem is divided into multiple sub-problems.
Each sub-problem is solved individually. Finally, sub-
problems are combined to form the final solution.
Divide and Conquer Strategy
• Using the Divide and Conquer technique, we divide a problem into subproblems. When the
solution to each subproblem is ready, we 'combine' the results from the subproblems to solve
the main problem.
• Suppose we had to sort an array A. A subproblem would be to sort a sub-section of this array
starting at index p and ending at index r, denoted as A[p..r].
• DIVIDE:If q is the half-way point between p and r, then we can split the subarray A[p..r] into
two arrays A[p..q] and A[q+1, r].
• CONQUER:In the conquer step, we try to sort both the subarrays A[p..q] and A[q+1, r]. If
we haven't yet reached the base case, we again divide both these subarrays and try to sort
them.
• COMBINE:When the conquer step reaches the base step and we get two sorted
subarrays A[p..q] and A[q+1, r] for array A[p..r], we combine the results by creating a sorted
array A[p..r] from two sorted subarrays A[p..q] and A[q+1, r].
MergeSort Algorithm
• The MergeSort function repeatedly divides the array into two halves until
we reach a stage where we try to perform MergeSort on a subarray of size 1
i.e. p == r.
• After that, the merge function comes into play and combines the sorted
arrays into larger arrays until the whole array is merged

• To sort an entire array, we need to call MergeSort(A, 0, length(A)-1)


• THE MERGE STEP OF MERGE SORT

• The merge step is the solution to the simple problem of


merging two sorted lists(arrays) to build one large sorted
list(array).
Merge operation

You might also like