Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this question, assume the definition of Java class Heap given in the Appendix. The heaps referred to in this question are all maxHeaps. a.
For this question, assume the definition of Java class Heap given in the Appendix. The heaps referred to in this question are all maxHeaps. a. (5 marks)Iusert into an empty (binary) heap the values 35, 4, 72, 36, 49, 50. Draw all interuediate steps. b. (3 marks) Carry out one deletion operation on the final heap in (a.) above c. (2 marks) Give the worst-case time complexity of insertion aud deletion operations for a heap with n elements, aud justify this complexity [in two sentences or so) d. (4 marks) Imagine a variatiou to the binary heap of lectures called terHeap, where instend of each noe haig two clildre, t has three children. The treis still rquired to be complete, and the heap property that the parent is at least as large as its children must be maintained. An example of a terHcap is as followe: 70 60 40 50 25 10 45 10 40 30 There is similarly an array representation: index 0 1 2 3 4 5 6 78 9 value TO 60 40 50 25 10 45 10 40 30 Call the children of each node leftChild, midChild, and rightChild. What are the equations that relate the index of a node to the indices of its children in this array repre- sentation? e. (7 marks) Using your answer to (d.) above or otherwise, modify the code for heapRebuild (in the Appendix) to handle terHeaps rather than regular binary heaps. You should write out the full code in the answer book. (You may leave out the coinments from the original code. f. (5 marks) Imagine a further generalisation of the heap, so that rather than the standard Heap where each node has two children, or the terHeap of (d.) where each node has three children, you have an naryHeap where each node has n children (subject to being a complete tree)
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