Program Complexity - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Program Complexity

Description:

The number of 'mental objects' that are required to be kept in mind simultaneously. More objects require more concentration ... 1. Start with 1 for the ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 8
Provided by: mikemcc
Category:

less

Transcript and Presenter's Notes

Title: Program Complexity


1
Program Complexity
  • Lecture 11
  • 10/18/2000

2
Introduction to Complexity
  • Complexity
  • The number of mental objects that are required
    to be kept in mind simultaneously
  • More objects require more concentration
  • Control flow is the largest contributor to
    complexity (McCabe 1976)
  • Control flow complexity leads to
  • Low reliability
  • Frequent errors

3
How to Measure Complexity
  • McCabes complexity
  • Metric calculated by counting the number of
    decision points in a routine
  • Determining Number of Decision Points
  • 1. Start with 1 for the straight path through
    the routine
  • 2. Add 1 for each of the following keywords, or
    their equivalents if, while, repeat, for, and,
    or
  • 3. Add 1 for each case in a case statement.

4
Code Fragment - Bubble Sort
Public static void bubbleSort2 (Sequence S)
Position prec, succ int n S.size() for
(int i 0 i lt n i) // i-th pass prec
S.first() for (int j1 j lt n - i j)
succ S.after(prec) if (valAtPos(prec)
gt valAtPos(succ)) S.swapElements(prec,
succ) prec succ
5
Complexity Heuristics
  • Score
  • 0 - 5 Routine is OK
  • 6 - 10 Should consider if there are ways to
    simplify routine
  • 10 Routine should be further decomposed
  • Ways to Reduce Complexity
  • Divide software into subsystems
  • More independent subsystems, lower complexity
  • Defined modules allows single focus
  • Keep routines short
  • Limit nesting of loops and control structures

6
Program Flow Graphs
  • Way of visualizing complexity
  • Number or paths through program

1
Simple Example
Statement 1 Statement 2 if X lt 10 then
Statement 3 Statement 4
2
T
3
if
F
4
7
Bubble Sort Example
declarations
int size
for
T (i lt n)
prec
F (j gt n)
F (i gt n)
for
T (j lt n)
T
succ
if precgtsucc
S.swap
precsucc
F
End Routine
Write a Comment
User Comments (0)
About PowerShow.com