Skip to content

Commit 91ca6b1

Browse files
committed
Updated node or point to vertex.
1 parent 641254f commit 91ca6b1

7 files changed

+166
-166
lines changed

solutions/1-1000/127-word-ladder.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The **word transformation sequence** problem can be abstracted into a **graph th
4545
### Breadth-First Search
4646
![](../../images/binary_tree_BFS_1.gif)
4747

48-
* As shown in the figure above, **breadth-first search** can be thought of as visiting nodes in rounds and rounds. Actually, whenever you see a question is about
48+
* As shown in the figure above, **breadth-first search** can be thought of as visiting vertices in rounds and rounds. Actually, whenever you see a question is about
4949
getting `shortest` or `least` of something of a graph, `breadth-first search` would probably help.
5050

5151
* `breadth-first search` emphasizes first-in-first-out, so a **queue** is needed.

solutions/1-1000/200-number-of-islands-2.md

+81-81
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ And this graph may have multiple **connected components** (islands):
4545

4646
Finding the number of islands is to find the number of `connected components`.
4747

48-
Walk from one node to the adjacent node until all nodes on the island are visited.
48+
Walk from one vertex (land) to the adjacent vertices until all vertices on the island are visited.
4949

5050
## Steps
5151
1. Find the first land.
@@ -68,12 +68,12 @@ The benefit of using iteration is better program performance. After all, recursi
6868

6969
Maintaining a stack by yourself can accomplish the same function as recursive calls.
7070

71-
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, left`.
71+
From this sample code bellow, you can see that starting from a vertex, 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, left`.
7272
```java
73-
pointStack.push({i, j - 1}); // left
74-
pointStack.push({i + 1, j}); // down
75-
pointStack.push({i, j + 1}); // right
76-
pointStack.push({i - 1, j}); // up
73+
vertexStack.push({i, j - 1}); // left
74+
vertexStack.push({i + 1, j}); // down
75+
vertexStack.push({i, j + 1}); // right
76+
vertexStack.push({i - 1, j}); // up
7777
```
7878

7979
## Solution 3: Breadth-First Search
@@ -88,7 +88,7 @@ Please click [Breadth-First Search Solution](200-number-of-islands-3.md) for `20
8888
class Solution:
8989
def __init__(self):
9090
self.grid = None
91-
self.point_stack = []
91+
self.vertex_stack = []
9292

9393
def numIslands(self, grid: List[List[str]]) -> int:
9494
island_count = 0
@@ -103,11 +103,11 @@ class Solution:
103103

104104
return island_count
105105

106-
def depth_first_search(self, point):
107-
self.point_stack.append(point)
106+
def depth_first_search(self, vertex):
107+
self.vertex_stack.append(vertex)
108108

109-
while self.point_stack:
110-
i, j = self.point_stack.pop()
109+
while self.vertex_stack:
110+
i, j = self.vertex_stack.pop()
111111

112112
if i < 0 or i >= len(self.grid):
113113
continue
@@ -120,16 +120,16 @@ class Solution:
120120

121121
self.grid[i][j] = 'V'
122122

123-
self.point_stack.append((i, j - 1))
124-
self.point_stack.append((i + 1, j))
125-
self.point_stack.append((i, j + 1))
126-
self.point_stack.append((i - 1, j))
123+
self.vertex_stack.append((i, j - 1))
124+
self.vertex_stack.append((i + 1, j))
125+
self.vertex_stack.append((i, j + 1))
126+
self.vertex_stack.append((i - 1, j))
127127
```
128128

