Analyzing Depth-first Search Edge Types

In summary, the Depth-first search algorithm calculates the "discovery" and "finish" times for each node and also the kind of each edge. The algorithm uses the parent of each node to determine the type of each edge.
  • #1
evinda
Gold Member
MHB
3,836
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
  • #2
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: 46
  • #3
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: 46

Related to Analyzing Depth-first Search Edge Types

1. What is Depth-first Search (DFS)?

Depth-first Search (DFS) is an algorithm used to traverse a graph or tree data structure. It starts at a selected node and explores as far as possible along each branch before backtracking.

2. What are the different types of edges in DFS?

The three types of edges in DFS are tree edges, back edges, and forward/cross edges. Tree edges are the edges that are discovered during the traversal and create the tree structure. Back edges are edges that connect a descendant node to an ancestor node, creating a cycle. Forward/cross edges connect two nodes that are neither ancestor nor descendant, and do not create a cycle.

3. How do you analyze the time complexity of DFS edge types?

The time complexity of analyzing DFS edge types is O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges in the graph. This is because DFS visits each vertex and edge only once during the traversal.

4. How does DFS differ from Breadth-first Search (BFS)?

DFS differs from BFS in the order in which nodes are visited. DFS uses a stack data structure while BFS uses a queue. This means that DFS will explore one branch of the graph as far as possible before backtracking, while BFS will explore all nodes at a given depth before moving on to the next level.

5. What are the applications of DFS edge types analysis?

DFS edge types analysis can be used in various applications such as finding paths in a maze, detecting cycles in a graph, and solving puzzles. It can also be applied in network analysis, social network analysis, and data mining.

Similar threads

  • Set Theory, Logic, Probability, Statistics
Replies
22
Views
1K
  • Precalculus Mathematics Homework Help
Replies
13
Views
327
Replies
1
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
11
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
961
  • Programming and Computer Science
Replies
1
Views
691
  • Introductory Physics Homework Help
Replies
9
Views
170
  • Set Theory, Logic, Probability, Statistics
Replies
13
Views
3K
Replies
3
Views
353
  • Calculus and Beyond Homework Help
Replies
4
Views
824
Back
Top