Algorithms and Data Structures · Senior · Question 72 of 75

What is the main reason to prefer an adjacency matrix over adjacency lists?

Explanation

Checking matrix[u][v] is instant, and for dense graphs the O(V²) memory isn't wasted. For sparse graphs lists win on memory and neighbor iteration.

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 72

Test yourself

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

Take this quiz