Skip to content
CodeWiki
Practice
Paths
Tracks
Cheatsheets
Playground
Glossary
AI era
Search
⌘K
English
English
Chinese
Practice
Paths
Tracks
Cheatsheets
Playground
Glossary
AI era
English
English
Chinese
Practice
/
Quiz
/
CS foundations
/
Trees and graphs
When does ordinary BFS provide a shortest-path guarantee?
from Trees and graphs
Node 24
intermediate
1 min
When does ordinary BFS provide a shortest-path guarantee?
When shortest means the fewest edges, equivalently when all edges have equal cost.
Whenever all edge weights are nonnegative but unequal.
Only when the graph is represented by a matrix.
Whenever DFS and BFS happen to visit the same first neighbor.
Check
Ask AI about this kata
Report an error
previous kata
Why does an adjacency list usually fit a sparse graph better than an adjacency matrix?
Quiz
next kata
What does this iterative DFS print?
Predict the output
A new version is available
Reload