Question: In class we studied binary heaps, i.e., heaps that store the elements in complete binary trees. This question is about ternary heaps, i.e., heaps that

In class we studied binary heaps, i.e., heaps that store the elements in complete binary trees. This question is about ternary heaps, i.e., heaps that store the elements in complete ternary trees (where each node has at most three children, every level is full except for the bottom level, and all the nodes at the bottom level are as far to the left as possible). Here we focus on MAX heaps, where the priority of each node in the ternary tree is greater or equal to the priority of its children (if any) a. Explain how to implement a ternary heap as an array A with an associated Heapsize variable (assume that the first index of the array A is 1). Specifically, explain how to map each element of the tree into the array, and how to go from a node to its parent and to each of its children (if any) b. Suppose that the heap contains n elements. (1) What elements of array A represent internal nodes of the tree? Justify your answer. (2) What is the height of the tree? Justify your answer Consider the following operations on a ternary heap represented as an arrayA c. INSERT(A, key): Insert key into A . EXTRACT_MAX(A): Remove a key with highest priority from A .UPDATE A, i, key), where 1 s i s A.Heapsize: Change the priority of Al1] to key and restore the heap ordering property. REMoVE(A, i), where 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
