MHB Why is the runtime of Merge Sort O(n log n)?

  • Thread starter Thread starter find_the_fun
  • Start date Start date
  • Tags Tags
    Runtime Sort
Click For Summary
The discussion centers on the runtime complexity of the merge sort algorithm, specifically T(n) = nb + cn log(n). The confusion arises regarding why this is classified as O(n log n). It is clarified that for sufficiently large n (n > n0, where n0 is greater than the logarithm's base), the terms can be simplified. The dominant term in the expression is cn log(n), which grows faster than nb for large n. Therefore, the overall runtime can be expressed as being bounded by a constant multiple of n log(n), confirming that merge sort operates within O(n log n) complexity due to the constants b and c not affecting the growth rate as n increases.
find_the_fun
Messages
147
Reaction score
0
For megre sort alogirthm the runtime is T(n)=nb+cnlog(n). It's not quite clear to me why this is O(nlogn) is it because b and c are constants?
 
Technology news on Phys.org
find_the_fun said:
For megre sort alogirthm the runtime is T(n)=nb+cnlog(n). It's not quite clear to me why this is O(nlogn) is it because b and c are constants?

It is because for \(n>n_0\) where \(n_0>0\) is greater than the base of the logarithm (so \( \log(n)>1\) )
:

\[|T(n)|=|n \; b+c\; n \log(n)|<|b| \; n+|c|\; n \log(n)<|b|\; n \log(n)+ |c|\; n \log(n) = A\; n \log(n)\]

CB
 
Last edited:

Similar threads

  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 36 ·
2
Replies
36
Views
6K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K