Digraphs - PowerPoint PPT Presentation

About This Presentation
Title:

Digraphs

Description:

1. Digraphs. Reachability. Connectivity. Transitive Closure ... MIA. ORD. LAX. DFW. SFO. v. 2. v. 1. v. 3. v. 4. v. 5. v. 6. v. 7. 14. Floyd-Warshall Algorithm ... – PowerPoint PPT presentation

Number of Views:828
Avg rating:3.0/5.0
Slides: 23
Provided by: iu12
Category:
Tags: digraphs | mia

less

Transcript and Presenter's Notes

Title: Digraphs


1
Digraphs
  • Reachability
  • Connectivity
  • Transitive Closure
  • Floyd-Warshall Algorithm

v
7
BOS
v
ORD
4
JFK
v
v
2
6
SFO
DFW
LAX
v
3
v
1
MIA
v
5
2
Digraphs
1
A typical student day
wake up
3
2
eat
study computer sci.
5
4
work
more c.s.
7
play
8
write c.s. program
6
battletris
9
make cookies for c.s. prof.

10
sleep
11
dream of cs16
3
Whats a Digraph?
  • a) A small burrowing animal with long sharp teeth
    and a unquenchable lust for the blood of computer
    science majors
  • b) A distressed graph
  • c) A directed graph

a
Each edge goes in one direction Edge (a,b) goes
from a to b, but not b to a
Youre saying, Yo, how about an example of how
we might be enlightened by the use of
digraphs!! - Well, if you insist. . .
4
Applications
Maps digraphs handle one-way streets (especially
helpful in Providence)
5
Another Application
  • Scheduling edge (a,b) means task a must be
    completed before b can be started

cs15
cs16
cs22
cs126
cs127
cs141
cs32
cs167
cs31
old computer scientists never die, they just fall
into black holes
6
DAGs
  • dag (noun) dÂ-g
  • 1. Di-Acyl-Glycerol - My favorite snack!
  • 2.mans best friend
  • 3. directed acyclic graph

Say What?!
directed graph with no directed cycles
a
b
a
b
c
c
e
d
e
d
DAG
not a DAG
7
Depth-First Search
  • Same algorithm as for undirected graphs
  • On a connected digraph, may yield unconnected DFS
    trees (i.e., a DFS forest)

a
b
c
f
e
d
a
e
b
d
f
c
8
Reachability
  • DFS tree rooted at v vertices reachable from v
    via directed paths

a
b
c
f
e
d
e
c
f
b
a
c
a
b
d
d
9
Strongly Connected Digraphs
  • Each vertex can reach all other vertices

a
g
c
d
e
b
f
10
Strongly Connected Components
a
a , c , g
g
c
f , d , e , b
d
e
b
f
11
Transitive Closure
  • Digraph G is obtained from G using the rule If
    there is a directed path in G from a to b, then
    add the edge (a,b) to G


G
G
12
Computing the Transitive Closure
  • We can perform DFS starting at each vertex
  • Time O(n(nm))
  • Alternatively ... Floyd-Warshall Algorithm

if there's a way to get from A to B and from B
to C then there's a way to get from A to C.
Pink Flo
yd
13
Example
v
7
BOS
v
ORD
4
v
2
v
6
SFO
DFW
v
LAX
7
BOS
v
3
v
1
MIA
v
ORD
4
v
5
JFK
v
2
v
6
SFO
DFW
LAX
v
3
v
1
MIA
v
5
14
Floyd-Warshall Algorithm
  • Assumes that methods areAdjacent and
    insertDirectedEdge take O(1) time (e.g.,
    adjacency matrix structure)

Algorithm FloydWarshall(G) let v1 ... vn be
an arbitrary ordering of the vertices G0
G for k 1 to n do // consider all possible
routing vertices vk Gk Gk-1// these are the
only ones you need to store for each (i, j
1, ..., n) (i ! j) (i, j ! k) do // for
each pair of vertices vi and vj if
Gk-1.areAdjacent(vi,vk) and
Gk-1.areAdjacent(vk,vj) then
Gk.insertDirectedEdge(vi,vj,null) return
Gn
Digraph Gk is the subdigraph of the transitive
closure of G induced by paths with intermediate
vertices in the set v1, ..., vk Running time
O(n3)
15
Example
  • digraph G

BOS
v
ORD
4
JFK
v
v
2
6
SFO
DFW
LAX
v
3
v
1
MIA
v
5
16
Example
  • digraph G

v
7
BOS
v
4
ORD
JFK
v
v
2
6
SFO
DFW
LAX
v
3
v
1
MIA
v
5
17
Topological Sorting
  • For each edge (u,v), vertex u is visited before
    vertex v

1
A typical student day
w
ak
e up
3
2
eat
cs16 meditation
5
4
w
ork
more cs16
7
play
8
cs16 program
6
cxhe
xtris
9
mak
e cookies
for cs16 HT
A
10
sleep
11
dream of cs16
18
Topological Sorting
  • Topological sorting may not be unique

A
A B C D
or
A C B D
C
B
D
- You make the call!
19
Topological Sorting
  • Labels are increasing along a directed path
  • A digraph has a topological sorting if and only
    if it is acyclic (i.e., a dag)

1
A
2
3
B
C
5
4
E
D
20
Algorithm for Topological Sorting
A
method
T
opolog
icalSor
t
if
there are more v
ertices
let
v

be a source
B
C
// a v
erte
x w/o incoming edges
label and remo
v
e
v



T
opolog
icalSor
t
D
E
21
Algorithm (continued)
  • Simulate deletion of sources using indegree
    counters

T
opSort
(V
erte
x v)
label v
f
or
each
edge(v
,w)
inde
g(w) inde
g(w)
-
1
if
inde
g(w) 0
T
opSort
(w)
Compute indeg(v) for all vertices Foreach
vertex v do if v not labeled and indeg(v)
0 then TopSort(v)
22
Example
?
0
?
0
A
B
?
1
C
D
?
3
?
2
E
F
?
1
G
?
2
H
?
1
I
?
3
Write a Comment
User Comments (0)
About PowerShow.com