Home | Projects | Notes > Data Structures & Algorithms > Graphs

Graphs

 

Different Representations of Graphs

Graphs using Adjacency Matrix

 

undirected-graph-using-adjacency-matrix

 

Graphs using Adjacency List

 

undirected-graph-using-adjacency-list

 

 

Graphs Big-O

Time Complexity

 Adjacency MatrxAdjacency List
Add vertexO(|V|2); Have to completely rebuild the 2D matrixO(1)
Add edgeO(1)O(1)
Remove vertexO(|V|2); Have to completely rebuild the 2D matrixO(|V|); Have to check every vertex
Remove edgeO(1)O(1)

Space Complexity

Adjacency MatrxAdjacency List
O(|V|2)O(|V| + |E|)

 

Graph using Adjacency List (C++)

Interface

Implementation

Test Driver