You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -252,7 +299,7 @@ public int dfs(TreeNode root) {
252
299
```
253
300
254
301
255
-
### 11) Binary tree:DFS (recursive)
302
+
### 13) Binary tree:DFS (iterative)
256
303
257
304
```java
258
305
publicint dfs(TreeNode root) {
@@ -276,7 +323,7 @@ public int dfs(TreeNode root) {
276
323
```
277
324
278
325
279
-
### 12) Binary tree:BFS
326
+
### 14) Binary tree:BFS (iterative)
280
327
281
328
```java
282
329
publicint fn(TreeNode root) {
@@ -305,9 +352,11 @@ public int fn(TreeNode root) {
305
352
```
306
353
307
354
308
-
### 13) Graph:DFS (recursive)
355
+
### 15) Graph:DFS (recursive)
356
+
357
+
For the graph templates, assume the nodes are numbered from 0 to n -1 and the graph is given as an adjacency list.
309
358
310
-
For the graph templates, assume the nodes are numbered from 0 to n -1 and the graph is given as an adjacency list. Depending on the problem, you may need to convert the input into an equivalent adjacency list before using the templates.
359
+
Depending on the problem, you may need to convert the input into an equivalent adjacency list before using the templates.
311
360
312
361
```java
313
362
Set<Integer> seen =newHashSet<>();
@@ -332,7 +381,7 @@ public int dfs(int node, int[][] graph) {
332
381
```
333
382
334
383
335
-
### 14) Graph: DFS (iterative)
384
+
### 16) Graph: DFS (iterative)
336
385
337
386
```java
338
387
publicintfn(int[][] graph) {
@@ -358,7 +407,7 @@ public int fn(int[][] graph) {
358
407
```
359
408
360
409
361
-
### 15) Graph:BFS
410
+
### 17) Graph: BFS (iterative)
362
411
363
412
```java
364
413
publicintfn(int[][] graph) {
@@ -384,53 +433,6 @@ public int fn(int[][] graph) {
0 commit comments