88% found this document useful (8 votes)
8K views

Graph Matrices and Applications

Graph matrices represent graphs using matrices. A graph matrix is a square array with rows and columns corresponding to each node in the graph. The entries represent relationships between nodes, such as connection weights. Graph matrices allow applying matrix operations and theorems to analyze graph properties and relationships mathematically. They provide a more systematic approach than tracing graph paths. The document discusses graph matrix definitions, observations, operations, and properties of the relationships they represent.

Uploaded by

Sunit Prasad
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
88% found this document useful (8 votes)
8K views

Graph Matrices and Applications

Graph matrices represent graphs using matrices. A graph matrix is a square array with rows and columns corresponding to each node in the graph. The entries represent relationships between nodes, such as connection weights. Graph matrices allow applying matrix operations and theorems to analyze graph properties and relationships mathematically. They provide a more systematic approach than tracing graph paths. The document discusses graph matrix definitions, observations, operations, and properties of the relationships they represent.

Uploaded by

Sunit Prasad
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 47

Graph Matrices and Applications

Note: Please use a slide show since transitions have been


animated.
Tip: dark red text corresponds to dark red entries in the
table for that slide and so on . . .
Overview:

Graph matrices are just another representation


for graphs

• We will be covering -
 the need for matrices
Matrix operations, relations
 node reduction algorithm
 equivalence class partition
Why do we need matrices?…
• Path tracing can lead to errors
• Links can be missed or covered twice
(redundancy)
• Interruptions while tracing a path can cause
errors and lead to confusion
• There is a need for a more methodical and
mechanical approach
• Proving theorems by mathematical
representations(matrices) helps in proving
theorems about graphs
Operations that comprise the
toolkit…
• Matrix multiplication, which is used to get the
path expression from every node to every
other node
• A partitioning algorithm for converting graphs
with loops into loop free graphs of
equivalence classes
• A collapsing process (analogous to the
determinant of a matrix) which gets the path
expression from any node to any other node
The matrix of a graph
• A graph matrix is a square array with one row
and one column for every node of the graph
• Each row-column combination corresponds to
a relation b/w the node corresponding the row
and the node corresponding the column. This
could be the link name.

1 0
GRAPH MATRIX
Graph matrix observations:
• The size of the matrix (i.e. the number of rows and
columns) equals the number of nodes
GRAPH a 0 MATRIX
1
• If there are several links between two nodes, then, the
entry is a sum. The ‘+’ sign denotes parallel links, as usual.
a
GRAPH b MATRIX

a+b
1 2
Graph matrix observations (cont…)
• The entry at a row and column intersection is
the link weight of the link (if any) that
connects the two nodes in that direction
a
e a d
1 2
b b+e
d c
c

GRAPH 3 MATRIX
Graph matrix observations (cont…)
• A connection from node i to node j does not
imply(mean) a connection from node j to node i
as seen in the graph.

• There is a place to put every possible direct


connection or link between any node and any
other node.
a
GRAPH b a bMATRIX
1 2
Definitions:
• The simplest weight that we can denote is to
indicate if there is a connection or not. Say –
‘1’ means that there is a connection and ‘0’
means that there is no connection. The
arithmetic rules as we already know are-
1+1= 1 1+0= 1 0+0= 0
1*1= 1 1*0= 0 0*0= 0
A matrix with weights defined is called a
connection matrix.
Obtaining the connection matrix-
• Replace each entry with ‘1’ if there is a link and with ‘0’ if there
isn’t. To reduce clutter, ignore the ‘0’s.
• Each row of the matrix denotes the out-link of the node
corresponding to that row
• Each column denotes the in-link corresponding to that node
• A branch node has more than one non-zero entry in its row
• A junction node has more than one non-zero entry in its column
• A Self loop is an entry along the diagonal
• Graph’s cyclo-matic complexity (will be dealt further)
Deducing the relation matrix…
3
a b c h g
m d e f
1 5 6 7 8 2
l
i j k
4
a i Replace each entry
with the link
b h weight if there is a
link and leave it
j blank if there isn’t.
m
RELATION MATRIX
c l d
e
f k g
Deducing the connection matrix &
calculating the cyclomatic complexity…
3
a b c h g
m d e f
1 5 6 7 8 2
l
i j k
4 Now add the
Replace each 1 the
Add 1 entries in each 2-1=1 results from each
entry with ‘1’ if row & subtract the total row. You get 6.
by 1. Adding 1 to this
there is a link
2-1=1 gives you the cyclo
and leave it matic complexity
blank if there 1-1=0
(M).
isn’t. 1-1=0
CONNECTION MATRIX Cyclo-matic
3-1=2 complexity
1-1=0
6+1=7=M
3-1=2
Simplifying references-
• Instead of saying- ‘entry at row 6, column 7’, we say –
entry at node i and column j.
• So, the link weight between nodes i and j is
represented by aij
• Self loop at node i is represented by aii
• So, the link weight between nodes j and i is
represented by aji
w.r.t the graph,
3 b c abmd should read a13 a35 a56 a67
a m d where, a13 = a
1 5 6 7
a35 = b…
Examples-

