From 057498ebc01641147ffd42a2f7ffd6ce2cf60350 Mon Sep 17 00:00:00 2001 From: James Su Date: Fri, 25 Oct 2019 16:05:02 +0000 Subject: [PATCH] Update Merge Sort.md --- .../ICS4U1/Sorting Methods/Merge Sort.md | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/Grade 10/Computer Science/ICS4U1/Sorting Methods/Merge Sort.md b/Grade 10/Computer Science/ICS4U1/Sorting Methods/Merge Sort.md index 2b6ddcf..63ed5a3 100644 --- a/Grade 10/Computer Science/ICS4U1/Sorting Methods/Merge Sort.md +++ b/Grade 10/Computer Science/ICS4U1/Sorting Methods/Merge Sort.md @@ -1,4 +1,25 @@ ## 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. \ No newline at end of file +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. + +```py +def mergesort(left, right, array[]): + if left <= right: + mid = (left + right) / 2 + mergesort(left, mid, array[]) + mergesort(mid+1, right, array[]) + 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. +