shikaruki / Hactoberfest2021

Hacktoberfest2021
43 stars 372 forks source link

MergeSort.java #402

Open MUSKAN-GARG1108 opened 1 year ago

MUSKAN-GARG1108 commented 1 year ago

Merge Sort is a divide-and-conquer algorithm. It divides the input array into two halves, calls itself the two halves, and then merges the two sorted halves. The merge() function is used for merging two halves. The merge(arr, l, m, r) is a key process that assumes that arr[l..m] and arr[m+1..r] are sorted and merges the two sorted sub-arrays into one.

Merge Sort Algorithm There are only five steps to understand Merge Sort Algorithm:

Step 1: Divide Array into Two Parts Step 2: Merge Sort the first part of the array Step 3: Merge Sort the second part of the array Step 4: Merge Both the parts Step 5: Return the Sorted Array

The base Condition for Merge Sort is : Divide the Array till the size of the Array is greater than 1