• aij ajj ajm This expression denotes a path from node i


to j, with a self loop at j and then a link from node j
to m.
• ∑aik akk akj (where k = 1 to n) This expression denotes
the set of all possible paths between nodes i and j via
one(or many) intermediate node(s).
Definitions:
• The transpose of a matrix is the matrix with rows and columns
interchanged (denoted by superscript T) . If C = AT , then cij = aji
• The intersection of two matrices of the same size, (denoted by A
# B) is obtained by an element-by-element multiplication of the
entries. C = A # B  cij = aji (usually Boolean AND/ set
intersection)
• The union of two matrices is defined as the element-by-element
addition (usually Boolean OR/ set union).
Relations:
• A relation is a property that exists between two objects of interest.
a and b are objects and R is used to denote that a has a relation to
b.
Examples:
aR b  a is connected to b. R = ‘is connected to’
a>= b or aR b  R is ‘is greater that or equal to’
A is a subset of b  R is ‘is a subset of’
Redefining what we already know:
• A graph consists of a set of abstract objects called nodes and
a relation R between the nodes. If aRb, it is denoted by a link
(a to b).
• Some relations can be associated with properties. These are
called link weights.
• ‘is connected to’ is the simplest relation denoted by a link
with no weight. A graph with this relation are called a
connection /adjacency matrix.
• General relations form the relation matrix.
Properties of relations (overview):
• Transitive relations
aRbbRcaRc
• Reflexive relations
for every a, a R a (eg. self loop)
• Symmetric relations (undirected graph)
for every a & b, a R b  b R a (aij = aji for all i, j)
• Anti-symmetric relations
for every a & b, a R b  b R a, then a = b
• Equivalence relations
satisfies transitive, reflexive & symmetric
• Partial ordering relations
satisfies transitive, reflexive & anti-symmetric
Properties of relations:
• Transitive relations
aRbbRcaRc
Most relations used in testing are transitive.
Examples for transitive relations: is connected
to, is greater than or equal to, is less than or
equal to, is a relative of, is faster than, is
slower than, takes more time than, is a subset
of, includes, shadows, is the boss of.
Examples for intransitive relations: is acquainted
with, is a friend of, is a neighbor of, is lied to,
has a du chain between.
Properties of relations (cont…):
• Reflexive relations
for every a, a R a (eg. self loop)
A reflexive relation is equivalent to a self loop
at every node.
Examples for reflexive relations: equals, is
acquainted with, is a relative of.
Examples for ir-reflexive relations: not equals, is
a friend of(unfortunately), is on top of, is
under.
Properties of relations (cont…):
• Symmetric relations (undirected graph)
for every a & b, a R b  b R a (aij = aji for all i, j)
This implies that if there is a link from a to b, there is
also a link from b to a. Which means that instead of
two way links between nodes we can justSince
have a to
we need
single undirected link . A graph whose relations use arrows to
are not symmetric is called a directed graph. denote direction
Examples for symmetric relations: is a relative of,
equals, is alongside of, shares a room with, is
married, brother of, OR, AND, XOR.
Examples for asymmetric relations: is the boss of,
is the husband of, is greater than, controls,
dominates, can be reached from.
Properties of relations (cont…):
• Anti-symmetric relations
for every a & b, a R b  b R a, then a = b
This implies that both a & b are the same
elements.
Examples for anti-symmetric relations: is greater than or
equal to, is a subset of, time.
Examples for non-antisymmetric relations: is connected to,
can be reached from, is greater than, is a relative of, is a
friend of.
Properties of relations (cont…):
• Equivalence relations
satisfies transitive, reflexive & symmetric
Example for equivalence relations: numerical equality.
• If a set of objects satisfy an equivalence relation, they
form an equivalence class over that relation.
• Importance of equivalence classes & relations:
any member of the equivalence class, is with respect to
the relation , equivalent to any other member of the
class. [Please refer the text for short notes]
Properties of relations (cont…):
• Partial ordering relations
satisfies transitive, reflexive & anti-symmetric
Properties: loop free, there is at least 1 maximum element & one minimum element,
if you reverse all the rows, the resulting graph is also partially ordered.
Example for partial ordering relations: trees, most data structures, integration plan.
• A maximum element a, is one for which the relation xRa does not hold for any
other element x.
• A minimum element a, is one for which the relation aRx does not hold for any
other element x.
[Please refer the text for short notes]
Partitioning algorithm:
1
1 1
1 1 1
2 7 1 1
8 1 1 1
1 1
3
1
5
1 1 1
4 1 1

RELATION MATRIX
6
… Considering that the graph may have loops.
Diagonal entries are made to represent self loop.
Partitioning algorithm(cont…):
1
1 1 1 1 1 1 1
1 1 1 1 1 1
2 7 1 1 1 1
8 1 1 1 1
1 1 1 1
3
1
5
1 1 1 1 1 1
4 1 1 1 1 1

TRANSITIVE CLOSURE MATRIX


… Explanation for getting the transitive closure matrix
6 & its transpose is not included since we assumed that
you would know this. Please get back if you need any
info. 
Partitioning algorithm(cont…):
1
1 1 1
1 1 1
1 1 1
2 7
1 1 1
8 1
1 1
3 1
5 INTERSECTION WITH ITS TRANSPOSE
4 Considering the entries is the above matrix, we
have the following…
Example: to get values A=[1]
for B – It is evident that B = [ 2, 7 ]
6 B(row 2) has entries at C = [ 3, 4, 5 ]
column 2 & 7. Hence the D=[6]
values. E=[8]
Partitioning algorithm(cont…):
1
A
The resulting graph is ---
2,7
A B C D E B
A 1 8
1
E
3,4,
B 1 1 From the
5C
earlier slide,
1 1 we had --
C
A=[1] 6
1 B = [ 2, 7 ]
D C = [ 3, 4, 5 ]
D
D=[6]
1 1
E E=[8]
… Considering that the graph had self loops.
Diagonal entries are made to represent self loop.
Node Reduction Algorithm – some matrix
properties: interchanging rows 3 & 4 …
1 2 3 4 5 1 2 * * 5
1 a 1 a
2 2

3 d b * c f

4 c f * d b
g e h g e h
5 5

To interchange node names in 1 2 4 3 5


1 a
a matrix, we must interchange
both the corresponding rows 2
and the corresponding
columns… 4 c f

3 d b
interchanging columns 3 & 4 … g e h
5
*Node
• Advantages:
Reduction Algorithm*
– The matrix reduction method is more methodical than the graphical method
– Does not entail(involve) continually redrawing of the graph
• Steps to be followed:
– Select a node for removal, replace the node by equivalent links that bypass that node.
– Add the parallel terms & simplify if you can
– Adjust out-links that have a self loop
– The result is a matrix whose size is reduced by 1.
– Continue until only two nodes are left. There should be only one link between these
nodes.
*Node Reduction Algorithm*
d
1 a 3 b 4 c 2

e f g
1 2 3 4 5
5 1 a
h 2
STEP 1: Eliminate a node 3 d b
and replace it with a set of
c f
equivalent links… 4
g e h
5
Say, we start with eliminating
node 5-

TIP: The out-link of the node removed will correspond to


the row and the in-link will correspond to the column
*Node Reduction Algorithm*
Eliminating node 5 … the self loop is represented with a *
and the outgoing link from the node is multiplied . . .
d
1 a 3 b 4 c 2

e f g
5
1 2 3 4 5
1 a
h
2

3 d b
Say, we start with eliminating 4 c f
node 5. First, we remove the
g
h*g e
h*e h
self loop- 5

TIP: The out-link of the node removed will correspond to


