Skip to content

Commit c4c0e08

Browse files
authored
Update and rename Dfs (Directed Graph).cpp to DFS.cpp
1 parent d419dfa commit c4c0e08

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

DFS.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Depth First Search is a technique to traverse a tree or a graph.
3+
4+
*/
5+
6+
/* DFS of a Directed tree/graph */
7+
const int M = 1e6+6;
8+
9+
vector<int> G[M];
10+
vector<bool> vis(M);
11+
12+
void dfs(int u)
13+
{
14+
vis[u] = true;
15+
cout << u << endl;
16+
for(int child : G[u])
17+
{
18+
if(!vis[child])
19+
dfs(child);
20+
}
21+
}
22+
23+
/* DFS of a Undirected tree/graph */
24+
void dfs(int u, int par)
25+
{
26+
cout << u << endl;
27+
for(int child : G[u])
28+
{
29+
if(child != par)
30+
dfs(child);
31+
}
32+
}
33+

Dfs (Directed Graph).cpp

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)