2c03-review - 00024

2c03-review - 00024 - 2 ) worst case time complexity. The...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
2 Suppose we are lucky and each time a pivot is such that the sublist to its left is of the same size as that to its right. This would leave us with the sorting of two sublists, each of size roughly n/2. Therefore we have: T(n) = 2T(n/2)+cn for some constant c, (or equivalently T(n) = 2T(n/2)+ Θ (n) ). According to Master theorem, case 2, we have T(n)= Θ (nlogn) . One can also use induction or expansion method. b.[10] Prove that Quick Sort has time complexity O(n 2 ) for the worst case. Suppose we are unlucky and each time a pivot is such that the sublist to its left has the size k-1 and the sublist to the right has the length 1, for k=n,n-1,…, 2 Therefore we have: T(n) = T(n-1)+cn for some constant c. By expansion method we have: T(n) = T(n-1)+cn = T(n-2)+2cn = … = T(n-k)+kcn = …. = T(1) + (n-1)cn = O(n 2 ). c.[5] Explain why Quick Sort is considered very efficient despite O(n
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2 ) worst case time complexity. The average case has complexity O(n log n) for practically all distributions. The computational overhead is small as only moving to the left of pivot is costly, moving to the right costs very little (or vice versa dependently if we sort ascending or descending). Hence we have huge time savings in roughly half cases on average. 4.[10] a.[6] Show the heap (complete partially ordered tree) that results if the integers 6,4,7,3,1,9 are inserted into an empty heap. What is the result if DELETEMIN is then applied? b.[4] Show the binary search tree that results if the integers 6,4,7,3,1,9 are inserted into an empty tree. What is the result if DELETEMIN is then applied? a) 1 / \ 3 7 / \ / 6 4 9 After DELETEMIN: 3 / \ 4 7 / \ 6 9...
View Full Document

Ask a homework question - tutors are online