the row and the in-link will correspond to the column
*Node Reduction Algorithm*
Eliminating node 5 … the self loop is represented with a *
and the outgoing link from the node is multiplied . . .
d

1 a 3b c4 2
+
fh*e (fh*g)
1 2 3 4 5
a
1

Now, we eliminate node 5- 2

3 d b
C+fh
4 c fh*e f
TIP: The out-link of the node *g
removed will correspond to the 5 g e h
h*g h*e
row and the in-link will correspond
to the column
*Node Reduction Algorithm*
Eliminating node 4 … the parallel link is added up and serial
links multiplied . . .
d d+
1 a 3b 4 2
fh*e c + (fh*g)
bfh*e bc + b(fh*g) 1 2 3 4 5

1 a

2
d
d+bc+ b
Now, we eliminate node 4-
3 bfh*g
bfh*g

c
C+fh f
4 *g
fh*e

g e h
5 h*g h*e
*Node Reduction Algorithm*
Eliminating node 4 … the parallel link is added up and serial
links multiplied . . .
a X d+ bc + b(fh*g) bfh*e
1 3 23

Now, we should ideally 1 2 3 4 5


eliminate node 3-
Since row 2 and column 2
1 a

are empty, these are


dropped. Values of nodes 1 2
and 3 are retained.
d
d+bc+ b
If row n and its 3 bfh*g
bfh*g
corresponding column n is
not empty, them we need to c
C+fh f
4 *g
fh*e
continue removing node 3
and retain values for nodes 1 g e h
& 2. 5 h*g h*e
Building tools (node degree & graph density):
• The out-degree of a node is the number of out-links it has.
• The in-degree of a node is the number of in-links it has.
• The degree of a node is the sum of in-degree and out-
degree.
• The average degree(mean) of a node is b/w 3 and 4.
• Degree of a simple branch/junction is 3
• Degree of a loop contained in 1 statement is 4
• Mean degree of 4 or 5  very busy flow graph
Node Reduction Optimization (tips):
• The optimum order for node reduction is to do the lowest degree
nodes first.
• When a node with degree 3(may be 1 in-link & 2out-links or 2 in-links
& 1 out-link) is removed , it reduces the total link count by 1 link.
• A degree 4 node keeps the link count the same & all higher degree
nodes increase the link count.
What’s wrong with arrays?
Matrix as a 2-dimensional array is not
convenient for larger graphs. Herez why!...
We have four reasons for the same-
• Space: For a matrix representation of an array, space
grows as n2 whereas, for a linked list, it grows only as kn,
where k is a small number such as 3 or 4.
• Weights: Most weights in arrays are complicated and may
have many components. This means that an additional
weight matrix is required for each such weight.
What’s wrong with arrays? (cont…)
• Variable-length weights: If the weights are regular
expressions/algebraic expressions, we would then need a 2-
dimensional string array (most of whose entries would be null).
• Processing time: Even though operations over null entries are
fast, it still takes time to access such entries and discard them.
The matrix representation forces us to spend a lot of time
processing combinations of entries that we know will yield null
results.
Building tools - Linked
d
list representations: 1 2 3 4 5
1
a b c a
1 3 4 2 2

3 d b
e f g 4 c f
5
g e h
h 5
node1, 3 ; a
node1,2, The link names will usually
Every node is a unique be pointers to entries in a
name/ number. node3, 2 ; d
string array(where actual
A link is a pair of node node3, 4; b weight expressions are
names. stored).
node4, 2 ; c
The linked list entries for
the above are  … node4, 5 ; f
If the weights are fixed
node5, 2 ; g length, they can be
Format for linked list node5, 3 ; e associated with links in
entries: node5, 5 ; h parallel-fixed entry length
row, column ; data entry array.
Building tools - Linked list list entry content
representations: 1 node1, 3 ; a
Clarifying entries by using node 2 node2,exit
names & pointers…
list entry content 3,
1, 3 ; a 1 node1, 3 ; a 4,
2, 2 node2,exit 5,
3, 2 ; d 3 node3, 2 ; d 3 node3, 2 ; d

