Computers and Technology

The problem is to implement a convert method to convert a given Max Heap into a Binary Search Tree (BST) with the condition that the output BST needs to be also a Complete Binary Tree.

Note that we assume:

- The number of elements in the Max Heap tree is always 2^L - 1 , which L is the number of levels in the tree.

- There is no duplicate element in the Max Heap.

- The Max Heap class has add and remove methods to construct and access the elements in the Heap.

- The MyBST class has insert method.

- The Solution class contains the header of the convert method. It needs a MaxHeap and a MyBST to convert the Max Heap to a Complete BST.

- The Driver class, will construct the MaxHeap and an empty BST and pass it to the convert method.

Example:

Input to convert method (a Max Heap):

7
/ \
6 5
/ \ / \
3 4 1 2

Convert Method Output (BST):

4
/ \
2 6
/ \ / \
1 3 5 7

class Solution{
public static void convert(MaxHeap maxHeap, MyBST bst){
// Write your code here, you can add more methods

}
}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 19:20, mahaleyrenee1195
How might the success of your campaign be affected if you haven’t carefully completed all field data or if you accidentally insert the wrong merge field in the document?
Answers: 2
image
Computers and Technology, 24.06.2019 12:30, stephanieanaya7
Why does the pc send out a broadcast arp prior
Answers: 1
image
Computers and Technology, 24.06.2019 20:00, impura12713
Avirus enters a computer or network as code embedded in other software directly from another computer
Answers: 1
image
Computers and Technology, 24.06.2019 21:30, croxy0514
Jenny wants to create an animated short video to add to her website. which software will she use to create this animated video?
Answers: 1
Do you know the correct answer?
The problem is to implement a convert method to convert a given Max Heap into a Binary Search Tree (...

Questions in other subjects:

Konu
Advanced Placement (AP), 06.01.2021 02:10
Konu
Mathematics, 06.01.2021 02:10
Konu
Mathematics, 06.01.2021 02:10