Software Engineering - cyclomatic complexity

In summary: You probably want to be consistent with how your book does it, if you have one, so you can follow examples. Otherwise, do what seems best to you.In summary, the conversation is about a student's attempt to solve a problem on cyclomatic complexity by creating a flow graph. The student receives feedback on their solution, with one mistake pointed out and a suggestion to move an arrow in the flow graph. The student also asks for clarification on the number of paths in the graph.
  • #1
ming2194
32
0

Homework Statement


[PLAIN]http://img17.imageshack.us/img17/651/cyclomaticcomplexity.png

Homework Equations


Main problem on part (i), am i correct on constructing the flow graph?
The If statement after process x makes me quite confused.

The Attempt at a Solution


[PLAIN]http://img141.imageshack.us/img141/5377/attempt2009ppc3page2.png
[PLAIN]http://img714.imageshack.us/img714/4234/attempt2009ppc3page3.png
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
The image of your solution is too large: 1654 x 2339 pixels. Please shrink it to about 600 x 800 and repost.
 
  • #3
ok now. Thanks
 
  • #4
Much better. Now I can see it without having to scroll up-down and left-right. You have a mistake on the if statement inside the while loop. Process q executes if either or both of the following is true:
1. condition d is true AND condition f is true
2. condition e is true

In your flow diagram you are saying that if d is true and f is false, q executes. That is incorrect.

There's another thing I would change -- I would move the arrow going from "a" to "end if" so that it goes to "end mymodule".
 
  • #5
[PLAIN]http://img822.imageshack.us/img822/1746/image001zqp.jpg
Is this time correct?

(ii) Cyclomatic Complexity = 7, since there are 7 regions in the whole flow graph.

(iii) 8 paths?
1. n-end if-end mymodule
2. n-m-end if-end mymodule
3. n-m-t-a-end if-end mymodule
4. n-m-t-a-x-d-e-q-k-a-end if-end mymodule
5. n-m-t-a-x-d-e-q-k-a-end if-end mymodule
6. n-m-t-a-x-d-f-q-k-a-end if-end mymodule
7. n-m-t-a-x-d-f-e-q-k-a-end if-end mymodule
8. n-m-t-a-x-d-f-e-k-a-end if-end mymodule

**Why I found there are 8 paths?! Not support to be 7 paths only?!

Hope you can help me to check patiently since I m going to face this type of question in the coming up exam and I don't want to lose any marks...

And for your last statement, what you suggest to me?
 
Last edited by a moderator:
  • #6
I don't see anything wrong in your flow diagram now. As far as how many paths, and whether there should be 7 or 8, I don't know. The best thing to do is count them, I think. If your book has any examples, take a look at them and see whether you are doing the same thing.

Regarding my comment about moving the arrow from a to end-if so that it points to end-mymodule, I don't think it matters much either way.
 

Related to Software Engineering - cyclomatic complexity

1. What is cyclomatic complexity?

Cyclomatic complexity is a software metric that measures the complexity of a program by counting the number of linearly independent paths through its source code. It is a quantitative measure of the number of possible paths through a program's control flow.

2. Why is cyclomatic complexity important in software engineering?

Cyclomatic complexity is important in software engineering as it helps developers identify and mitigate potential risks and issues in the code. It also helps in understanding the overall complexity of the program, which can aid in making decisions about refactoring and code optimization.

3. How is cyclomatic complexity calculated?

Cyclomatic complexity is calculated by counting the number of decision points (e.g. if statements, loops, switches) in a program and adding 1 to the result. This results in a single numerical value that represents the complexity of the program.

4. What is an acceptable range for cyclomatic complexity?

The acceptable range for cyclomatic complexity can vary depending on the specific programming language and context of the program. However, in general, a lower cyclomatic complexity (e.g. 1-10) is considered desirable as it indicates a simpler and easier to understand code. A higher cyclomatic complexity (e.g. 11-20) may indicate the need for refactoring and optimization, while a very high cyclomatic complexity (e.g. > 20) may be a sign of poorly written and overly complex code.

5. How can cyclomatic complexity be reduced?

Cyclomatic complexity can be reduced through various techniques such as refactoring, using control structures (e.g. loops, functions) effectively, and following best coding practices. Writing modular and well-structured code can also help in reducing cyclomatic complexity.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
15
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
5K
  • Engineering and Comp Sci Homework Help
2
Replies
53
Views
7K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
26
Views
8K
Back
Top