Merge Sort

  • divide-and-conquer technique
  • Divide into subarrays by calculating the midpoint
  • Combine the two adjacent sorted arrays (as if merging two decks of cards)
def merge_sort(A, p, r)
    if p >= r
        return
    q = floor((p + r) / 2)
    merge_sort(A, p, q)
    merge_sort(A, q + 1, r)
    merge(A, p, q, r)
  • The merge process is equivalent to scanning through the real axis and “report” the first number encountered.

-Merge Sort

  • Get the minimum using min-heap
  • When , merge sort becomes heapsort.