AiSc 12

Pasted Nov 4, 2026, 3:50 PM1 file33 lines

Scan to open on your phone

Point a camera at the QR code - it opens this exact paste, no app needed.

https://codepastes.com/ai12
untitled
# 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