                               PRACTICAL NO:1
                          DEPTH FIRST SEARCH
GRAPH
CODE:-
graph= {
   'A':['B','C'],
   'B':['A','D','E'],
   'C':['A','F'],
   'D':['B'],
   'E':['B','F'],
   'F':['C','E']
    }
print("Graph representation:\n")
for node in graph:
    print(node,"->",graph[node])
OUTPUT:-
Write a program to implement depth first search algorithm.
GRAPH:
CODE:
graph={
 1:[2],
 2:[3,6,1,8],
 3:[7,4,6,2],
 4:[3,6],
 5:[6],
 6:[4,5,2,3],
 7:[3],
 8:[2]
}
def dfs(graph,node,visited):
    if node not in visited:
        visited.append(node)
        for n in graph[node]:
            dfs(graph,n,visited)
    return visited
visited=dfs(graph,2,[])
print("visited:-")
print(visited)
OUTPUT: