Merge is the core technology of MergeSort, that is why it was named MergeSort.
convert input array -> left_part and right_part
left_sorted_part = MergeSort(left_part)
right_sorted_part = MergeSort(right_part)
Merge(left_sorted_part, right_sorted_part)
- taking one (
l) fromleft_sorted_part - taking one (
r) fromright_sorted_part - find the smaller(
s) one inlandr - put
sintoresult array - put bigger one back to
left_sorted_partorright_sorted_part - loop to step 1 until one is empty