0
0
DSA Typescriptprogramming~5 mins

Number of Islands BFS and DFS in DSA Typescript - 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, marking them visited 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 connected land cells around the starting point before moving deeper.
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 order of discovery.
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?
AObstacle
BWater
CVisited cell
DLand
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?
AStack
BQueue
CSet
DTree
Why do we mark cells as visited during traversal?
ATo change their value to water
BTo count them multiple times
CTo avoid revisiting and infinite loops
DTo sort the grid
If a grid has no '1's, what is the number of islands?
A0
B1
CGrid size
DUndefined
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 difference between BFS and DFS when solving the Number of Islands problem.
    Focus on the order of visiting neighbors.
    You got /4 concepts.