From 8127c132a2292fe9589f37af08233e3b1b88f1c7 Mon Sep 17 00:00:00 2001 From: Shelam-Mehta <39619452+Shelam-Mehta@users.noreply.github.com> Date: Fri, 25 Oct 2019 23:31:25 +0530 Subject: [PATCH 1/2] DFS using python --- Graph/DFS | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Graph/DFS diff --git a/Graph/DFS b/Graph/DFS new file mode 100644 index 0000000..26692f6 --- /dev/null +++ b/Graph/DFS @@ -0,0 +1,26 @@ +def DFS(graph,visited,element,n): + a=graph[element] + #adding current node to visited nodes list + visited+=[element] + print(element,end=" ") + for i in a: + #checking whether all nodes are visited + if(len(visited)==n): + return 0 + #checking if node is visited + if i not in visited: + + DFS(graph,visited,i,n) + + + +graph = {"a": ["c", "f"], + "b": ["c", "e"], + "c": ["a", "b", "d", "e"], + "d": ["c"], + "e": ["c", "b"], + "f": ["a"] + } +visited=[] +DFS(graph,visited,'a',6) + From f30b8f65ea1e0121aab92df5bbe843fb8d038b04 Mon Sep 17 00:00:00 2001 From: Shelam-Mehta <39619452+Shelam-Mehta@users.noreply.github.com> Date: Fri, 25 Oct 2019 23:34:36 +0530 Subject: [PATCH 2/2] DFS using python --- Graph/{DFS => DFS.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Graph/{DFS => DFS.py} (100%) diff --git a/Graph/DFS b/Graph/DFS.py similarity index 100% rename from Graph/DFS rename to Graph/DFS.py