0% found this document useful (0 votes)
11 views22 pages

STM Unit - Iv

Unit IV discusses path products and path expressions as algebraic representations of paths in flow graphs, which are essential for analyzing program structures. It covers the reduction procedure algorithm for converting flow graphs into path expressions, the detection of flow anomalies using regular expressions, and various applications of these concepts. The document emphasizes the complexity of determining the number of paths in a flow graph and provides methods for calculating maximum path counts.

Uploaded by

divyameher2004
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)
11 views22 pages

STM Unit - Iv

Unit IV discusses path products and path expressions as algebraic representations of paths in flow graphs, which are essential for analyzing program structures. It covers the reduction procedure algorithm for converting flow graphs into path expressions, the detection of flow anomalies using regular expressions, and various applications of these concepts. The document emphasizes the complexity of determining the number of paths in a flow graph and provides methods for calculating maximum path counts.

Uploaded by

divyameher2004
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/ 22

UNIT – 4

Dept. of CSE Page 72


UNIT - IV
1. PATH PRODUCTS AND PATH EXPRESSION:
• Path expressions is an algebraic representations 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
MOTIVATION:
• Flow graphs are being an abstract representation of programs.
• Any question about a program can be cast into an equivalent question about an appropriate
flowgraph.
• Most software development, testing and debugging tools use flow graphs analysis
techniques.
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.

Dept. of CSE Page 73


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."
. Dept. of CSE Page 74
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; a2 = 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.
• The "PATH SUM" denotes paths in parallel between nodes.

. Dept. of CSE Page 75


• 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
ABSORPTION RULE:
• If X and Y denote the same set of paths, then the union of these sets is unchanged;
consequently,
RULE 5: X+X=X (Absorption Rule)
• For example, if X=a+aa+abc+abcd+def then X+a = X+aa = X+abc = X+abcd = X+def =
X
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+..............

Dept. of CSE Page 76


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:

Dept. of CSE Page 77


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 inlinks with the set of outlinks 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:

Dept. of CSE Page 78


A REDUCTION PROCEDURE – EXAMPLE:

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

Dept. of CSE Page 79


 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,

Dept. of CSE Page 80


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:

Dept. of CSE Page 81


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 PROBLEM:
 The generic flow-anomaly detection problem (note: not just data-flow anomalies, but

any flow anomaly) 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 want to
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 andcw are
anomalous. Similarly, if the file is read before it's been written, just after opening, we

Dept. of CSE Page 82


may have a bug. Therefore, or is also anomalous. Furthermore, ooand 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 in Unit 4 requires us to detect the dd, dk, kk,
and ku sequences. Are there paths with anomalous data flows?

THE METHOD:
 Annotate each link in the graph with the appropriate operator or the null operator 1.
 Simplify things to the extent possible, using the fact that a + a = a and 12 = 1.
 You now have a regular expression that denotes all the possible sequences of operators
in that graph. You can now examine that regular expression for the sequences of
interest.
 EXAMPLE: Let A, B, C, be nonempty sets of character sequences whose smallest
string is at least one character long. Let T be a two-character string of characters. Then if
T is a substring of (i.e., if T appears within) ABnC, then T will appear in AB2C.
(HUANG's Theorem)

 As an example, let

A = pp
B = srr
C = rp
T = ss
The theorem states that ss will appear in pp(srr)nrp if it appears in pp(srr)2rp.
However, let

A = p + pp + ps
B = psr + ps(r + ps)
C = rp
T = P4

Dept. of CSE Page 83


Is it obvious that there is a p4 sequence in ABnC? The theorem states that we have only
to look at

(p + pp + ps)[psr + ps(r + ps)]2rp

Multiplying out the expression and simplifying shows that there is no p4 sequence.
 Incidentally, the above observation is an informal proof of the wisdom of looping
twice discussed in Unit 2. Because data-flow anomalies are represented by
two-character sequences, it follows the above theorem that looping twice is what
you need to do to find such anomalies.

LIMITATIONS:

 Huang's theorem can be easily generalized to cover sequences of greater length than
two characters. Beyond three characters, though, things get complex and this method
has probably reached its utilitarian limit for manual application.
 There are some nice theorems for finding sequences that occur at the beginnings and
ends of strings but no nice algorithms for finding strings buried in an expression.
 Static flow analysis methods can't determine whether a path is or is not achievable.
Unless the flow analysis includes symbolic execution or similar techniques, the impact
of unachievable paths will not be included in the analysis.
 The flow-anomaly application, for example, doesn't tell us that there will be a flow
anomaly - it tells us that if the path is achievable, then there will be a flow anomaly.
Such analytical problems go away, of course, if you take the trouble to design routines
for which all paths are achievable.

4. APPLICATIONS:
 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,

Dept. of CSE Page 84


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.
HOW MANY PATHS IN A FLOWGRAPH ?

 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.

Dept. of CSE Page 85


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.

Dept. of CSE Page 86


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:
13 = 10 + 11 + 12 + 13 = 1 + 1 + 1 + 1 = 4
E: Multiply the link weights inside the loop: 1 X 4 = 4
F: Evaluate the loop by multiplying the link wieghts: 2 X 4 = 8.
G: Simpifying the loop further results in the total maximum number of paths in the
flowgraph: 2 X 84 X 2 = 32,768.

Dept. of CSE Page 87


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
= 1(1 + 1)1(1(1 x 1)31 x 1 x 1(1 + 1)1)41(1 x 1)31 x 1 x 1
= 2(131 x (2))413
= 2(4 x 2)4 x 4
= 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
outlink in the last step.

Dept. of CSE Page 88


 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

Dept. of CSE Page 89


Dept. of CSE Page 90
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 unitl step 3 (C) as
below:

Dept. of CSE Page 91


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

Dept. of CSE Page 92


 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.

Dept. of CSE Page 93

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy