Merge sort running time O(nlogn) formula

In summary, The conversation discusses the running time of sorting an array using divide and conquer approach. It is mentioned that the running time of sorting the left half and right half is T(n/2) and the merging of the sorted halves has a running time of O(n). The equation T(n/2) + T(n/2) + O(n) = O(nlogn) is given and the question is asked about the math behind it. The underlying idea is that combining two sets of n/2 elements within O(n) steps results in a total running time of O(nlogn) when combining n sets of 1 element each.
  • #1
ducmod
86
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
  • #2
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 -> ...)
 

1. What is the time complexity of Merge Sort?

The time complexity of Merge Sort is O(nlogn), which means that the algorithm runs in linearithmic time. This is a very efficient running time for sorting algorithms.

2. How is the time complexity of Merge Sort calculated?

The time complexity of Merge Sort is calculated by analyzing the number of comparisons and operations needed to sort a list of n elements. It is determined by the number of times the list is divided in half (logn) and the number of comparisons needed to merge the divided lists (n).

3. Why is the time complexity of Merge Sort O(nlogn)?

The time complexity of Merge Sort is O(nlogn) because the algorithm follows a divide and conquer approach, where the list is divided into smaller sublists until they are sorted. This results in a logarithmic time complexity for the division process, and a linear time complexity for the merging process, resulting in a overall time complexity of O(nlogn).

4. Can Merge Sort have a different running time in different scenarios?

No, the time complexity of Merge Sort is always O(nlogn) regardless of the initial order of the elements in the list. This is because the algorithm always follows the same steps of dividing and merging the list, regardless of the content of the list.

5. Is there a way to make Merge Sort run faster than O(nlogn)?

No, the time complexity of Merge Sort is already very efficient at O(nlogn). It is considered one of the most efficient sorting algorithms, and it is not possible to improve its time complexity. However, there may be variations of the algorithm that can improve its space complexity or running time in certain scenarios.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Precalculus Mathematics Homework Help
Replies
17
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
721
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
4K
  • Set Theory, Logic, Probability, Statistics
Replies
9
Views
2K
Replies
56
Views
713
Back
Top