answersLogoWhite

0

Suppose (for simplicity) that n = 2k for some entire k. Let T(n) the time used to sort n elements. As we can perform separation and merging in linear time, it takes cn time to perform these two steps, for some constant c. So, T(n) = 2T(n/2) + cn.

In the same way:

T(n/2) = 2T(n/4) + cn/2, so

T(n) = 4T(n/4) + 2cn. Going in this way ... T(n) = 2mT(n/2m) + mcn, and

T(n) = 2kT(n/2k) + kcn = nT(1) + cnlog2n = O(n log n). Remember, as n=2k k = log2n! The general case requires a bit more work, but it takes O(n log n) time anyway.

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

What is the Big O notation of the selection sort algorithm?

The Big O notation of the selection sort algorithm is O(n2), indicating that its time complexity is quadratic.


What are some examples of algorithms that exhibit quadratic time complexity?

Some examples of algorithms that exhibit quadratic time complexity include bubble sort, selection sort, and insertion sort. These algorithms have a time complexity of O(n2), meaning that the time it takes to execute them increases quadratically as the input size grows.


Is selection sort and tournament sort are same?

No. Tournament sort is a variation of heapsort but is based upon a naive selection sort. Selection sort takes O(n) time to find the largest element and requires n passes, and thus has an average complexity of O(n*n). Tournament sort takes O(n) time to build a priority queue and thus reduces the search time to O(log n) for each selection, and therefore has an average complexity of O(n log n), the same as heapsort.


What is the running time of heap sort algorithm in terms of time complexity?

The running time of the heap sort algorithm is O(n log n) in terms of time complexity.


What is the time complexity of heap sort algorithm?

The time complexity of the heap sort algorithm is O(n log n), where n is the number of elements in the input array.


What is the time complexity of quick sort algorithm?

The time complexity of the quick sort algorithm is O(n log n) in the average case and O(n2) in the worst case.


What is the time complexity of the best case scenario for Bubble Sort?

The time complexity of the best case scenario for Bubble Sort is O(n), where n is the number of elements in the array.


What is the worst case time complexity of heap sort?

The worst case time complexity of heap sort is O(n log n), where n is the number of elements in the input array.


What is the worst case time complexity of quick sort algorithm?

The worst case time complexity of the quick sort algorithm is O(n2), where n is the number of elements in the input array.


Calculate the Time and Space complexity for the Algorithm to add 10 numbers?

The algorithm will have both a constant time complexity and a constant space complexity: O(1)


What is the average case time complexity of the Bubble Sort algorithm?

The average case time complexity of the Bubble Sort algorithm is O(n2), where n is the number of elements in the array being sorted.


What is the best case time complexity of heap sort?

The best case time complexity of heap sort is O(n log n), where n is the number of elements in the array being sorted.