Consider the following routine (in Modula-2): procedure SiftDown(var A: array of integer; k, n: integer); var parent,
Question:
Consider the following routine (in Modula-2):
procedure SiftDown(var A: array of integer; k, n: integer);
var parent, child, insert, Ak: integer;
begin parent:= k; child:= k + k;
Ak:= A[k]; insert:= Ak;
loop if child > n then exit end;
if child < n then if A[child] > A[child+1] then child:= child+1 end end;
if insert <= A[child]
then exit else A[parent]:= A[child];
parent:= child; child:= child + child end end;
A[parent]:= Ak end SiftDown;
(This operation performs the sift-down operation for heaps; if needed, you may consult any text on data structures to learn more about heaps.) The routine is tested using the following input:
n = 5, k = 2, A[1] = 80, A[2] = 60, A[3] = 90, A[4] = 70, A[5] = 10.
Will the above test yield a 100% statement coverage? If not, provide one or more additional test cases this that a 100% statement coverage is obtained.
Step by Step Answer: