Algorithm


Merge Sort Algorithm:

  1. Start with an unsorted array.
  2. Divide the array into two halves recursively until each subarray contains only one element.
  3. Merge the subarrays back together in a sorted manner:
    1. Compare the elements of both subarrays.
    2. Place the smaller element into the sorted array.
    3. Repeat the comparison and placement until all elements are merged.
  4. The merging process continues until the entire array is sorted.

Example:

Merge Sort Example

Fig. 1: Iteration by Iteration Visualization of Merge Sort

Note: Merge Sort efficiently divides and conquers, making it suitable for large datasets.