Title: Lecture 18 Directed graphs and binary relations
1Lecture 18 Directed graphs and binary relations
2Directed Graph
- The representation of directed graph
- Adjacent matrix (5.1)
- Adjacent relation
- ni ? nj ? there is an arc in G from ni
to nj - Page 413, Example 1
- Practice 1
3Three equivalent set
Binary relations on n-element sets
Directed graphs with n nodes, no parallel arcs.
n X n Boolean matrix
?
?
Example two binary relations ? and s on a set
N, Let R and S be the boolean matrix for ? and s.
Then boolean matrix for ? U s is R V S
boolean matrix for ? s is R S
4Reachability
- Definition In a directed graph, node nj is
reachable from node ni if there is a path from ni
to nj -
- A(2) AXA (Boolean matrix multiplication).
- Recall the boolean matrix operation?
5A theorem
- Theorem on boolean adjacency matrices and
reachability -- If A is the Boolean adjacency
matrix for a directed graph G with n nodes and no
parallel arcs, then A(2)I,j1 if and only if
there is a path of length m from node ni to nj - Prove by induction
6Reachability matrix R
- If the number of nodes is n.
- R A V A(2) V A(3) V ..V A(n)
- then ni is reachable from nj if and only if
entry i, j in R is positive.
7Three equivalent sets for reachability
(ni,nj) belongs to the transistive closure of ?
nj reachable from ni in G
Ri,j 1 where R A V A(2) V A(3) V ..V A(n)
?
?
Example 5 (Page 416)
8Warshalls Algorithm
- Warshalls algorithm computes a sequence of n1
matrices M0, M1,M2,.,Mn. For each k, 0ltkltn,
MkI,j1 if and only if there is a path in G
from ni to nj whose interior nodes come only from
the set of nodes n1,n2,. nk .
9Warshalls Algorithm (cont.)
- ALGORITHM WALSHALL
- Walshall(nXn Boolean matrix M)
- for k0 to n-1 do
- for i1 to n do
- for j1 to n do
- Mi,j Mi,jV(Mi,k1
Mk1,j) - end for
- end for
- end for
- end Warshall
10Warshalls Algorithm (cont.)
- M0A and MnR
- To compute Mk1 from Mk
- 1. consider column k1 in Mk1
- 2. Foe each row with a 0 entry in this column,
copy that row to Mk1. - 3. Foe each row with a 1 entry in this column, or
that row with row k1 and write the resulting
row in Mk1. - Application of Warshalls Algorithm find out R
in O(n3) time.
11Assignment
- Exercise 6.1 , Due on Next Monday.
- 1, 4, 5, 17,24