fundamentals of algorithmics.pdf (page 200 of 530) Q Search Protiom 8.24. For he
ID: 3902310 • Letter: F
Question
fundamentals of algorithmics.pdf (page 200 of 530) Q Search Protiom 8.24. For heapsort, what are the best and the worst initial arrangements of the elements to be sorted, as far as the execution time of the algorithm is concerned? Justify your answer Problem 5.25. Prove that the binomial tree B defined in Section 5.8 contains 2 nodes, of which (i) are at depth k, 0 s k si Problem 5.26. Prove that a binomial heap con Tlg nl binomial trees, the largest of which contains 2 n items comprises at most items. Problem 5.27. Consider the algorithm for inserting a new item into a binomial heap H given in Section 5.8. A simpler method would be to create a binomial tree B0 as in step (i) of the algorithm, make it into a binomial heap, and merge this new heap with H. Why did we prefer the more complicated algorithm? Problem 5.28. Using the accounting trick described in Section 5.8, what is the amortized cost of deleting the largest item from a binomial heap? Problem 5.29. (Fibonacci trees) It is convenient to define the Fibonacci tree F-i to consist of a single node. Then the i-th Fibonacci tree Fit z0, is defined recursively to consist of a root node with i children, where the j-th child, 1 s j s i, is in turn the root of a Fibonacci tree Fj-2. Figure 5.23 shows Fo to Fs. Prove that the Fibonacci tree Fii 2 0, has fii nodes, where fi is the k-th member of the Fibonacci sequence; see Section 1.6.4Explanation / Answer
Heap sort doesn't always use the same number of comparisons for a given number of elements. The worst case is anlogn and the best case is bnlognbnlog?n, where a>b.
Assuming you're using a max heap represented as an array and inserting your max elements backwards into your output array/into the back of your array if you're doing it in-place, the worst case input for heapSort is any input that forces you to "bubble down" or reheapify every time you remove an element. This happens every time you are trying to sort a set with no duplicates. It will still be ?(n log n), as templatetypedef said.
This property implies that heapSort's best-case is when all elements are equal (?(n), since you don't have to reheapify after every removal, which takes log(n) time since the max height of the heap is log(n)). It's kind of a lousy/impractical case, though, which is why the real best case for heapsort is ?(n log n).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.