Merge sort running time O(nlogn) formula

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
ducmod
Messages
86
Reaction score
0
Hello!
If T denotes running time, then, as I heard at the lecture,

T(n/2) + T(n/2) + O(n) = O(nlogn)

where T(n/2) running time for sorting the left half
T(n/2) running time for sorting the right half
O(n) merging sorted

Please, help me to see the math - how did the left side of expression turned into the right side one?

Thank you!
 
Physics news on Phys.org
That requires T(n/2) to be O(n logn) and the equal sign is problematic.
I think the underlying idea is: If you can combine two sets of n/2 elements within O(n) steps, the completely combining n sets of 1 element each to a single set of n elements requires O(n log n) steps because you get log(n) merging steps (lists of 1 -> lists of 2 -> lists of 4 -> ...)