Graph Representations There are two main ways of representing graphs in a computer: The adjacency matrix representation. The adjacency list representation.
Graph Representations The adjacency matrix representation: 1 if (v, w) E M(v, w) = 0 otherwise A B C D E F 0 1 0 1 0 0 A B C D E F B C 1 0 1 0 0 0 A 0 1 0 1 1 0 F 1 0 1 0 1 0 D E 0 0 1 1 0 0 0 0 0 0 0 0
Graph Representations The adjacency matrix representation: Space: |V| bits 2 1 if (v, w) E M(v, w) = 0 otherwise A B C D E F 0 1 0 1 0 0 A B C D E F B C 1 0 1 0 0 0 A 0 1 0 1 1 0 F 1 0 1 0 1 0 D E 0 0 1 1 0 0 0 0 0 0 0 0
Graph Representations The adjacency list representation: L(v) = list of w such that (v, w) E, for v V A B C D E F B D B C A C A B D E F A C E D E C D
Graph Representations The adjacency list representation: How much space: ? A B C D E F B D B C A C A B D E F A C E D E C D
Graph Representations The adjacency list representation: Space: a |V| + 2 b |E| a b A B C D E F B D B C A C A B D E F A C E D E C D
Graph Representations The adjacency matrix representation, again, this time representing a directed graph. A B C D E F 0 1 0 1 0 0 A B C D E F B C 0 0 1 0 0 0 A 0 0 0 0 1 0 F 0 0 1 0 0 0 D E 0 0 0 1 0 0 0 0 0 0 0 0
Graph Representations The adjacency list representation, again, this time representing a directed graph. A B C D E F B D B C C A E F C D E D
Graph Representations The adjacency list representation, again, this time representing a directed graph. How much space? A B C D E F B D B C C A E F C D E D
Graph Representations The adjacency list representation, again, this time representing a directed graph. Space: a |V| + b |E| a b A B C D E F B D B C C A E F C D E D