129129
# Java
130130
```java
131131
class Solution {
132-
Stack<int[]> pointStack = new Stack<>();
132+
Stack<int[]> vertexStack = new Stack<>();
133133
char[][] grid;
134134

135135
public int numIslands(char[][] grid) {
@@ -149,13 +149,13 @@ class Solution {
149149
return islandCount;
150150
}
151151

152-
void depthFirstSearch(int[] point) {
153-
pointStack.push(point);
152+
void depthFirstSearch(int[] vertex) {
153+
vertexStack.push(vertex);
154154

155-
while (!pointStack.empty()) {
156-
point = pointStack.pop();
157-
int i = point[0];
158-
int j = point[1];
155+
while (!vertexStack.empty()) {
156+
vertex = vertexStack.pop();
157+
int i = vertex[0];
158+
int j = vertex[1];
159159

160160
if (i < 0 || i >= grid.length) {
161161
continue;
@@ -171,10 +171,10 @@ class Solution {
171171

172172
grid[i][j] = 'V';
173173

174-
pointStack.push(new int[]{i, j - 1});
175-
pointStack.push(new int[]{i + 1, j});
176-
pointStack.push(new int[]{i, j + 1});
177-
pointStack.push(new int[]{i - 1, j});
174+
vertexStack.push(new int[]{i, j - 1});
175+
vertexStack.push(new int[]{i + 1, j});
176+
vertexStack.push(new int[]{i, j + 1});
177+
vertexStack.push(new int[]{i - 1, j});
178178
}
179179
}
180180
}
@@ -185,17 +185,17 @@ class Solution {
185185
class Solution {
186186
private:
187187
vector<vector<char>> grid_;
188-
stack<pair<int, int>> point_stack;
188+
stack<pair<int, int>> vertex_stack;
189189

190190
void depth_first_search(int i1, int j1) {
191-
point_stack.push({i1, j1});
191+
vertex_stack.push({i1, j1});
192192

193-
while (!point_stack.empty()) {
194-
pair<int, int> point = point_stack.top();
195-
point_stack.pop();
193+
while (!vertex_stack.empty()) {
194+
pair<int, int> vertex = vertex_stack.top();
195+
vertex_stack.pop();
196196

197-
int i = point.first;
198-
int j = point.second;
197+
int i = vertex.first;
198+
int j = vertex.second;
199199

200200
if (i < 0 || i >= grid_.size()) {
201201
continue;
@@ -211,10 +211,10 @@ private:
211211

212212
grid_[i][j] = 'V';
213213

214-
point_stack.push({i, j - 1});
215-
point_stack.push({i + 1, j});
216-
point_stack.push({i, j + 1});
217-
point_stack.push({i - 1, j});
214+
vertex_stack.push({i, j - 1});
215+
vertex_stack.push({i + 1, j});
216+
vertex_stack.push({i, j + 1});
217+
vertex_stack.push({i - 1, j});
218218
}
219219
}
220220

@@ -241,11 +241,11 @@ public:
241241
# JavaScript
242242
```JavaScript
243243
let grid
244-
let pointStack
244+
let vertexStack
245245

246246
var numIslands = function (grid_) {
247247
grid = grid_
248-
pointStack = []
248+
vertexStack = []
249249
let islandCount = 0
250250

251251
grid.forEach((row, i) => {
@@ -261,11 +261,11 @@ var numIslands = function (grid_) {
261261
return islandCount
262262
};
263263

264-
function depthFirstSearch(point) {
265-
pointStack.push(point)
264+
function depthFirstSearch(vertex) {
265+
vertexStack.push(vertex)
266266

267-
while (pointStack.length > 0) {
268-
const [i, j] = pointStack.pop()
267+
while (vertexStack.length > 0) {
268+
const [i, j] = vertexStack.pop()
269269

270270
if (i < 0 || i >= grid.length) {
271271
continue
@@ -281,10 +281,10 @@ function depthFirstSearch(point) {
281281

282282
grid[i][j] = 'V';
283283

284-
pointStack.push([i, j - 1])
285-
pointStack.push([i + 1, j])
286-
pointStack.push([i, j + 1])
287-
pointStack.push([i - 1, j])
284+
vertexStack.push([i, j - 1])
285+
vertexStack.push([i + 1, j])
286+
vertexStack.push([i, j + 1])
287+
vertexStack.push([i - 1, j])
288288
}
289289
}
290290
```
@@ -293,7 +293,7 @@ function depthFirstSearch(point) {
293293
```c#
294294
public class Solution
295295
{
296-
Stack<int[]> pointStack = new Stack<int[]>();
296+
Stack<int[]> vertexStack = new Stack<int[]>();
297297
char[][] grid;
298298

299299
public int NumIslands(char[][] grid)
@@ -317,15 +317,15 @@ public class Solution
317317
return islandCount;
318318
}
319319

320-
void depthFirstSearch(int[] point)
320+
void depthFirstSearch(int[] vertex)
321321
{
322-
pointStack.Push(point);
322+
vertexStack.Push(vertex);
323323

324-
while (pointStack.Count > 0)
324+
while (vertexStack.Count > 0)
325325
{
326-
point = pointStack.Pop();
327-
int i = point[0];
328-
int j = point[1];
326+
vertex = vertexStack.Pop();
327+
int i = vertex[0];
328+
int j = vertex[1];
329329

330330
if (i < 0 || i >= grid.Length)
331331
{
@@ -342,10 +342,10 @@ public class Solution
342342

343343
grid[i][j] = 'V';
344344

345-
pointStack.Push([i, j - 1]);
346-
pointStack.Push([i + 1, j]);
347-
pointStack.Push([i, j + 1]);
348-
pointStack.Push([i - 1, j]);
345+
vertexStack.Push([i, j - 1]);
346+
vertexStack.Push([i + 1, j]);
347+
vertexStack.Push([i, j + 1]);
348+
vertexStack.Push([i - 1, j]);
349349
}
350350
}
351351
}
@@ -354,11 +354,11 @@ public class Solution
354354
# Go
355355
```go
356356
var grid [][]byte
357-
var pointStack = arraystack.New()
357+
var vertexStack = arraystack.New()
358358

359359
func numIslands(grid_ [][]byte) int {
360360
grid = grid_
361-
pointStack.Clear()
361+
vertexStack.Clear()
362362
islandCount := 0
363363

364364
for i, row := range grid {
@@ -374,14 +374,14 @@ func numIslands(grid_ [][]byte) int {
374374
return islandCount
375375
}
376376

377-
func depthFirstSearch(point []int) {
378-
pointStack.Push(point)
377+
func depthFirstSearch(vertex []int) {
378+
vertexStack.Push(vertex)
379379

380-
for !pointStack.Empty() {
381-
point, _ := pointStack.Pop();
380+
for !vertexStack.Empty() {
381+
vertex, _ := vertexStack.Pop();
382382

383-
i := point.([]int)[0]
384-
j := point.([]int)[1]
383+
i := vertex.([]int)[0]
384+
j := vertex.([]int)[1]
385385

386386
if i < 0 || i >= len(grid) {
387387
continue
@@ -397,10 +397,10 @@ func depthFirstSearch(point []int) {
397397

398398
grid[i][j] = 'V'
399399

400-
pointStack.Push([]int{i, j - 1})
401-
pointStack.Push([]int{i + 1, j})
402-
pointStack.Push([]int{i, j + 1})
403-
pointStack.Push([]int{i - 1, j})
400+
vertexStack.Push([]int{i, j - 1})
401+
vertexStack.Push([]int{i + 1, j})
402+
vertexStack.Push([]int{i, j + 1})
403+
vertexStack.Push([]int{i - 1, j})
404404
}
405405
}
406406
```
@@ -409,7 +409,7 @@ func depthFirstSearch(point []int) {
409409
```ruby
410410
def num_islands(grid)
411411
@grid = grid
412-
@point_stack = []
412+
@vertex_stack = []
413413
island_count = 0
414414

415415
@grid.each_with_index do |row, i|
@@ -425,14 +425,14 @@ def num_islands(grid)
425425
island_count
426426
end
427427

428-
def depth_first_search(point)
429-
@point_stack << point
428+
def depth_first_search(vertex)
429+
@vertex_stack << vertex
430430

431-
while !@point_stack.empty?
432-
point = @point_stack.pop
431+
while !@vertex_stack.empty?
432+
vertex = @vertex_stack.pop
433433

434-
i = point[0]
435-
j = point[1]
434+
i = vertex[0]
435+
j = vertex[1]
436436

437437
next if i < 0 || i >= @grid.size
438438

@@ -442,10 +442,10 @@ def depth_first_search(point)
442442

443443
@grid[i][j] = 'V'
444444

445-
@point_stack << [i, j - 1]
446-
@point_stack << [i + 1, j]
447-
@point_stack << [i, j + 1]
448-
@point_stack << [i - 1, j]
445+
@vertex_stack << [i, j - 1]
446+
@vertex_stack << [i + 1, j]
447+
@vertex_stack << [i, j + 1]
448+
@vertex_stack << [i - 1, j]
449449
end
450450
end
451451
```

0 commit comments

Comments
 (0)