Analyzing Depth-first Search Edge Types

  • Context: MHB 
  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Edge Search
evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hello! (Wave)

I want to apply the Depth-first search algorithm at the following graph.
We consider that at the iteration of the algorithm, we look at the nodes alphabetically. Also the nodes are registered alphabetically in each list. I want to calculate the "discovery" time and the "finish" time for each node and also the kind of each edge.

View attachment 3654
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

I found these "discovery" and "finish" times:

View attachment 3655

Have I calculated them right? (Thinking)

Also, in order to find the kind of the edges I wanted to use this:

$$\begin{bmatrix}
\text{ tree edges: } x \to y & [d[y],f[y]] \subset [d[x],f[x]] \\ \\
\text{forward edges: } x \to y & [d[x],f[x]] \subset [d[y],f[y]] \\ \\
\text{back edges: } x \to y & [d[y],f[y]] \subset [d[x],f[x]] \\ \\
\text{Cross edges: } x \to y & [d[x],f[x]] \cap [d[y],f[y]]=\varnothing
\end{bmatrix}$$

But, when we have for example the case $[d[y],f[y]] \subset [d[x],f[x]]$ how can we know if it is a tree edge or a back edge? (Thinking)
 
I think that I have done some mistakes.. (Lipssealed)
I think that it should be like that:

View attachment 3669But how can we find the type of the edges? :confused:
 

Attachments

  • discfin.png
    discfin.png
    7.2 KB · Views: 140
This graph:

View attachment 3678shows the parent of each node.
When there is a red edge does this mean that we have a tree edge? If so, could you explain me why? (Thinking)

Aren't $jh,ia$ forward edges and $ag$ a back edge? (Thinking)
 

Attachments

  • DNdZr.png
    DNdZr.png
    6.3 KB · Views: 143

Similar threads

  • · Replies 22 ·
Replies
22
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 0 ·
Replies
0
Views
3K
  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 14 ·
Replies
14
Views
5K
Replies
1
Views
1K
Replies
2
Views
2K
Replies
23
Views
2K