From 8d0ca1729d0f0f5718485bdf4ea96b0cee884ab5 Mon Sep 17 00:00:00 2001 From: Ha Anh Nguyen Date: Wed, 31 Oct 2018 23:16:56 +0200 Subject: [PATCH] Summarize time complexity of merge sort (#20632) Add simple way to remember time complexity of merge sort --- guide/english/algorithms/sorting-algorithms/merge-sort/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guide/english/algorithms/sorting-algorithms/merge-sort/index.md b/guide/english/algorithms/sorting-algorithms/merge-sort/index.md index d598f1d0d9..10d1a89a4f 100644 --- a/guide/english/algorithms/sorting-algorithms/merge-sort/index.md +++ b/guide/english/algorithms/sorting-algorithms/merge-sort/index.md @@ -21,7 +21,7 @@ T(n) = 2T(n/2) + n = n + n + ... + n + n + n ``` -Counting the number of repetitions of n in the sum at the end, we see that there are lg n + 1 of them. Thus the running time is n(lg n + 1) = n lg n + n. We observe that n lg n + n < n lg n + n lg n = 2n lg n for n>0, so the running time is O(n lg n). +Counting the number of repetitions of n in the sum at the end, we see that there are lg n + 1 of them. Thus the running time is n(lg n + 1) = n lg n + n. We observe that n lg n + n < n lg n + n lg n = 2n lg n for n>0, so the running time is O(n lg n). Another simple way to remember the time complexity O(n lg n) of merge sort is that it takes roughly log2n steps to split an array of size n to multiple arrays of size one. After each split, the algorithm have to merge 2 sorted arrays into one which can take n steps in total. As a result, the time complexity for merge sort is O(n lg n). ```Algorithm MergeSort(arr[], left, right):