0
0
DSA Typescriptprogramming~5 mins

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

Choose your learning style9 modes available
Recall & Review
beginner
What does BFS stand for and what is its main use in graphs?
BFS stands for Breadth-First Search. It is mainly used to explore nodes level by level and find the shortest path in unweighted graphs.
Click to reveal answer
beginner
Why is BFS suitable for finding the shortest path in an unweighted graph?
Because BFS explores neighbors in layers, the first time it reaches a node, it has found the shortest path to that node.
Click to reveal answer
beginner
In BFS for shortest path, what data structure is commonly used to keep track of nodes to visit next?
A queue is used to keep track of nodes to visit next, ensuring nodes are processed in the order they are discovered.
Click to reveal answer
intermediate
What additional information do we store during BFS to reconstruct the shortest path?
We store the parent or predecessor of each node, so after BFS finishes, we can trace back from the target node to the start node.
Click to reveal answer
intermediate
What is the time complexity of BFS when finding the shortest path in an unweighted graph?
The time complexity is O(V + E), where V is the number of vertices and E is the number of edges, because each node and edge is processed once.
Click to reveal answer
What data structure does BFS use to explore nodes in order?
AQueue
BStack
CPriority Queue
DHash Map
In an unweighted graph, BFS finds the shortest path because it:
AExplores nodes in increasing order of distance from the start
BExplores nodes randomly
CUses weights to calculate distance
DOnly visits each node once
Which of these is NOT needed to reconstruct the shortest path after BFS?
AParent or predecessor of each node
BNode color coding
CVisited nodes set
DDistance from start node
What is the initial step in BFS for shortest path?
AMark all nodes as visited
BAdd all nodes to the queue
CAdd the start node to the queue and mark it visited
DCalculate weights of edges
What is the time complexity of BFS in terms of vertices (V) and edges (E)?
AO(E^2)
BO(V^2)
CO(log V)
DO(V + E)
Explain how BFS finds the shortest path in an unweighted graph step-by-step.
Think about how BFS explores nodes layer by layer.
You got /5 concepts.
    Describe how to reconstruct the shortest path after BFS completes.
    Trace back from the end node to the start using parents.
    You got /4 concepts.