Question
Write a program in Java to implement a d-heap data structure that supports the following operations: deleteMin (and percolate down) insert buildHeap The value of
Write a program in Java to implement a d-heap data structure that supports the following operations:
deleteMin (and percolate down)
insert
buildHeap
The value of 'd' is input by the user. A sample inputis given below.
Enter heap elements: 31 16 24 21 13
Enter d: 2
Output: Heap (d=2): 13 16 24 31 21
Press 1) for insert, 2) for deleteMin, 3) for new d value, 4) to quit
Enter choice: 1
Enter element to insert: 6
Output: Heap (d=2): 6 16 13 31 21 24
Press 1) for insert, 2) for deleteMin, 3) for new d value, 4) to quit
Enter choice: 1
Enter element to insert: 20
Output: Heap (d=2): 6 16 13 31 21 24 20
Press 1) for insert, 2) for deleteMin, 3) for new d value, 4) to quit
Enter choice: 2
Output: Heap (d=2): 13 16 20 31 21 24
Enter choice: 3
Enter d: 3
Output: Heap (d=3): 13 16 20 31 21 24
Press 1) for insert, 2) for deleteMin, 3) for new d value, 4) to quit
Enter choice: 3
Enter d: 4
Output: Heap with d=4: 13 16 20 31 21 24
Press 1) for insert, 2) for deleteMin, 3) for new d value, 4) to quit
Enter choice: 4
Program Terminated
Note: Program will be tested with a larger heap with more elements and different d values.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started