structural:reformatting
Common data structures for graph representation

The following table gives the time complexity cost of performing various operations on graphs, for each of these representations, with | V | the number of vertices and | E | the number of edges. In the matrix representations, the entries encode the cost of following an edge. The cost of edges that are not present are assumed to be ∞.

Adjacency lists are generally preferred for the representation of sparse graphs, while an adjacency matrix is preferred if the graph is dense; that is, the number of edges | E | {\displaystyle |E|} is close to the number of vertices squared, | V | 2 {\displaystyle |V|^{2}}, or if one must be able to quickly look up if there is an edge connecting two vertices.