Merge sort running time O(nlogn) formula

Click For Summary
SUMMARY

The discussion centers on the running time of the merge sort algorithm, specifically the formula T(n) = T(n/2) + T(n/2) + O(n) = O(n log n). The participants clarify that T(n/2) represents the running time for sorting each half of the array, and O(n) accounts for the merging process. The conclusion is that the logarithmic factor arises from the repeated merging of smaller sorted lists, leading to an overall complexity of O(n log n).

PREREQUISITES
  • Understanding of algorithmic complexity, specifically Big O notation
  • Familiarity with the merge sort algorithm and its recursive nature
  • Basic knowledge of mathematical induction and recursive functions
  • Concept of merging sorted lists and its computational implications
NEXT STEPS
  • Study the derivation of the Master Theorem for analyzing recursive algorithms
  • Learn about the implementation of merge sort in Python or Java
  • Explore the concept of divide and conquer algorithms in depth
  • Investigate other sorting algorithms and their time complexities for comparison
USEFUL FOR

Students, computer science enthusiasts, and software developers looking to deepen their understanding of sorting algorithms and their performance analysis.

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 -> ...)
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 12 ·
Replies
12
Views
5K
Replies
5
Views
2K
  • · Replies 25 ·
Replies
25
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K