



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




For example:
Figure 1: Adjacency Lists
Explore level-by-level from s — find shortest paths
This is like exploring a maze.
Figure 2: Depth-First Search Frontier
parent = {s: None} DFS-visit (V, Adj, s): for v in Adj [s]: if v not in parent: parent [v] = s DFS-visit (V, Adj, v) DFS (V, Adj) parent = { } for s in V: if s not in parent: parent [s] = None DFS-visit (V, Adj, s)
search from start vertex s (only see stuff reachable from s)
explore entire graph
(could do same to extend BFS)
start v finish v
Figure 3: Depth-First Search Algorithm
Graph G has a cycle ⇔ DFS has a back edge
tree edges is a cycle
back edge: to tree ancestor
(<=)
(=>) consider first visit to cycle:
FIRST!
v (^2)
v 3
vk
v 1 v 0
Given Directed Acylic Graph (DAG), where vertices represent tasks & edges represent dependencies, order tasks without violating dependencies
Figure 6: Dependence Graph: DFS Finishing Times
Source = vertex with no incoming edges = schedulable at beginning (A,G,I)
BFS from each source:
DFS-Visit(v)
... Reverse of DFS finishing times (time at which DFS-Visit(v) finishes)
order.append(v) ^ order.reverse()
MIT OpenCourseWare http://ocw.mit.edu
Fall 2011
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.