Analyzing Depth-first Search Edge Types

  • Context: MHB 
  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Edge Search
Click For Summary
SUMMARY

This discussion focuses on the implementation of the Depth-first Search (DFS) algorithm to analyze edge types in a graph. The user outlines the algorithm's structure, including the calculation of "discovery" and "finish" times for nodes, and seeks clarification on identifying edge types: tree edges, forward edges, back edges, and cross edges. The user presents a matrix to categorize edges based on discovery and finish times but expresses confusion regarding specific cases, particularly distinguishing between tree edges and back edges.

PREREQUISITES
  • Understanding of Depth-first Search (DFS) algorithm
  • Familiarity with graph theory concepts, including edge types
  • Knowledge of time complexity analysis in algorithms
  • Basic programming skills to implement DFS in a preferred language
NEXT STEPS
  • Implement the Depth-first Search algorithm in Python or Java
  • Study the properties of graph traversal algorithms
  • Explore advanced graph theory topics, such as strongly connected components
  • Learn about the applications of DFS in solving real-world problems
USEFUL FOR

Students, computer science enthusiasts, and software developers interested in algorithm design, graph theory, and data structure optimization.

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)
 
Physics news on Phys.org
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: 116
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: 115

Similar threads

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