Docsity

Homework Assignment: Analyzing Program Complexity, Assignments of Software Engineering

Toggle sidebar
bg1
Homework #2
Homework #2 is due for all groups on Monday April 14, 2004. Each group is required to
hand in a typewritten report (see “More information about homework”) and must be
prepared to present and discuss your report in class. (Note: each homework-related
presentation is worth about 20% of a homework grade).
For the following program you are to:
1. Draw its control graph.
2. Compute its complexity V(G).
3. Compute its actual complexity, AC.
4. Reduce the complexity to its minimum if possible.
a. Redraw the graph
b. Compute the new complexity V(G’)
c. Show the new program.
// “c,” “g,” “x,” and “y” are global variables
void bill(int a, int b, int r1, int r2, int r3)
{
if (a == 1)
c = r1;
else if (a == 2)
c = r2;
else
c = r3;
if (b == 1)
{
printf(“Hello”);
x = 3;
}
else if (b == 2)
{
printf(“Hi”);
y = 82;
}
else
printf(“Bye”);
if (c == r1)
g = 65;
else if (c ==2)
g = 42;
else
g = 103;
}
pf2

Partial preview of the text

Download Homework Assignment: Analyzing Program Complexity and more Assignments Software Engineering in PDF only on Docsity!

Homework # 2

Homework # 2 is due for all groups on Monday April 14 , 200 4. Each group is required to hand in a typewritten report (see “More information about homework”) and must be prepared to present and discuss your report in class. (Note: each homework-related presentation is worth about 20% of a homework grade).

For the following program you are to:

  1. Draw its control graph.
  2. Compute its complexity V(G).
  3. Compute its actual complexity, AC.
  4. Reduce the complexity to its minimum if possible. a. Redraw the graph b. Compute the new complexity V(G’) c. Show the new program.

// “c,” “g,” “x,” and “y” are global variables void bill(int a, int b, int r1, int r2, int r3) { if (a == 1) c = r1; else if (a == 2) c = r2; else c = r3;

if (b == 1) { printf(“Hello”); x = 3; } else if (b == 2) { printf(“Hi”); y = 82; } else printf(“Bye”);

if (c == r1) g = 65; else if (c ==2) g = 42; else g = 103; }

For the following function compute its essential complexity and prove that it is not structures by using result 7 from the McCabe paper.

int search(int item, int table[100]) { x = 0; quit = FALSE; while (!quit) { if (table[x++] == item) return (x-1);

if (x > 100) quit = TRUE; } return –1; }

In page 319 of the McCabe paper in the lower right corner is a binary search program. In the following page is its control graph. Does this control graph represent the binary search function? Explain.

In the McCabe paper result 1 give 4 conditions that if any exists then the program is not structured. Later in result 5 and 6 they give 2 conditions each. Can we change the result 1 from “A structured program can be written by no branching into or out of a loop of into or out of a decision.”

To

“A structured program can be written by no branching into or out of a decision.”

Based on the fact that a loop is in fact a decision. Except for infinite loops, a loop must have a stopping condition. Comment and justify your answer.