Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Digraphs - Lecture Slides - Fundamental Algorithms | CS 231, Study notes of Algorithms and Programming

Material Type: Notes; Class: Fundamental Algorithms; Subject: Computer Science; University: Wellesley College; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 08/19/2009

koofers-user-cd7
koofers-user-cd7 🇺🇸

10 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Directed graphs, digraphs, are graphs in which edges
connecting nodes are one-way.
Directed graphs may be represented using either an
adjacency matrix or an adjacency list.
Digraphs
A
B C G
D E
F
HI
JK
LM
Setting Up Depth-First Search
DFS(G)
for each u V[G]
do color[u] WHITE
parent[u] NIL
time 0
for each u V[G]
do if color[u] = WHITE
then DFS-Visit[u]
A
B C G
D E
F
HI
JK
LM
pf3
pf4
pf5

Partial preview of the text

Download Digraphs - Lecture Slides - Fundamental Algorithms | CS 231 and more Study notes Algorithms and Programming in PDF only on Docsity!

• Directed graphs, digraphs, are graphs in which edges

connecting nodes are one-way.

• Directed graphs may be represented using either an

adjacency matrix or an adjacency list.

Digraphs

A

B C (^) G

D E

F

H I

J K

L M

Setting Up Depth-First Search

DFS(G)

for each uV [ G ] do color[u] ← WHITE parent[u] ← NIL time0 for each uV [ G ] do if color[u] = WHITE then DFS-Visit[ u ]

A

B C (^) G

D E

F

H I

J K

L M

DFS-Visit( u )

DFS-Visit( u ) color[u] ← GRAY d[u]time ← time+ for each vAdj(u) do if color[v] = WHITE then parent[v]u DFS-Visit[ v ] color[u] ← BLACK f[u]time ← time+

A

B C (^) G

D E

F

H I

J K

L M

A

B

C

G

D

E

F

H

I

J

L

M

K

Depth-First Search Forest*

Tree edge

Back edge

*Which edges betray a directed cycle?

Cross edge

Forward edge

*In order for the Professor's algorithm to work, what must be true about the digraph?

All Dressed Up*

Recognizing DAGs

Lemma.

A directed graph G is acyclic if and only if a depth-first

search of G yields no back edges.

A

B

C

G

D

E

F

H

I

J

L

M

K

Proof of Correctness

Theorem.

Topological-Sort( G ) produces a topological sort of a

directed acyclic graph.