Graph Algorithms

Your answer
Answer & solution
Official answer: C
1. Method and setup. For adjacency lists, examining neighbors costs the degree of the current vertex. With a matrix, locating all neighbors requires inspecting n possible entries even for a low-degree vertex. A full DFS forest covers disconnected components too, so all n rows are scanned.
2. Work through the result and its assumptions. DFS scans an entire adjacency-matrix row for each visited vertex. A full traversal visits all n vertices, giving n rows of n entries and Θ(n²) time, C.