Professional Documents
Culture Documents
WEEK – 12
PROGRAM:
graph = {}
n = int(input("Enter number of Nodes: "))
for i in range(n):
key = input("Enter the parent Node: ")
value = list(map(str,input("Enter the child Nodes").split()))
graph[key] = value
# Driver Code
OUTPUT:
Enter number of Nodes: 7
Enter the parent Node: 5
Enter the child Nodes3 7
Enter the parent Node: 3
Enter the child Nodes2 4
Enter the parent Node: 7
Enter the child Nodes8
Enter the parent Node: 2
Enter the child Nodes
Enter the parent Node: 4
Enter the child Nodes9
Enter the parent Node: 8
Enter the child Nodes
Enter the parent Node: 9
Enter the child Nodes
Following is the Depth-First Search
5 3 2 4 9 7 8