MergeSort is a divide-and-conquer algorithm that splits an array into two halves (sub arrays) and recursively sorts each sub array before merging them back into one giant, sorted array.
In this blog, I will provide a simple implementation of Merge Sort using C# with comments on every significant line of code for beginners to quickly grasp the algorithm.
Pseudocode
mergeSort(array)
mergeSort(array)
if array.length <= 1 then
return array
left = new array
right = new array
mid = left+ right/2
mergeSort(left)
mergeSort(right)
merge(left, right)
You can now go ahead and call your Merge Sort(array) method from Main to see the results
Post a Comment