0
0
DSA Cprogramming~5 mins

BFS Breadth First Search on Graph in DSA C - 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 method to explore all nodes of a graph level by level, starting from a chosen node.
Click to reveal answer
beginner
In BFS, which data structure is primarily used to keep track of nodes to visit next?
A queue is used in BFS to keep track of nodes to visit next. It ensures nodes are explored in the order they are discovered.
Click to reveal answer
intermediate
What is the main difference between BFS and DFS in graph traversal?
BFS explores nodes level by level using a queue, while DFS explores as deep as possible along each branch using a stack or recursion.
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), where V is the number of vertices and E is the number of edges, because each vertex and edge is processed once.
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 ensures correct traversal.
Click to reveal answer
Which data structure does BFS use to keep track of nodes to visit?
APriority Queue
BStack
CQueue
DHash Map
What is the first step in BFS traversal starting from a node?
AAdd all neighbors to the queue
BAdd the starting node to the queue and mark it visited
CMark all nodes as visited
DRemove the starting node from the graph
What happens when BFS visits a node's neighbor that is already visited?
AIt restarts the BFS
BIt adds it to the queue again
CIt removes the neighbor from the graph
DIt skips adding it to the queue again
Which of these is a correct BFS traversal order for a graph starting at node 1 with neighbors 2 and 3?
A1 -> 2 -> 3
B1 -> 3 -> 2
C2 -> 3 -> 1
D3 -> 2 -> 1
What is the space complexity of BFS in terms of vertices V?
AO(V)
BO(1)
CO(V^2)
DO(log V)
Explain how BFS works step-by-step on a graph starting from a given node.
Think about how you explore friends in layers, starting from one person.
You got /4 concepts.
    Describe why BFS is useful and what kind of problems it can solve.
    Consider situations where you want to find the closest or all nodes reachable from a start.
    You got /3 concepts.