mirror of
https://gitlab.com/magicalsoup/Highschool.git
synced 2025-01-24 00:21:45 -05:00
991 B
991 B
Introduction
Merge sort is a comparison type sort that has an effective use of
recursion and the divide and conquer algorithm.
Merge sort sorts in
\(`O(N \log N)`\) time and uses \(`O(N \log N)`\) space.
We will explore
the pros and cons of this sort the proofs on its time and space
complexity and the implementation and algorithm of this sorting
method.
Abstract: Given two sorted arrays \(`a_{lo}`\) to \(`a_{mid}`\) and \(`a_{mid+1}`\) to \(`a_{hi}`\), replace with sorted subarray \(`a_{lo}`\) to \(`a_{hi}`\).
Basic Algorithm
- Divide array into 2 halves
- Recursively sort each half
- Merge the two halfs.
def mergesort(left, right, array[]):
if left <= right:
= (left + right) / 2
mid
mergesort(left, mid, array[])+1, right, array[])
mergesort(mid mergehalves(left, mid, right, array[])
Running Time Analysis
- Latop computer can run close to \(`10^8`\) per second.
- Supercomputer can execute \(`10^{12}`\) compares per second.