depth-first-search Questions
6
Solved
In the recursive DFS, we can detect a cycle by coloring the nodes as WHITE, GRAY and BLACK as explained here.
A cycle exists if a GRAY node is encountered during the DFS search.
My question is: W...
Faber asked 30/9, 2017 at 19:0
12
Predominantly DFS is used to find a cycle in graphs and not BFS. Any reasons? Both can find if a node has already been
visited while traversing the tree/graph.
Seawright asked 19/5, 2010 at 21:42
2
Suppose we have a graph such as:
If you wanted a path from 0 to 5, in what order will we visit the nodes if we perform DFS and BFS on this graph (assume the lowest element is always pushed...
Intracardiac asked 28/4, 2013 at 8:30
17
Solved
I always mix up whether I use a stack or a queue for DFS or BFS. Can someone please provide some intuition about how to remember which algorithm uses which data structure?
Moses asked 14/10, 2010 at 0:18
10
Can you please let me know what is incorrect in below DFS code. It's giving correct result AFAIK, but I don't know when it will fail.
graph1 = {
'A' : ['B','S'],
'B' : ['A'],
'C' : ['D','E','F'...
Guaiacum asked 15/4, 2017 at 19:23
5
Solved
It seems to me like Pre-order traversal and DFS are same as in both the cases we traverse till the leaf node in a depth wise fashion. Could anyone please correct me if I am wrong?
Thanks in advanc...
Manas asked 5/2, 2014 at 8:8
3
I want to count total number of directed cycles available in a directed graph (Only count is required).
You can assume graph is given as adjacency matrix.
I know DFS but could not make a workin...
Unesco asked 27/10, 2015 at 14:49
5
Solved
I understand BFS, and DFS, but for the life of me cannot figure out the difference between iterative deepening and BFS. Apparently Iterative deepening has the same memory usage as DFS, but I am una...
Lighterman asked 8/6, 2010 at 0:54
4
Here is the question description. The first 2 suggested solutions involve DFS and BFS. This question refers to the 1st two approaches: DFS and BFS.
I have included the problem statement here for ...
Pawsner asked 17/6, 2018 at 23:17
4
Solved
I know we can use DFS for maze exploration. But I think we can also use BFS for maze exploration. I'm little bit confused here because most of the books and articles that I've read had used DFS for...
Caughey asked 25/11, 2013 at 11:55
7
Solved
I understand and can easily implement BFS.
My question is, how can we make this BFS limited to a certain depth? Suppose, I just need to go 10 level deep.
Batchelor asked 21/4, 2012 at 10:56
8
I know BFS alone can find the shortest path in an unweighted graph but I also read on a couple of sites where people were claiming that either BFS or DFS could do this. I just wanted to confirm tha...
Gemperle asked 9/2, 2013 at 3:50
2
Solved
In a bidirectional graph check if a path exists between node A and node B.
My code does not work for certain input (samples provided below). Is this implementation correct or I missed something?
bo...
Cozenage asked 5/1, 2022 at 4:41
9
Solved
I know the common way to do a topological sort is using DFS with recursion. But how would you do it using stack<int> instead of recursion? I need to obtain the reversed post-order but I'm kin...
Shuck asked 22/11, 2013 at 20:1
2
To make things easier, the table contains all the words in the English dictionary.
What I would like to do is be able to store the data as a trie. This way I can traverse the different branches o...
Futrell asked 28/5, 2010 at 5:23
4
Solved
So I know how to create a kernel and to iterate over the processes linearly by simply including linux/sched.h and using the following code:
struct task_struct *task;
for_each_process(task)
{
prin...
Yowl asked 6/10, 2013 at 11:41
5
Solved
Extracted from here we got a minimal iterative dfs routine, i call it minimal because you can hardly simplify the code further:
def iterative_dfs(graph, start, path=[]):
q = [start]
while q:
v ...
Saritasarkaria asked 9/11, 2017 at 1:51
3
Solved
I have read about DFS and BFS many times but I have this doubt lingering my mind since long. In a lot of articles it is mentioned that DFS can get stuck in infinite loops.
As far as I know, this l...
Sparid asked 15/10, 2011 at 16:55
5
Solved
I'm having a hard time understanding Tarjan's algorithm for articulation points. I'm currently following this tutorial here: https://www.hackerearth.com/practice/algorithms/graphs/articulation-poin...
Isthmus asked 12/6, 2017 at 8:10
1
The following is pseudocode implement depth-first search(DFS) with one stack and a large table to mark visited nodes:
DFS(N0):
StackInit(S)
S.push((N0, null))
if isGoal(N0) then do
return true
...
Pseudaxis asked 24/12, 2020 at 3:43
2
I am trying to find (using Python) all possible solutions to a maze. I have a DFS script that returns one solution. I am trying to adapt it but I'm really having a hard time wrapping my head around...
Arbuckle asked 29/12, 2020 at 17:3
4
Solved
I was trying to write code for detecting a cycle in a directed graph and if there is no cycle then return a topological order of the same.
While I was searching for it I came across different tec...
Submarine asked 15/10, 2019 at 6:31
3
According to Norvig in AIMA (Artificial Intelligence: A modern approach), the Depth-first algorithm is not complete (will not always produce a solution) because there are cases when the subtree bei...
Intransigence asked 21/2, 2011 at 15:38
2
Solved
What's the difference between a Spanning Tree and a Spanning Forest in graphs, conceptually.
Also, is it possible to construct a Spanning Forest through DFS or BFS traversals? Why? How?
I underst...
Hordein asked 6/4, 2017 at 10:31
4
Solved
I have written a recursive DFS algorithm to traverse a graph:
void Graph<E, N>::DFS(Node n)
{
std::cout << ReadNode(n) << " ";
MarkVisited(n);
NodeList adjnodes = Adjacent(n...
Hunger asked 8/2, 2012 at 20:48
1 Next >
© 2022 - 2025 — McMap. All rights reserved.