Professional Documents
Culture Documents
Graphs: Chapter 6 Lec 2
Graphs: Chapter 6 Lec 2
CHAPTER 6 LEC 2
Outline
Cycle Detection
Spanning Trees
Topological Sort
Cycle Detection
Can be implemented with small modifications in DFS(v)
cycleDetectionDFS(v)
num(v) = i++;
for all vertices u adjacent to v
if num(u) is 0
attach edge(uv) to edges;
cycleDetectionDFS(u);
else if edge(vu)is notin edges
cycle detected;
Cycle Detection- Application
Deadlock detection in
operation system
topologicalSort(digraph)
for i = 1 to |V|
find a minimal vertex v;
num(v) = i;
remove from digraph vertex v and all edges incidentwith v;
Topological Sort -example
Topological Sort - DFS
TS(v)
num(v) = i++;
for all vertices u adjacent to v
if num(u) == 0
TS(u);
else if TSNum(u) == 0
error;
TSNum(v) = j++;
Topological Sort - example
Assignment
Select any application that can be modeled with common
problems of graph such as path, shortest path, minimum
spanning tree, cycle detection, topological sort, graph
coloring, networking and matching.
Model and implement the application and report a word
document which contain statement of the problem, model of
the problem and implementation.
Refer Adam Drozdek 8.13 Case Study: Distinct
Representatives (p 450) as a sample
Due date January 13, 2014. e-mail my2alew@gmail.com