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

help plz for maximumrating a) We can use a heap to implement a priority queue. T

ID: 3611931 • Letter: H

Question

help plz for maximumrating

a)     We can use a heap to implement a priority queue.

The Serve( ) function returnsthe highest priority item that will be the maximum heap element.The Enqueue () function inserts an input value into heap.“Enqueue ( )” function first add a new node to thetree. Then it traverses a path from this lead toward the root tofind a proper place for this new element.

Write pseudo code for Serve( ) and Enqueue ( ) function.

b)     Suppose H is a min heap containing n keys (elements). We want towrite a function printSmaller() that printsall the keys in H that are smaller than a given input key x.

Explanation / Answer

ENQUEUE () function:

1) Insert an element (e) at the end of an array.

2) Find out the parent of this node [ R=ceil(i/2) ]

3) Find out its two children 2*R and 2*R+1

4) If 2*R== e then S=2*R+1 else S=2*R

5) If (e>S)

      {

         if (e>R)

            Swap e & R;

               Goto step 2

       }

     STOP otherwise

SERVE function:

Heapify the array

Return first element of the array (Heap)

b)