Cho đồ thị như hình vẽ. Kết quả khi duyệt đồ thị theo thuật toán DFS(I) là:
Trả lời:
Đáp án đúng: D
DFS (Depth-First Search) starts at vertex I. It explores as far as possible along each branch before backtracking. The algorithm visits the children of a node before visiting its siblings. Assume alphabetical order when multiple choices exist.
1. Start at I.
2. Neighbors of I: C, G. Choose C.
3. Neighbors of C: A, B, E, I. Choose A.
4. Neighbors of A: B, C, D, I. Choose B.
5. Neighbors of B: A, C, G. Choose G.
6. Neighbors of G: B, F, H, I, K. Choose F.
7. Neighbors of F: B, D, E, G. Choose D.
8. Neighbors of D: A, B, F, H. Choose H.
9. Neighbors of H: D, G, N. Choose N.
10. Neighbors of N: H, K. Choose K.
So the traversal order is I, C, A, B, G, F, D, H, N, K.