DFS

DFS uses Stack.

There are 3 color stages in every vertex: White (not visited yet), Grey (already visited, not printed yet), and Black (already printed).

Vertex v
While (semua v belum hitam)
    v = paling atas di stack S
    print v
    cek tetangga v
    If (tetangga = putih)
        u = tetangga warna putih
        Input u ke S
        u = jadi warna abu
        jadikan u sebagai anak (child) dari v di DFS-Tree T
    else
        pop v from S
        v = jadi warna hitam

Time Complexity: O(V+E) where V is number of vertices in the graph and E is number of edges in the graph.

results matching ""

    No results matching ""