Is Depth-First Search Order for Graph Traversal Direction-Agnostic?

In summary, the speaker is seeking clarification on the concept of depth-first search and if there are any restrictions on the order in which nodes can be traversed. They are also discussing the difference between a tree and a graph in relation to depth-first search. The responder explains that depth-first means processing the whole subtree of each child node before any other child nodes are processed and that in a graph, every unvisited neighbor must be processed before backtracking.
  • #1
gfd43tg
Gold Member
950
50
ImageUploadedByPhysics Forums1407629937.062203.jpg


Hello, I drew up this graph to try and understand the concept of depth-first search. Starting at node C, I was wondering if its correct for the order to be C-A-B-D or C-B-A-D? It seems like you can traverse in either direction without a problem.
 
Physics news on Phys.org
  • #2
For me, both are valid. You could certainly look at all the children, order them by some preference and visit each one in that order.
 
  • #3
I'm confused as to what movements are not allowed? It seems very unclear to me what is a legitimate traversal and what isn't. Can you go C-D-B-A or C-D-A-B? What counts as not being permitted?
 
  • #4
Depth-first means the whole subtree of each child node is processed before any other child nodes are processed. Does that make sense? Your example tree is a bad example because the children of C have no children themselves.

Oh sorry, you are talking about a graph, not a tree. Hmm.
 
  • #5
Ok, for a graph, depth-first must mean, process every unvisited neighbor before backtracking. CAD -- not allowed.
 

Related to Is Depth-First Search Order for Graph Traversal Direction-Agnostic?

What is depth first search of graph?

Depth first search of graph is a graph traversal algorithm that starts at a root vertex and explores as far as possible along each branch before backtracking. This algorithm is commonly used to traverse or search a graph and can be implemented using recursion or a stack data structure.

What is the time complexity of depth first search of graph?

The time complexity of depth first search of graph is O(V + E), where V is the number of vertices and E is the number of edges in the graph. This means that the time required to traverse the entire graph is directly proportional to the number of vertices and edges in the graph.

How does depth first search of graph differ from breadth first search?

Depth first search of graph differs from breadth first search in the order in which vertices are visited. In depth first search, all the descendants of a vertex are explored first before moving on to the next vertex. In contrast, breadth first search explores all the vertices at the current depth before moving on to the next depth.

What is the purpose of using a visited array in depth first search of graph?

A visited array is used in depth first search of graph to keep track of which vertices have already been visited. This prevents the algorithm from getting stuck in an infinite loop by visiting the same vertex multiple times. The array is typically initialized to all false and is updated to true once a vertex has been visited.

What are some applications of depth first search of graph?

Depth first search of graph has many applications in computer science, including topological sorting, cycle detection, path finding, and maze generation. It is also commonly used in artificial intelligence, web crawling, and social network analysis.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
977
  • Programming and Computer Science
Replies
1
Views
993
  • Engineering and Comp Sci Homework Help
Replies
2
Views
822
  • Programming and Computer Science
Replies
3
Views
738
  • Calculus and Beyond Homework Help
Replies
22
Views
2K
  • Calculus and Beyond Homework Help
Replies
3
Views
2K
  • Calculus and Beyond Homework Help
Replies
5
Views
948
  • Calculus and Beyond Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Calculus and Beyond Homework Help
Replies
32
Views
2K
Back
Top