Henry R
- 25
- 0
Hello... how to write the function of depth first search?
Thank you.
Thank you.
The discussion revolves around writing a function for depth-first search (DFS) in graph traversal. Participants share algorithmic details and seek clarification on the implementation of DFS.
The discussion does not appear to have significant disagreement, as participants are primarily focused on sharing and clarifying the algorithm for depth-first search.
There are no explicit limitations or unresolved issues mentioned in the discussion.
This discussion may be useful for individuals looking to understand or implement depth-first search in graph algorithms, particularly students or those new to algorithm design.
Henry R said:Hello... how to write the function of depth first search?
Thank you.
Depthfirstsearch(G)
for each v ∈ V
color[v]=white
p[v]=NIL
time=0
for each v ∈ V
if color[v]=white then
Visit(v)
Visit(u)
color[u]=gray
time=time+1
d[u]=time
for each v ∈ Adj[u]
if color[v]=white then
p[v]=u
Visit(v)
color[u]=black
time=time+1
f[u]=time
Hey! Thanks. But, did u get the code by any websites? Oh okay, I understand. Thanks for helping.evinda said:Hi! (Wave)
That's the algorithm of depth-first-search:
Code:Depthfirstsearch(G) for each v ∈ V color[v]=white p[v]=NIL time=0 for each v ∈ V if color[v]=white then Visit(v)
Code:Visit(u) color[u]=gray time=time+1 d[u]=time for each v ∈ Adj[u] if color[v]=white then p[v]=u Visit(v) color[u]=black time=time+1 f[u]=time
Henry R said:Hey! Thanks. But, did u get the code by any websites? Oh okay, I understand. Thanks for helping.