0% found this document useful (0 votes)
35 views

Algorithm

This document discusses algorithms for depth first search, topological sorting, and finding connected components in graphs. It explains that depth first search (DFS) colors nodes white before visiting, gray while visiting, and black after visiting. It traces the DFS process and records discovery and finish times. Topological sorting runs DFS to compute finish times and inserts vertices into a linked list in that order. Finding connected components runs DFS on the graph and outputs the vertices of each tree in the depth first forest as separate connected components.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Algorithm

This document discusses algorithms for depth first search, topological sorting, and finding connected components in graphs. It explains that depth first search (DFS) colors nodes white before visiting, gray while visiting, and black after visiting. It traces the DFS process and records discovery and finish times. Topological sorting runs DFS to compute finish times and inserts vertices into a linked list in that order. Finding connected components runs DFS on the graph and outputs the vertices of each tree in the depth first forest as separate connected components.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

1/8

U V 2/7 Faheem Janjua

W
9/12

Algorithm Depth First Search


d[u] Distance or time between searching a Node. f[u] is the time of searching all the variables in the graph(G). d[u] is always less then f[u] 4/5 d[u] < f[u] 5/6 10/12 and the values must be between 1_____2 vertices [V] u is white before time d[u] Gray between d[u]f[u] Black there after Depth First Search DFS(G) For each vertex u V[G] Do color [u] White X Y Z

.[u]
Time

Nil 0

For each V[u] V [G] Do if color [u] = white Then DFS-visit (u) DFS visit (u) Color (u) Time D[u] Gray time+1 time

For each V A adj [u] Do if color [V] = white Then [u] DFS-visit [V] Color[u] F[u] Black time time+1 u

Topological Sorting
Topological Sort (G) Call DFS (G) to compute finishing Item f[v] for each u

Faheem Janjua As each vertex is finished insert it into The format of a link list Return the link of list of vertices

Connecting Components
Call DFS (G) to compute finishing line f [u] For each vertex Compute Call DFS GT (GT) but in the main loop of Decreasing f[u]

DFS consider the vertex in order of Output

the vertices of each tree

In the depth first forest formed in line, 3 as a separate straight connected component.
ABC
FGH

DE

You might also like