0% found this document useful (0 votes)
72 views2 pages

Ex3 Software Engineering Virtual Lab - IIT Kharagpur

Software engineering iit Kharagpur labs solution

Uploaded by

Tasneem khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views2 pages

Ex3 Software Engineering Virtual Lab - IIT Kharagpur

Software engineering iit Kharagpur labs solution

Uploaded by

Tasneem khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Home Credits Feedback Advanced Network Technologies Virtual Lab Virtual Labs

Estimation of Test Coverage Metrics and Structural


Complexity

Introduction Theory Simulation Case Study Self-evaluation Procedure Exercises References

Select 3

Cyclomatic complexity of binary search

The following C program implements the binary search technique performed over an array of integers. This is an example of a non-
trivial program that we often encounter in our lives.

01 #include <stdio.h>
02
03 int
04 main(int argc, char **argv)
05 {
06 int a[] = {2, 4, 6, 8, 10, 12, 14, 16};
07 int key = atoi(argv[1]);
08 int n = 8;
09 int low = 0;
10 int high = n - 1;
11 int middle;
12 int flag = 0;
13
14 while (low <= high) {
15 middle = (low + high) / 2;
16 if (key == a[middle]) {
17 printf("Found key %d at position %d\n", key, middle);
18 flag = 1;
19 }
20 else if (key < a[middle]) {
21 high = middle - 1;
22 }
23 else {
24 low = middle + 1;
25 }
26 if (flag)
27 break;
28 }
29
30 if (! flag)
31 printf("Key %d was not found!\n", key);
32
33 return 0;
34 }

Determine the cyclomatic complexity of this program. How would you classify this program in terms of its complexity (simple,
complex, unstable)?

Limitations: The current workspace can generate CFGs only for the main function. In other words, this would not work with user-
defined functions. However, in real life a program would contain several modules. All such modules have to be taken into account
while determining the complexity.

Submit

Write the C program below


10 pt

1 #include <stdio.h>
2
3 int
4 main(int argc, char **argv)
5
6 {
7
8 int a[] = {2, 4, 6, 8, 10, 12, 14, 16};
9
10 int key = atoi(argv[1]);
Position: Ln 63, Ch 1 Total: Ln 63, Ch 635 resize

Compile program (gcc -c -fdump-tree-vcg -fdump-tree-cfg test.c)

Compilation error (if any)

Program representation in terms of Basic Blocks

Control Flow Graph of the program

Result
View Solution

Sponsored by MHRD (NME-ICT) | Licensing Terms | Disclaimer Except otherwise noted, content on
this site is licensed under the CC-BY-
Copyright © 2010-2016 IIT Kharagpur NC-SA-3.0 License. See details.

You might also like