Algorithms and Data Structures · Junior · Question 57 of 75

How is a graph usually stored when it has many vertices but few edges?

Explanation

An adjacency list takes O(V + E) memory, while a matrix always takes O(V²), which is wasteful for sparse graphs. The matrix is handy when the graph is dense or you need an O(1) "is there an edge?" check.

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 57

Test yourself

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

Take this quiz