BFS · Nhóm: Đồ thị
Duyệt theo chiều rộng (BFS), nhóm Đồ thị.
def bfs(graph, start):
visited = {start}
queue = [start]
while queue:
node = queue.pop(0)
for nb in graph[node]:
if nb not in visited:
visited.add(nb)
queue.append(nb)
Mở trang để xem mô phỏng từng bước và xuất slide bài giảng.