AIML-Lab1
AIML-Lab1
1. BFS:
import collections
Graph_Nodes = {
'B': [('D', 3), ('E', 7), ('F', 1), ('A', 4), ('C', 1)],
'F': [('G', 1), ('E', 1), ('H', 1), ('D', 1), ('B', 1)],
while queue:
continue
return path
else:
visited.add(vertex) # Mark node as visited
return None
Graph_Nodes = {
'B': [('D', 3), ('E', 7), ('F', 1), ('A', 4), ('C', 1)],
'F': [('G', 1), ('E', 1), ('H', 1), ('D', 1), ('B', 1)],
while stack:
(vertex, path) = stack.pop() # Get the current node and path
continue
return path
return None
# Find path from 'C' to 'G'