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

16y ago

What else can I help you with?

Continue Learning about Engineering

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 best case complexity of selection sort algorithm?

The best case complexity of the selection sort algorithm is (O(n^2)). This is because the algorithm always consists of two nested loops: one for selecting each element and another for finding the minimum element from the unsorted portion of the array. Regardless of the initial order of the elements, selection sort will always perform the same number of comparisons and swaps, leading to a quadratic time complexity.


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 time complexity of radix sort?

If the range of numbers is 1....n and the size of numbers is k(small no.) then the time complexity will be theta n log..


How do you select pivot in quick sort?

quick sort has a best case time complexity of O(nlogn) and worst case time complexity of 0(n^2). the best case occurs when the pivot element choosen as the center or close to the center element of the list.the time complexity can be derived for this case as: t(n)=2*t(n/2)+n. whereas the worst case time complexity for quick sort happens when the pivot element is towards the end of the list.the time complexity for this can be derived using the recurrence eqn: t(n)=t(n-1)+n

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 best case complexity of selection sort algorithm?

The best case complexity of the selection sort algorithm is (O(n^2)). This is because the algorithm always consists of two nested loops: one for selecting each element and another for finding the minimum element from the unsorted portion of the array. Regardless of the initial order of the elements, selection sort will always perform the same number of comparisons and swaps, leading to a quadratic time complexity.


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.


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.