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
AI Thread 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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top