breadth-first-search Questions

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.

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

4

So my aunt plays this now popular mobile game, shown in the picture below. She got stuck on a certain level and asked me if I can solve it. Knowing that I'm not smart enough to find patterns or a s...
Burchett asked 15/9, 2021 at 18:16

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

5

Solved

I don't need code, just an explanation. My textbook says level order: each node at level i is processed before any node at level i+1 My understanding of breadth first searching is that you exp...

8

Solved

The time complexity to go over each adjacent edge of a vertex is, say, O(N), where N is number of adjacent edges. So, for V numbers of vertices the time complexity becomes O(V*N) = O(E), where E is...
Coble asked 24/10, 2014 at 13:43

24

Solved

Let's say you wanted to implement a breadth-first search of a binary tree recursively. How would you go about it? Is it possible using only the call-stack as auxiliary storage?
Drugi asked 31/3, 2010 at 0:5

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...

9

Solved

I've done some research, and I seem to be missing one small part of this algorithm. I understand how a Breadth-First Search works, but I don't understand how exactly it will get me to a specific pa...
Tammitammie asked 5/12, 2011 at 0:35

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...

3

Solved

Just a quick and silly question, about BFS traversal on graphs I found on many sites the pseudocode for a BFS is pretty much something like this: BFS (Graph, root): create empty set S create emp...
Omora asked 10/8, 2017 at 21:29

4

I'm trying to write the codes for breadth-first search in binary tree. I've stored all the data in a queue, but I can't figure out how to travel to all nodes and consume all their children. Here's...
Berbera asked 17/5, 2011 at 2:35

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

7

Solved

Both can be used to find the shortest path from single source. BFS runs in O(E+V), while Dijkstra's runs in O((V+E)*log(V)). Also, I've seen Dijkstra used a lot like in routing protocols. Thus, w...
Outpour asked 29/9, 2010 at 0:56

5

Solved

I was reading about Graph algorithms and I came across these two algorithms: Dijkstra's algorithm Breadth-first search What is the difference between Dijkstra's algorithm and BFS while looking fo...
Racquelracquet asked 22/8, 2014 at 14:46

7

Solved

I need help finding all the shortest paths between two nodes in an unweighted undirected graph. I am able to find one of the shortest paths using BFS, but so far I am lost as to how I could find ...
Fieldwork asked 3/1, 2013 at 17:31

7

Solved

How do you trace the path of a Breadth-First Search, such that in the following example: If searching for key 11, return the shortest list connecting 1 to 11. [1, 4, 7, 11]
Shantell asked 19/1, 2012 at 6:45

4

Solved

This is a leetcode question. Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree [3, 9, 20, null, n...

9

Solved

The basic algorithm for BFS: set start vertex to visited load it into queue while queue not empty for each edge incident to vertex if its not visited load into queue mark vertex So I w...

6

Solved

Here is a java code for breadth-first travel: void breadthFirstNonRecursive(){ Queue<Node> queue = new java.util.LinkedList<Node>(); queue.offer(root); while(!queue.isEmpty()){ Nod...
Hilarius asked 3/6, 2010 at 19:16

10

This is what I have. I thought pre-order was the same and mixed it up with depth first! import java.util.LinkedList; import java.util.Queue; public class Exercise25_1 { public static void main(S...
Narcoma asked 10/3, 2011 at 16:3

5

Solved

What is the easiest way, preferably using recursion, to find the shortest root-to-leaf path in a BST (Binary Search Tree). Java prefered, pseudocode okay. Thanks!

3

Solved

I wrote this code of BFS in c++ using wikipedia's pseudocode. The function takes two parameters s,t. Where s is the source node and t is the target, if the target is fount, the the search return th...
Hyatt asked 1/11, 2012 at 4:40

© 2022 - 2025 — McMap. All rights reserved.