Mô phỏng thuật toán Duyệt theo chiều sâu

DFS · Nhóm: Đồ thị

Duyệt theo chiều sâu (DFS), nhóm Đồ thị.

Mã Python

def dfs(adj, start):
    visited = set()
    order = []
    def visit(u):
        visited.add(u)
        order.append(u)
        for v in adj[u]:
            if v not in visited:
                visit(v)
    visit(start)
    return order

Mở trang để xem mô phỏng từng bước và xuất slide bài giảng.