Author | Message |
---|---|
mnava18
Posts: 86
|
Posted 04:31 Dec 07, 2014 |
anyone rememeber what question 1 and 2 were? totally forgot how how that worked Last edited by mnava18 at
04:33 Dec 07, 2014.
|
vsluong4
Posts: 87
|
Posted 23:19 Dec 07, 2014 |
It would probably help the most if you rewatch the video about these topics. 1) After inserting 15, the two heaps differ by 2 and they must be balanced for the algorithm to work. So the one with more elements has 1 taken off and given to the one with less. 2) The root, or first element, of a MAX heap is the max element. Looking up the first element is the same whether you have 1 element or 1000000000. This is different from extracting the max element because extra work must be done(O(logn)) in order to maintain the heap structure. Balanced BST support fast look-up because there are log(n) levels and the max element is in the rightmost(or leftmost if you reverse a tree) node. Then you just jump from one node to its right one until you get to the end. Each time you go to another node, you're going down a level and there are only log(n) levels to explore because the tree is balanced. |