Algorithms and Data Structures · Middle · Question 60 of 75

What is the complexity of BFS or DFS on a graph stored as adjacency lists?

Explanation

Every vertex is processed once and every edge is looked at once (twice for undirected graphs). With an adjacency matrix the same traversal costs O(V²), because each row has V cells.

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 60

Test yourself

Take the Algorithms and Data Structures · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz