Scan to open on your phone
Point a camera at the QR code - it opens this exact paste, no app needed.
https://codepastes.com/ai12untitledPlain Text
# Graph dictionary representation
graph = {
"A": ["B", "C"],
"B": ["D", "E"],
"C": ["F"],
"D": [],
"E": [],
"F": []
}
def bfs_traverse(start_node):
visited = []
queue = [start_node]
while queue:
node = queue.pop(0) # Dequeue first element (FIFO)
if node not in visited:
visited.append(node)
# Append all unvisited neighbors
queue.extend([
n for n in graph[node] if n not in visited
])
return visited
print(
"BFS Traversal Order starting from A:",
bfs_traverse("A")
)603 chars · codepastes.com