Learn Before
Concept
Logic behind Merge Sort
This algorithm is recursive by nature; it divides the input array into two halves, then merges the two sorted halves. The merge() function is used for merging two halves.
Pseudocode:
# Let the array arr[] be of length n. 1. FInd the middle point to divide the array into two halves. middle m = 1 + (n -1) /2 2. Call mergeSort for first half. mergeSort(arr, 1, m) 3. Call mergeSort for second half. mergeSort(arr, m + 1, n) 4. Merge the two halves. merge(arr, 1, m, r)
0
1
Updated 2021-07-20
Tags
Python Programming Language
Data Science