0
0
DSA Cprogramming~5 mins

Shortest Path in Unweighted Graph Using BFS in DSA C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main idea behind using BFS to find the shortest path in an unweighted graph?
BFS explores nodes level by level, ensuring the first time we reach a node is via the shortest path from the start node.
Click to reveal answer
beginner
In BFS for shortest path, what data structure is used to keep track of nodes to visit next?
A queue is used to keep nodes in the order they are discovered, ensuring level-wise traversal.
Click to reveal answer
intermediate
How do we keep track of the shortest distance from the start node to every other node in BFS?
We maintain a distance array where distance[node] is updated the first time the node is visited, representing the shortest path length.
Click to reveal answer
intermediate
Why does BFS guarantee the shortest path in an unweighted graph but not necessarily in a weighted graph?
Because BFS treats all edges as equal cost (1 step), it finds the minimum number of edges. Weighted graphs require algorithms like Dijkstra's to consider edge weights.
Click to reveal answer
intermediate
What is the time complexity of BFS when finding the shortest path in an unweighted graph with V vertices and E edges?
The time complexity is O(V + E) because each vertex and edge is processed at most once.
Click to reveal answer
Which data structure is essential for BFS to find the shortest path in an unweighted graph?
AHash Map
BStack
CPriority Queue
DQueue
What does the distance array store in BFS shortest path algorithm?
AWeight of edges
BNumber of edges from start node to each node
CNumber of nodes in the graph
DOrder of node discovery
Why can't BFS be used directly to find shortest paths in weighted graphs?
ABecause BFS does not consider edge weights
BBecause BFS uses a stack
CBecause BFS is too slow
DBecause BFS only works on trees
What is the initial distance value assigned to all nodes except the start node in BFS shortest path?
A0
B1
C-1 or Infinity
DUndefined
What is the time complexity of BFS for shortest path in an unweighted graph?
AO(V + E)
BO(V^2)
CO(E^2)
DO(log V)
Explain step-by-step how BFS finds the shortest path in an unweighted graph starting from a given node.
Think about how BFS explores neighbors and records distances.
You got /5 concepts.
    Describe why BFS is suitable for shortest path in unweighted graphs but not for weighted graphs, and name an algorithm used for weighted graphs.
    Compare edge treatment in BFS vs weighted graph algorithms.
    You got /3 concepts.