Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use only C programming language for the following questions, only need to answer

ID: 3810019 • Letter: U

Question

Use only C programming language for the following questions, only need to answer question 1 and 3

1. Write in pseudo-code the siftdown algorithm for a min-heap.

2. A ternary max-heap is similar to the binary max-heap that we have discussed in class, but now non-leaf nodes can have 3 children instead of 2.

(i) A ternary max-heap can be represented using an array. What are the indices of the parent and children of a node at index i ? (ii) Write in pseudocode the siftdown algorithm for a ternary max-heap.

3. Show that the alogorihm in Question 2(ii) has worst-case complexity O(log n), where n is the length of the array.

Explanation / Answer

Heapify (A, i)