0
0
DSA Typescriptprogramming~5 mins

BFS Breadth First Search on Graph in DSA Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does BFS stand for in graph traversal?
BFS stands for Breadth First Search. It is a way to explore all nodes in a graph level by level, starting from a chosen node.
Click to reveal answer
beginner
In BFS, which data structure is mainly used to keep track of nodes to visit next?
A queue is used in BFS to keep track of nodes to visit next. It helps explore nodes in the order they were discovered.
Click to reveal answer
intermediate
What is the main difference between BFS and DFS (Depth First Search)?
BFS explores nodes level by level using a queue, while DFS explores as far as possible along one branch before backtracking, using a stack or recursion.
Click to reveal answer
beginner
Why do we mark nodes as visited in BFS?
Marking nodes as visited prevents revisiting the same node multiple times, which avoids infinite loops and repeated work.
Click to reveal answer
intermediate
What is the time complexity of BFS on a graph with V vertices and E edges?
The time complexity of BFS is O(V + E), because it visits every vertex and edge at most once.
Click to reveal answer
Which data structure does BFS use to keep track of nodes to visit?
ATree
BQueue
CHash Map
DStack
What is the first step in BFS starting from a node?
AAdd all neighbors to the queue
BRemove the starting node from the graph
CMark all nodes as visited
DAdd the starting node to the queue and mark it visited
What happens when BFS visits a node's neighbor that is already visited?
AIt skips adding it to the queue again
BIt adds it again to the queue
CIt removes the neighbor from the graph
DIt restarts the BFS
Which of these is NOT true about BFS?
AIt uses a stack to keep track of nodes
BIt can find the shortest path in an unweighted graph
CIt explores nodes level by level
DIt marks nodes as visited
What is the order of visiting nodes in BFS starting from node 1 in this graph? 1 connected to 2 and 3, 2 connected to 4
A1, 4, 2, 3
B1, 3, 2, 4
C1, 2, 3, 4
D4, 2, 3, 1
Explain how BFS works step-by-step on a simple graph starting from a node.
Think about how you explore friends in layers starting from one person.
You got /5 concepts.
    Describe why BFS is useful for finding the shortest path in an unweighted graph.
    Imagine walking through rooms one step at a time.
    You got /4 concepts.