Unit 3 Part-1
Unit 3 Part-1
E.RUPA
Assistant Professor
1
CSE Department
Path Products & expressions - Purpose
PURPOSE: APPLICATIONS
1. How many paths in a flow-graph?
4
Path Products & expressions - Definitions
Path Expression:
Regular Expression:
5
Path Products & expressions – Path Product
c
1 2 3 4
a b d
abd abcbd a b c b c b d ….
6
Path Products & expressions – Path Expression
Path Expression
Simply: Derive using path products.
c
1 2 3 4
a b d
Example:
{ a b d , a b c b d, a b c b c b d , ….. }
h i
e f j
a b c d
8
Path Products & expressions – Path Expression
9
Path Products & expressions – Path Segments &
Products
• Loops:
• Identity element
a0 = 1 X0 = 1 (path of length 0)
10
Path Products & expressions – Path Product
Path Product
• Not Commutative:
XY ≠ YX in general
• Associative
A ( BC ) = ( AB ) C = ABC : Rule 1
11
Path Products & expressions – Path Product
• Commutative
X + Y = Y + X : Rule 2
• Associative
• Distributive
A ( B + C) = A B + A C : Rule 4
(A+B)C = AC+BC
12
Path Products & expressions – Path Products
• Absorption
X + X = X : Rule
5
X + any subset of X = X
X = a + bc + abcd X + a = X + bc + abcd = X
13
Path Products & expressions – Path Products
• Loop:
b
An infinite set of parallel paths.
a c
b* = b0 + b1 + b2 + b3 + ……
X* = X0 + X1 + X2 + X3 + ……
X+ = X1 + X2 + X3 + ……
• X X* = X* X = X+ a a* = a* a = a+
n
X = X0 + X1 + X2 + X3 + …… + Xn
14
Path Products & expressions – Path products
More Rules…
m n
X + X = Xn if n ≥ m : Rule 6
= Xm if n < m
m n
X X = Xm+n : Rule 7
X X* = X*
n n
= X* X : Rule 8
X X+ = X+
n n
= X+ X : Rule 9 15
Path Products & expressions – Path products
Identity Elements ..
1 : Path of Zero Length
1+1 = 1 : Rule 11
1X = X1 = X : Rule
12
1* = 1 +
n n
1 = 1 = = 1 : Rule
13
16
+
Path Products & expressions – Path products
Identity Elements ..
X + 0 = 0+X = X : Rule 15
X0 = 0X = 0 : Rule 16
0* = 1 + 0 + 0 2 + 03 + . . . = 1 : Rule 17
17
Path Products & expressions – Reduction Procedure
18
Path Products & expressions – Reduction Procedure
Initialization Steps:
5
4
d e
f
g
1 a 2 3
b
20
Path Products & expressions – Reduction Procedure
Steps in the Algorithm’s loop:
8. IF there’s just one node between entry & exit nodes, path
expression for the flow graph is the link’s path expression.
ELSE, return to step 4.
21
Path Products & expressions – Reduction Procedure
• is not unique
22
Path Products & expressions – Reduction Procedure
Example
Cross-Term Step (Step 4 of the algorithm)
• Fundamental step.
• Removes nodes one by one till there’s one entry & one exit
node.
• Replace the node by path products of all in-links with all out-links
and interconnecting its immediate neighbors.
23
Path Products & expressions – Reduction Procedure
Example
Processing of Loop Terms:
a c a b*c
1 2 1 2
d b*d
24
Path Products & expressions – Reduction Procedure
Example
Processing of Loop Terms:
a b c f
1 2 3 4 5
d
e
bd
a bc f
1 2 4 5
a (bd)* bc f
1 2 4 5
e
25
Path Products & expressions – Reduction Procedure
Example
Processing of Loop Terms:
a (bd)* bc f
1 2 4 5
a (bd)* bc f
1 4 5
e (bd)* bc
a (bd)* bc ( e (bd)* bc ) * f
1 4 5
a (bd)* bc ( e (bd)* bc )* f
26
Path Products & expressions – Reduction Procedure
Example
Example:
a b c d e
1 3 4 5 6 2
f g h i
j k l
7 8 9 10
a b c d e
1 3 4 5 6 2
f g h il
j k
7 8 9
im
27
Path Products & expressions – Reduction Procedure
Example
a b c d e
1 3 4 5 6 2
f g ilh
j kh
7 8
im
a b c d e
1 3 4 5 6 2
g ilh
jf
kh
8
imf
a b c+gkh d e
1 3 4 5 6 2
gif ilh
imf 28
Path Products & expressions – Reduction Procedure
Example
bgif
a b(c+gkh) d e
1 3 5 6 2
ilh
imf
(bgif)*b(c+gkh)
a d e
1 3 5 6 2
ilh
imf
ilhd
a (bgif)*b(c+gkh)d e
1 3 6 2
imf
29
Path Products & expressions – Reduction Procedure
Example
a (bgif)*b(c+gkh)d (ilhd)*e
1 3 6 2
(ilhd)*imf
a(bgif)*b(c+gkh)d (ilhd)*e
1 6 2
(ilhd)*imf(bgif)*b(c+gkh)d
30
Path Products & expressions – Reduction Procedure
Example
31
Path Products & expressions – Before going into
Applications
Before that, we learn:
Identities
32
Path Products & expressions – Identities / Rules
(A+B)* = ( A* + B* ) * :
I1
= ( A* B* )* :
I2
= ( A* B )* A* :
I3
= ( B* A )* B* :
I4
= ( A* B + A )* :
I5
= ( B* A + B )* :
I6
(A+B+C+...)* = ( A* + B* + C* + . . . )* 33:
I7
Path Products & expressions – Structured Flow
Graphs
Reducible to a single link by successive application of the
transformations shown below.
A B A, B
Process
A B A B
IF THEN .. ELSE ..
A B
WHILE .. DO ..
34
Path Products & expressions – Structured Flow
Graphs
Structured flow graph transformations
A B A, B
REPEAT .. UNTIL ..
Properties:
•No cross-term transformation.
•No GOTOs.
•No entry into or exit from the middle of a loop.
35
Path Products & expressions – Structured Flow
Graphs
Some examples:
f
d
b
a b c d e
a c g i
e h
j
36
Path Products & expressions – UNstructured Flow
Graphs
Some examples – unstructured flow graphs/code:
X
Jumping into loops
X
Jumping out of loops
1. Write short notes on: path products, path expressions, path sums,
loops.
38