How directed graphs are visited using DFS and BFS?

Viewed 2021

Is the answer to first question correct? IF Yes then How? What is the rule of DFS and BFS to visit the nodes in directed graph?

For whatever I know, we have to go through level by level in BFS. In that case, The answer to first question should be A B C D E F ??

S

2 Answers

The correct answer to the first question is the one you wrote in your Question. There must be typo in the Question. BFS follows queues while DFS follows stack.

In BFS, nodes are visited level by level and from left to right. It does not mater even if it Directed tree or Undirected tree or graph.

In DFS, parent node is visited before visiting its children or any connected node.

Related