0
0
DSA Cprogramming~5 mins

Number of Islands BFS and DFS in DSA C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main goal of the Number of Islands problem?
To count how many separate groups of connected '1's (land) exist in a 2D grid of '1's and '0's (land and water).
Click to reveal answer
intermediate
How does Depth-First Search (DFS) help solve the Number of Islands problem?
DFS explores all connected land cells from a starting point by going deep into neighbors recursively, marking visited cells to avoid counting the same island multiple times.
Click to reveal answer
intermediate
How does Breadth-First Search (BFS) differ from DFS in this problem?
BFS explores neighbors level by level using a queue, visiting all adjacent land cells before moving deeper, but both BFS and DFS mark visited cells to count islands correctly.
Click to reveal answer
beginner
What data structure is commonly used to keep track of cells to visit in BFS for Number of Islands?
A queue is used to store cells to visit next in BFS, ensuring neighbors are processed in the order they are discovered.
Click to reveal answer
beginner
Why do we mark cells as visited in Number of Islands algorithms?
Marking cells as visited prevents counting the same land cell multiple times and avoids infinite loops during traversal.
Click to reveal answer
In the Number of Islands problem, what does a '1' represent in the grid?
AVisited cell
BWater
CLand
DBoundary
Which traversal method uses a stack or recursion to explore deep into neighbors?
ADepth-First Search (DFS)
BBreadth-First Search (BFS)
CBinary Search
DLinear Search
What data structure does BFS use to keep track of nodes to visit next?
ATree
BStack
CSet
DQueue
Why do we mark cells as visited during traversal?
ATo avoid revisiting and infinite loops
BTo sort the grid
CTo change their value to water
DTo count them multiple times
Which of these is NOT a valid neighbor direction in Number of Islands problem?
AUp
BDiagonal
CDown
DLeft
Explain how DFS can be used to count the number of islands in a grid.
Think about exploring deep into connected land cells.
You got /4 concepts.
    Describe the steps BFS follows to find all cells of an island in the grid.
    Focus on level-by-level exploration using a queue.
    You got /5 concepts.