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

1. a) In a priority queue (not necessarily a min-heap) with n > 0 nodes, how man

ID: 3741160 • Letter: 1

Question

1. a) In a priority queue (not necessarily a min-heap) with n > 0 nodes, how many are leaves? Write one mathematical formula (not a C0 expression) that expresses the number of leaves regardless of whether n is even or odd. You may use ?x? to round x down and ?x? to round x up.

b) Suppose a sequence of n elements are inserted into a priority queue so that the priority of each element inserted is strictly decreasing. Afterward, the elements are removed one at a time based on priority. What common data structure does this priority queue implement?

c) If the priorities are strictly increasing instead, what common data structure does this priority queue implement?

d) Consider a non-empty priority queue of n elements, each with a di erent priority. This priority queue is represented using the array implementation of min-heaps. Give the exact range (inclusive), in terms of n, of array indexes where any element of lowest priority might occur. You may use mathematical notation or C0 notation.

Explanation / Answer

a) Number of leaves in a heap = ceil(n/2)
b) Queue
c) Stack
d) First element will be the lowest priority element always in case of min-heap implementation.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote