Untitled

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

# Write a program for DFS algorithm using uninformed search method

visited = set()

def dfs(visited, graph, node):

if node not in visited:

print(node, end = " ")

visited.add(node)

for neighbour in graph[node]:

dfs(visited, graph, neighbour)

graph2 = {

'0' : ['1','9'],

'1' : ['2'],

'2' : ['0','3'],

'9' : ['3'],

'3' : ['3']

print("\nFollowing is the depth-first search for dfs graph 2:")

dfs(visited, graph2, '0')

##########################Output#######################

# Following is the depth-first search for dfs graph 2:

#01239

You might also like