Merge Sort


Merge sort is a comparison-based sorting algorithm based on the  divide-and-conquer algorithm. The goal of the algorithm is to implements the input elements into the sorted output.

Here is an example of Merge Sort.

The unsorted array: 6 2 4 1 5 9

Step 1: [6 2 4 1 5 9]

Step2: [2 6] [1 4] [5 9]

Step3: [1 2 4 6] [5 9]

Step4: [1 2 4 5 6 9]

The output will be [1 2 4 5 6 9].

The advantage of the Merge sort is able to sort data from sequence and slow access data, such as tape or hard disk.

image

https://en.wikipedia.org/wiki/Merge_sort