Answered You can hire a professional tutor to get the answer.

QUESTION

Find a formula for the total number of swap operations performed by the iteration of INSERT(x, A) with the values of priorities of inserted processes...

Find a formula for the total number of swap operations performed by the iteration of INSERT(x, A) with the values of priorities of inserted processes equal to n, n-1, n-2, ..., 1. Assume that the priority queue A is initially empty. Leave your answer in the form of a sum.

procedure INSERT(x: processtype; var A: PRIORITYQUEUE);

               var

                               i: integer;

                              temp: processtype;

               begin

                               A.last := A.last + 1;

                               A.contents[A.last] := x;

                               i := A.last;

                               while (i > 1) and (p(A.contents[i]) < p(A.contents[i div 2])) do begin

                                               temp := A.contents[i];

                                               A.contents[i] := A.contents[i div 2];

                                               A.contents[i div 2] := temp;

                                               i := i div 2;

                               end

               end;

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question