Top "Breadth-first-search" questions

In graph theory, breadth-first search (BFS) is a graph search algorithm that begins at the root node and explores all the neighboring nodes.

Why DFS and not BFS for finding cycle in graphs

Predominantly DFS is used to find a cycle in graphs and not BFS. Any reasons? Both can find if a …

algorithm tree graph-theory depth-first-search breadth-first-search
How can I remember which data structures are used by DFS and BFS?

I always mix up whether I use a stack or a queue for DFS or BFS. Can someone please provide …

stack queue depth-first-search breadth-first-search
How would you print out the data in a binary tree, level by level, starting at the top?

This is an interview question I think of a solution. It uses queue. public Void BFS() { Queue q = new Queue(); …

algorithm binary-tree breadth-first-search
Printing BFS (Binary Tree) in Level Order with Specific Formatting

To begin with, this question is not a dup of this one, but builds on it. Taking the tree in …

python algorithm binary-tree breadth-first-search tree-traversal
Why use Dijkstra's Algorithm if Breadth First Search (BFS) can do the same thing faster?

Both can be used to find the shortest path from single source. BFS runs in O(E+V), while Dijkstra's …

algorithm graph dijkstra breadth-first-search
Finding all the shortest paths between two nodes in unweighted undirected graph

I need help finding all the shortest paths between two nodes in an unweighted undirected graph. I am able to …

algorithm graph shortest-path breadth-first-search
Implementing BFS in Java

I am a beginner in Java, and I need some help. I am trying to implement Breadth First Search algorithm …

java breadth-first-search game-development
Shortest path (fewest nodes) for unweighted graph

I'm trying build a method which returns the shortest path from one node to another in an unweighted graph. I …

java algorithm graph shortest-path breadth-first-search
Recursive breadth-first travel function in Java or C++?

Here is a java code for breadth-first travel: void breadthFirstNonRecursive(){ Queue<Node> queue = new java.util.LinkedList<…

java c++ algorithm tree breadth-first-search