0% found this document useful (0 votes)
48 views1 page

Program Experiment No 3

This document contains code for performing a breadth-first search (BFS) on a graph data structure, it defines a graph as a dictionary with nodes as keys and their neighbors as values, initializes visited and queue lists, and uses a BFS algorithm to traverse the graph starting from node A by appending each discovered neighbor to the queue.

Uploaded by

OMKAR PAREKH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views1 page

Program Experiment No 3

This document contains code for performing a breadth-first search (BFS) on a graph data structure, it defines a graph as a dictionary with nodes as keys and their neighbors as values, initializes visited and queue lists, and uses a BFS algorithm to traverse the graph starting from node A by appending each discovered neighbor to the queue.

Uploaded by

OMKAR PAREKH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

graph = {

"A":["B","C"],
"B":["D","E"],
"C":["F"],
"D":[],
"E":[],
"F":[]
}
visited = [] # List to keep track of visited nodes.
queue = [] #Initialise a queue
def bfs(visited, graph, node):
[Link](node)
[Link](node)
while queue:
s = [Link](0)
print (s, end = "")
for neighbour in graph[s]:
if neighbour not in visited:
[Link](neighbour)
[Link](neighbour)
# Driver Code
bfs(visited, graph,"A")

You might also like