3, 4; b 3, 4; b 3, 4; b
1,
4, 2 ; c 4 node4, 2 ; c
5,
4, 5 ; f 4, 5 ; f
4 node4, 2 ; c
5, 2 ; g 5 node5, 2 ; g
4, 5 ; f
5, 3 ; e 5, 3 ; e
3,
5, 5 ; h 5, 5 ; h 5 node5, 2 ; g
Fig.1 is represented in a more logical format 3;e
in Fig.2 by representing the nodes under list 5;h
entry. Fig 3 is more detailed the with in-links 4,
to that node added (highlighted in black).
5,
Matrix operations:
• Parallel Reduction: the easiest operation. After
sorting, parallel links are adjacent entries with the
same pair of node names.
Example: Say we have 3 parallel links from node 17 to
node 44. y, z & w are the pointers to the weight
expressions.
Depicting all the entries for
parallel links between node
17 & node 44, we have -
node 17, 21 ; x  node 17, 21 ; x
, 44 ; y , 44 ; y
, 44 ; z where, y = y + z + w
, 44 ; w
Matrix operations:
• Loop Reduction: the self loop is identified. To remove the loop,
the link weight must be multiplied with all the out-links from that node.
Start by identifying the out-links to be multiplied. Multiply the self loop
(h*) where h is the link weight of the self loop with the out-link.
Example: From the below entries, it is evident at entry(5,5;h) that it is a self
loop at node 5 with link weight h. Also, from the 1st two entries, we see
that the out-links from node 5 are 2 and 3. We need to multiply the self
loop (h*) with the link weights of nodes going from node 5 to node 2 & 3.

Refer fig. on slide 43 for the


node 5, 2 ; g node 5, 2 ; h*g
graph.
5, 3 ; e 5, 3 ; h*e
5, 5 ; h 5, 5 ; h
Matrix operations:
• Cross-Term Reduction: Select a node for reduction. The
cross-term step requires that you combine every in-link to the
node with every out-link from that node. The in-links are
obtained by back pointers. The new links created be removing
the node will be associated with the nodes of the in-links.
Example: Say that the node to be removed was node 4.
• entry
list content d list entry content
• 2 node2, exit 3 b 4 c 2 2 node2, exit
(inlink)4, 2
(inlink)4, 2 f
5 (inlink)3,2
(inlink)3,2
3 node3,2 ; d
3 node3,2 ; d The changes are
• 3,4 ; b highlighted in dark red
3,2 ; bc
3,5 ; bf
4 node4, 2 ; c d 4 node4, 2 ; c
4, 5 ; f 3 2
bc 4, 5 ; f
(inlink)3,4; b (inlink)3,4; b
• 5 (inlink)4, 5 bf 5 5 (inlink) 4, 5
The powers of a matrix has not
been covered. This includes basic
matrix multiplication that you
already know & sets of paths.
Please read through…  Page 405 of the
Boris Beizer text.
*** Some Questions picked up from the previous papers for units V, VI, VII, VIII ***
--8 marks questions--
1.Write the designers comments about state graphs.
2.Write an algorithm for all pair paths using matrix operations.
3.Define – maximum element and minimum element of a graph.
4.Explain parallel reduction and loop reduction.
5.Explain -
a) Distributive laws b) Absorption rule
6.Illustrate the applications of Decision tables?
7.The behavior of a finite state machine is invariant under all encodings. Justify?
8.What operations does a tool kit consist for the representation of graphs?
9.How can a relation matrix be represented and what are the properties of relations?
10.What are the rules of Boolean algebra?
--12 marks questions --
1.Define the purpose of KV charts. Describe the use of KV charts in logic based testing.
2.Define a state chart. Define the method used to distinguish good and bad state graphs.
3.Briefly discuss the following -
a) matrix of a graph b) node reduction algorithms
--16 marks questions--
1.Draw a hard disk recovery system with a state graph and state table.
2.What is decision table and how is it useful in testing? Explain it with the help of an example.
3.Write short notes on -
a) Transition bugs b) Dead states
c) State bugs d) Encoding bugs.
4.Explain State graphs with implementation?
5.What is Decision table and how is a Decision table useful in testing? Explain with the help of an example?
6.Explain -
a) finite state machine b)state graph inputs and outputs c) transitions and state tables
And yeah!!! Plz solve all
the questions that
appeared in previous
papers! 

Done!!! Do feel free to get back


incase you have any questions 

Note: Please read through the text


by ‘Boris Beizer’ atleast once. This
PPT is just for your reference & for
step by step understanding of the
processing.

You might also like