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

a) Please use the following insertProcedure method to answer the question. Defin

ID: 3912329 • Letter: A

Question

a) Please use the following insertProcedure method to answer the question.

Define the control flow graph. You need to define the set of edges (E) that defines your graph, the initial node (N0) and the final node (Nf). To simplify grading, use the line numbers for node numbers. For example, the node that represents the “while” statement should be node 10. (You will not need all the numbers.)

Example on how to define the following simple graph using the E, N0 and Nf:

N={ 1,2,3,4 }

N0={ 1 }

Nf={ 4 }

E={ (1,2) , (1,3) , (2,4) , (3,4) }

insertProcedure (int a[], int p [], int N)

int i, j, k;

    for (i=0; i<=N; i++)

       p[i] = i;

    for (i=2; i<=N; i++)

    {

       k = p[i];

       j = 1;

       while (a[p[j-1]] > a[k])

       {

          p[j] = p[j-1];

          j--;

       } // end while

       p[j] = k;

    } // end for

} // end insertProcedure

b) Use the insertProcedure method and your control flow graph to answer the following. Give one path that is not a test path.

c) Use the insertProcedure method and your control flow graph to answer the following question: List the edge-pair coverage test requirements for the graph.

3 4 2

Explanation / Answer

insertProcedure (int a[], int p [], int N)

{

int i, j, k;

    for (i=0; i<=N; i++)

       p[i] = i;

    for (i=2; i<=N; i++)

    {

       k = p[i];

       j = 1;

       while (a[p[j-1]] > a[k])

       {

          p[j] = p[j-1];

          j--;

       } // end while

       p[j] = k;

    } // end for

} // end insertProcedure

Ans b) considering this code and the while condition starting from line number 10, the path 10->11->12->13->14->10->... is not a test path because initially j=1 but inside the loop in in the first iteration it gets reduced to j=0 (since j--) and in the second iteration inside the while condition , it checks for a[p[-1]]>a[k]. This is the main problem because p[-1] is not valid (segmentation fault due to invalid index acces). Hence it generates an error.

Ans c) The test requirement should be : if we want the control flow to execute properly we should put a "break" statement inside the while loop as soon as j becomes less than 0.

i.e if(j<0)

{

break;

}