Merge sort is a recursive sorting algorithm and, luckily for us, it’s quite a bit faster than bubble sort. Merge sort is a divide and conquer algorithm.
Merge sort actually has two functions involved, the recursive mergeSort
function, and the merge
function.
Let’s write the mergeSort()
function first. It’s a recursive function, which means it calls itself, and in this case, it actually calls itself twice. The point of the mergeSort
function is to split the array into two roughly equal parts, call itself on those parts, then call merge()
to fit those halves back together.
#golang #go