Optimization and Data Flow questions

Q58

GATE CS 2015 CS-3Optimization and Data FlowMCQ2 marks−2/3 if wrong
Consider three software items: Program-X, Control Flow Diagram of Program-Y and Control Flow Diagram of Program-Z as shown below

Program-X:
sumcal(int maxint, int value)
{
    int result=0, i=0;
    if (value < 0)
    {
        value = -value;
    }
    while((i<value) AND (result <= maxint))
    {
        i=i+1;
        result = result + 1;
    }
    if (result <= maxint)
    {
        printf(result);
    }
    else
    {
        printf("large");
    }
    printf("end of program");
}
Control Flow Diagram of Program-Y: shown in the figure.

Control Flow Diagram of Program-Z: the Control Flow Diagram of Program-X followed by (with an arrow into) the Control Flow Diagram of Program-Y.

The values of McCabe's Cyclomatic complexity of Program-X, Program-Y, and Program-Z respectively are
Question figure
Show answer without attempting

Answer: A

Q38

GATE CS 2015 CS-1Optimization and Data FlowNAT2 marks
Consider the following C program segment.
while (first <= last)
{
    if (array[middle] < search)
        first = middle + 1;
    else if (array[middle] == search)
        found = TRUE;
    else last = middle - 1;
    middle = (first + last)/2;
}
if (first > last) notPresent = TRUE;
The cyclomatic complexity of the program segment is ________.
Show answer without attempting

Answer: 5

Q46

GATE CS 2015 CS-1Optimization and Data FlowMCQ2 marks−2/3 if wrong
A variable xx is said to be live at a statement SiS_i in a program if the following three conditions hold simultaneously:

i. There exists a statement SjS_j that uses xx
ii. There is a path from SiS_i to SjS_j in the flow graph corresponding to the program
iii. The path has no intervening assignment to xx including at SiS_i and SjS_j

(Control flow graph: block 1: p=q+rp = q + r, s=p+qs = p + q, u=s∗vu = s * v; block 2: v=r+uv = r + u; block 3: q=s∗uq = s * u; block 4: q=v+rq = v + r; edges 1→2, 1→3, 2→4, 3→4, 4→1.)

The variables which are live both at the statement in basic block 2 and at the statement in basic block 3 of the above control flow graph are
Question figure
Show answer without attempting

Answer: C

0/30 correct0 marks

Related topics in Compiler Design