0% found this document useful (0 votes)
15 views25 pages

Unit 3 STM

Uploaded by

shalima
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)
15 views25 pages

Unit 3 STM

Uploaded by

shalima
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/ 25

UNIT – 3

UNIT - III
1. PATH PRODUCTS AND PATH EXPRESSION:
• Path expressions is an algebraic representation of sets of paths in a graph.
• Path Expressions are converted into Regular Expressions that can be used to examine
structural properties of flow graphs such as the number of paths, processing time or whether
data flow anomaly can occur
PATH PRODUCTS:
• Normally flow graphs used to denote only control flow connectivity.
• The simplest weight we can give to a link is a name.
• Using link names as weights, we then convert the graphical flow graph into an equivalent
algebraic like expressions which denotes the set of all possible paths from entry to exit for
the flow graph.
• Every link of a graph can be given a name.
• The link name will be denoted by lower case italic letters.
• In tracing a path or path segment through a flow graph, you traverse a succession of link
names.
• The name of the path or path segment that corresponds to those links is expressed
naturally by concatenating those link names.
• For example, if you traverse links a,b,c and d along some path, the name for that path
segment is abcd. This path name is also called a path product.

1
Examples of paths.
PATH EXPRESSION:
• Consider a pair of nodes in a graph and the set of paths between those node.
• Denote that set of paths by Upper case letter such as X,Y. From Figure c, the members of
the path set can be listed as follows: ac, abc, abbc, abbbc, abbbbc.............
• Alternatively, the same set of paths can be denoted
by :ac+abc+abbc+abbbc+abbbbc+...........
• The + sign is understood to mean "or" between the two nodes of interest, paths ac, or abc,
or abbc, and so on can be taken.
• Any expression that consists of path names and "OR"s and which denotes a set of paths
between two nodes is called a "Path Expression."
2
PATH PRODUCTS:
• The name of a path that consists of two successive path segments is conveniently
expressed by the concatenation or Path Product of the segment names.
• For example, if X and Y are defined as X=abcde,Y=fghij,then the path corresponding to
X followed by Y is denoted by
XY=abcdefghij
• Similarly,
• YX=fghijabcde
• aX=aabcde
• Xa=abcdea
• XaX=abcdeaabcde
• If X and Y represent sets of paths or path expressions, their product represents the set of
paths that can be obtained by following every element of X by any element of Y in all
possible ways.
• For example,
• X = abc + def + ghi
• Y = uvw + z
• Then,
• XY = abcuvw + defuvw + ghiuvw + abcz + defz + ghiz
• If a link or segment name is repeated, that fact is denoted by an exponent.
• The exponent's value denotes the number of repetitions:

• a1 = a; a 2 = aa; a3 = aaa; an = aaaa . . . n times. Similarly, if


• X = abcde then X1 = abcde
• X2 = abcdeabcde = (abcde) 2
• X3 = abcdeabcdeabcde = (abcde)2abcde = abcde(abcde)2 = (abcde) 3
• The path product is not commutative (that is XY!=YX).
• The path product is Associative.
RULE 1: A(BC)=(AB)C=ABC
• where A,B,C are path names, set of path names or path expressions.
PATH SUMS:
• PATH SUMS: The "+" sign was used to denote the fact that path names were part of the
same set of paths.
3
• The "PATH SUM" denotes paths in parallel between nodes.

4
• If X and Y are sets of paths that lie between the same pair of nodes, then X+Y denotes
the UNION of those set of paths. For example,

