# Representing Graphs #### Adjacency Matrix Pros: * Space efficient for representing dense graphs * Edge weight lookup is $O(1)$ * Simplest graph representation Cons: * Requires $O(V^2)$ space (graphs with more than 10,000 nodes become infeasible quickly) * Iterating over all edges takes $O(V^2)$ time ![](Screen%20Shot%202021-04-05%20at%207.27.59%20AM.png) #### Adjacency List An **adjacency list** is a way to represent a graph as a map from nodes to lists of edges. Pros * Space efficient for sparse graphs * Efficient for iterating over all edges Cons: * less space efficient on dense graphs * Edge weight lookup is $O(E)$ (this rarely happens though) * Slightly more complex graph representation ![](Screen%20Shot%202021-04-05%20at%207.32.47%20AM.png) #### Edge List Pros: * Space efficient for representing sparse graphs * Iterating over all edges is efficient * Very simply structure Cons: * Less space efficient for denser graphs * Edge weight lookup is $O(E)$ ![](Screen%20Shot%202021-04-05%20at%207.34.37%20AM.png) --- Backlinks: [Graph-Theory](Graph-Theory.md)