What is the time complexity of DFS on an adjacency matrix?

What is the time complexity of DFS on an adjacency matrix?

Approach: Analyze the nested lookups for each vertex.

O(V^2). For each of the V vertices, the algorithm must scan across a row of length V to find its neighbors.

Follow-up: How does it compare to an adjacency list? (O(V+E))

Key concepts: O(V^2), matrix traversal.