Skip to content

Commit e9ea25d

Browse files
committed
0200-number-of-islands.md Added a DFS image.
1 parent 8ea814d commit e9ea25d

4 files changed

Lines changed: 8 additions & 4 deletions

File tree

images/binary_tree_BFS_1.gif

32.5 KB
Loading

images/binary_tree_DFS_1.png

72.1 KB
Loading

problems/0200-number-of-islands-2.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,19 @@ Walk from one node to the adjacent node until all nodes on the island are visite
4949

5050
## Steps
5151
1. Find the first land.
52-
1. Find all the adjacent lands of it.
52+
1. Starting at the first land, find all the lands of the island.
5353
* There are two major ways to explore a `connected components` (island): **Breadth-First Search** and **Depth-First Search**.
5454
* For **Depth-First Search**, there are two ways to make it: `Recursive` and `Iterative`. So I will provide 3 solutions in total.
5555
* Mark each found land as `V` which represents `visited`. Visited lands don't need to be visited again.
5656
1. After all lands on an island have been visited, look for the next non-visited land.
57-
1. Repeat the above steps until all the lands have been `visited`.
57+
1. Repeat the above two steps until all the lands have been `visited`.
5858

5959
### Solution 1: 'Depth-First Search' by Recursion
6060
Please click [Depth-First Search by Recursion Solution](0200-number-of-islands.md) for `200. Number of Islands` to view.
6161

6262
## Solution 2: 'Depth-First Search' by Iteration
63+
![](../images/binary_tree_DFS_1.png)
64+
6365
In solution 1, we have known how to traverse a graph by recursion. Computer language support for recursive calls is implemented through stacks.
6466
For every recursive solution, there is an iterative solution, which means the same problem can be solved using loops.
6567
The benefit of using iteration is better program performance. After all, recursive calls are expensive.

problems/0200-number-of-islands.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ Walk from one node to the adjacent node until all nodes on the island are visite
4949

5050
## Steps
5151
1. Find the first land.
52-
1. Find all the adjacent lands of it.
52+
1. Starting at the first land, find all the lands of the island.
5353
* There are two major ways to explore a `connected components` (island): **Breadth-First Search** and **Depth-First Search**.
5454
* For **Depth-First Search**, there are two ways to make it: `Recursive` and `Iterative`. So I will provide 3 solutions in total.
5555
* Mark each found land as `V` which represents `visited`. Visited lands don't need to be visited again.
5656
1. After all lands on an island have been visited, look for the next non-visited land.
57-
1. Repeat the above steps until all the lands have been `visited`.
57+
1. Repeat the above two steps until all the lands have been `visited`.
5858

5959
## Solution 1: 'Depth-First Search' by Recursion
60+
![](../images/binary_tree_DFS_1.png)
61+
6062
From this sample code bellow, you can see that starting from a node, through recursive calls, it goes up until it can't go any further, turns right, and continues up. The priority order of directions is `up, right, down, and left`.
6163
```python
6264
adjacent_points = [

0 commit comments

Comments
 (0)