1 votes 1 votes Q Consider a complete Binary Tree ‘T’ with key of root node be ‘P’. It is given that the left and right subtree of ‘P’ satisfies min-heap property. What is the time taken to convert the given tree ‘T’ to a max heap ? 1.O(log n) 2.O(n) 3. O(n log n) 4.Ο(n2) Programming in C data-structures binary-tree + – kallu singh asked Aug 8, 2017 kallu singh 412 views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply Shubhanshu commented Aug 8, 2017 reply Follow Share It is O(logn) . 1 votes 1 votes kallu singh commented Aug 8, 2017 reply Follow Share But ans is given O(n) 2 votes 2 votes Please log in or register to add a comment.
3 votes 3 votes The answer should be O(n). Since there is no better way to convert a min heap to max heap (or vice-versa) than to reconstruct the heap in O(n). Given additional features like left and right subtrees being min heap won't help either. Rishabh Gupta 2 answered Aug 9, 2017 Rishabh Gupta 2 comment Share Follow See all 0 reply Please log in or register to add a comment.