Graph Matrices and Applications
Graph Matrices and Applications
• 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.
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
3 d b * c f
4 c f * d b
g e h g e h
5 5
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-
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
1 a 3b c4 2
+
fh*e (fh*g)
1 2 3 4 5
a
1
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
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.