• The first set of parallel paths is denoted by X + Y + d and the second set by U +V + W + h
+ i + j. The set of all paths in this flowgraph
is f(X + Y + d)g(U + V + W + h + i + j)k
• The path is a set union operation, it is clearly Commutative and Associative.
DISTRIBUTIVE LAWS:
• The product and sum operations are distributive, and the ordinary rules of multiplication
apply; that is
` RULE 4: A(B+C)=AB+AC and (B+C)D=BD+CD
• Applying these rules to the below Figure (a) yields
e(a+b)(c+d)f=e(ac+ad+bc+bd)f= eacf+eadf+ebcf+ebdf
LOOPS:
• Loops can be understood as an infinite set of parallel paths. Say that the loop consists of a
single link b. then the set of all paths through that loop point is
b0+b1+b2+b3+b4+b5+..............

5
Example:

This potentially infinite sum is denoted by b* for an individual link and by X* when X is a path
expression.

• The path expression for the above figure is denoted by the notation:
ab*c=ac+abc+abbc+abbbc+................
• Evidently, aa*=a*a=a+ and XX*=X*X=X+
2. REDUCTION PROCEDURE ALGORITHM:
• This section presents a reduction procedure for converting a flow graph whose links are
labeled with names into a path expression that denotes the set of all entry/exit paths in that
flow graph. The procedure is a node-by-node removal algorithm.
The steps in Reduction Algorithm are as follows:
1. Combine all serial links by multiplying their path expressions.
2. Combine all parallel links by adding their path expressions.
3. Remove all self-loops (from any node to itself) by replacing them with a link of the
form X*, where X is the path expression of the link in that loop.
STEPS 4 - 8 ARE IN THE ALGORIHTM'S LOOP:

6
4. Select any node for removal other than the initial or final node. Replace it with a set of
equivalent links whose path expressions correspond to all the ways you can form a
product of the set of in links with the set of out links of that node.
5. Combine any remaining serial links by multiplying their path expressions.
6. Combine all parallel links by adding their path expressions.
7. Remove all self-loops as in step 3.
8. Does the graph consist of a single link between the entry node and the exit node? If yes,
then the path expression for that link is a path expression for the original flowgraph;
otherwise, return to step 4.

A flow graph can have many equivalent path expressions between a given pair of nodes;
that is, there are many different ways to generate the set of all paths between two nodes
without affecting the content of that set.

The appearance of the path expression depends, in general, on the order in which
nodes are removed.

From the above diagram, one can infer:


(a + b)(c + d + e) = ac + ad + + ae + bc + bd + be

LOOP REMOVAL OPERATIONS:

There are two ways of looking at the loop-removal operation:

7
A REDUCTION PROCEDURE – EXAMPLE:

Remove node 10 by applying step 4 and combine by step 5 to yield

7
Remove node 9 by applying step4 and 5 to yield,

Remove node 7 by steps 4 and 5, as follows,

Remove node 8 by steps 4 and 5, to obtain,

8
Parallel Term: combine them to create a path expression for an equivalent link whose
path expression is c+gkh; that is,

Loop Term: Removing node 4 leads to a loop term.

Continue the process by applying the loop-removal step as follows:

Removing node 5 produces:

9
Remove the loop at node 6 to yield:

Remove node 3 to yield:

• Removing the loop and then node 6 result in the following expression:
a(bgjf)*b(c+gkh)d((ilhd)*imf(bjgf)*b(c+gkh)d)*(ilhd)*e

3. REGULAR EXPRESSIONS AND FLOW ANOMALY DETECTION:

The generic flow-anomaly detection problem is that of looking for a specific sequence
of options considering all possible paths through a routine.
Let the operations be SET and RESET, denoted by s and r respectively, and we wantto
know if there is a SET followed immediately a SET or a RESET followed immediately
by a RESET (an ss or an rr sequence).
Some more application examples:
1. A file can be opened (o), closed (c), read (r), or written (w). If the file is read or written
to after it's been closed, the sequence is nonsensical. Therefore, cr and cw are anomalous.
Similarly, if the file is read before it's been written, just after opening, we

10
may have a bug. Therefore, or is also anomalous. Furthermore, oo and cc, though
not actual bugs, are a waste of time and therefore should also be examined.
2. A tape transport can do a rewind (d), fast-forward (f), read (r), write (w), stop (p), and
skip (k). There are rules concerning the use of the transport; for example, you cannot
go from rewind to fast-forward without an intervening stop or from rewind or fast-
forward to read or write without an intervening stop. The following sequences are
anomalous: df, dr, dw, fd, and fr. Does the flowgraph lead to anomalous sequences on
any path? If so, what sequences and under what circumstances?
3. The data-flow anomalies discussed requires us to detect the dd, dk, kk,and ku
sequences. Are there paths with anomalous data flows?

11
APPLICATIONS of Node removal:

The purpose of the node removal algorithm is to present one very generalized
concept- the path expression and way of getting it.
Every application follows this common pattern:
1. Convert the program or graph into a path expression.
2. Identify a property of interest and derive an appropriate set of "arithmetic"
rules that characterizes the property.
3. Replace the link names by the link weights for the property of interest. The
path expression has now been converted to an expression in some algebra
such as ordinary algebra, regular expressions, or Boolean algebra. This
algebraic expression summarizes the property of interest over the set of all
paths.
4. Simplify or evaluate the resulting "algebraic" expression to answer the
question you asked.

12
HOW MANY PATHS IN A FLOW GRAPH?

The question is not simple. Here are some ways you could ask it:
1. What is the maximum number of different paths possible?
2. What is the fewest number of paths possible?
3. How many different paths are there really?
4. What is the average number of paths?
Determining the actual number of different paths is an inherently difficult problem
because there could be unachievable paths resulting from correlated and dependent
predicates.
If we know both of these numbers (maximum and minimum number of possible paths)
we have a good idea of how complete our testing is.
Asking for "the average number of paths" is meaningless.

MAXIMUM PATH COUNT ARITHMETIC:

Label each link with a link weight that corresponds to the number of paths that link
represents.
Also mark each loop with the maximum number of times that loop can be taken. If the
answer is infinite, you might as well stop the analysis because it is clear that the
maximum number of paths will be infinite.
There are three cases of interest: parallel links, serial links, and loops.

13
Example:
The following is a reasonably well-structured program.

Each link represents a single link and consequently is given a weight of "1" to start.
Lets say the outer loop will be taken exactly four times and inner Loop Can be taken
zero or three times Its path expression, with a little work, is:
Path expression: a(b+c)d{e(fi)*fgj(m+l)k}*e(fi)*fgh
A: The flow graph should be annotated by replacing the link name with the maximum
of paths through that link (1) and also note the number of times for looping.
B: Combine the first pair of parallel loops outside the loop and also the pair in the
outer loop.
C: Multiply the things out and remove nodes to clear the clutter.
14
For the Inner Loop:
D: Calculate the total weight of inner loop, which can execute a min. of 0 times and
max. of 3 times. So, it inner loop can be evaluated as follows:

E: Multiply the link weights inside the loop


F: Evaluate the loop by multiplying the link weights
G: Simplifying the loop further results in the total maximum number of paths in the
flowgraph:

15
Alternatively, you could have substituted a "1" for each link in the path expression and
then simplified, as follows:
a(b+c) d{e(fi)*fgj(m+l) k}*e(fi)*fgh
= 2 x 84 x 4 = 32,768
This is the same result we got graphically.
Actually, the outer loop should be taken exactly four times. That doesn't mean it
will be taken zero or four times. Consequently, there is a superfluous "4" on the
out link in the last step.

16
Therefore, the maximum number of different paths is 8192 rather than 32,768.
STRUCTURED FLOWGRAPH:

Structured code can be defined in several different ways that do not involve ad-hoc
rules such as not using GOTOs.
A structured flowgraph is one that can be reduced to a single link by successive
application of the transformations of Below Figure.

Figure: Structured Flow Graph Transformations.


The node-by-node reduction procedure can also be used as a test for structured code.
Flow graphs that DO NOT contain one or more of the graphs shown below (Figure) as
subgraphs are structured.
1. Jumping into loops
2. Jumping out of loops
3. Branching into decisions
4. Branching out of decisions

17
18
LOWER PATH COUNT ARITHMETIC:

A lower bound on the number of paths in a routine can be approximated for structured
flow graphs.
The arithmetic is as follows:

The values of the weights are the number of members in a set of paths.
EXAMPLE:
Applying the arithmetic to the earlier example gives us the identical steps until step 3 (C)
as below:

19
From Step 4, the it would be different from the previous example:

20
If you observe the original graph, it takes at least two paths to cover and that it can be
done in two paths.
If you have fewer paths in your test plan than this minimum you probably haven't
covered. It's another check.

21

You might also like