Menu
- 3.Write a Program to Implement Tic-Tac-Toe game using Python.
- 4.Write a Program to Implement 8-Puzzle problem using Python.
- 5.Write a Program to Implement Water-Jug problem using Python.
- 6.Write a Program to Implement Travelling Salesman Problem using Python.
- 7.Write a Program to Implement Tower of Hanoi using Python
- 8.Write a Program to Implement Monkey Banana Problem using Python.
- 9.Write a Program to Implement Alpha-Beta Pruning using Python.
- 10.Write a Program to Implement 8-Queens Problem using Python.
Aim: Write a Program to Implement Depth First Search using Python
Program:
# Using a Python dictionary to act as an adjacency list
graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [],
'E': ['F'],
'F': []
}
visited = set()
def dfs(visited, graph, node):
if node not in visited:
print(node)
visited.add(node)
for neighbour in graph[node]:
dfs(visited, graph, neighbour)
# Driver Code
dfs(visited, graph, 'A')
Output:
A
B
D
E
F
C