And to merge the subarrays, made by dividing the original array of n elements, a running time of O n will be required. Let us call these arrays as left half and right half respectively. In merge sort we follow the following steps: We take a variable p and store the starting index of our array in this.
Here is how the sorted subarrays will look like: Recursively sorted left half: [1, 4, 5, 6] Recursively sorted right half: [2, 3, 7] Finally, as per step 3, we will merge these 2 halves to create the final sorted array.
But breaking the orignal array into 2 smaller subarrays is not helping us in sorting the array. The concept of Divide and Conquer involves three steps: Divide the problem into multiple small problems.
Moreover, merge sort is of interest because it creates an excellent case study for one of the widely used techniques in Computer Science — divide and conquer.
Now, the idea here is that an array with a single element is already sorted, so once we break the original array into subarrays which has only a single element, we have successfully broken down our problem into base problems.
Before jumping on to, how merge sort works and it's implementation, first lets understand what is the rule of Divide and Conquer? Well that was history, and a socio-political policy Divide and Rulebut the idea here is, if we can somehow divide a problem into smaller sub-problems, it becomes easier to eventually solve the whole problem.
In merge sort, we break the given array midway, for example if the original array had 6 elements, then merge sort will break it down into two subarrays with 3 elements each. Divide and Conquer If we can break a single big problem into smaller sub-problems, solve the smaller sub-problems and combine their solutions to find the solution for the original big problem, it becomes easier to solve the whole problem.
Conclusion Spread the Knowledge Merge sort is one of the most powerful sorting algorithms. Let us understand the detailed steps involved in performing a merge sort in the above array: [6, 4, 5, 1, 2, 7, 3] is divided into [6, 4, 5, 1] and [2, 7, 3] [6, 4, 5, 1] is divided into [6, 4] and [5, 1] [6, 4] is divided into  and   is a single element array and so, is sorted.