Graph

A data structure containing nodes and the collection of edges that connect the nodes.

Pros Cons
Allows for graph algorithms to be used Usually not built in to programming languages
Many different implementations with different pros and cons
Operation Graph (Adjacency list) Graph (Adjacency matrix)
Add edge O(1) O(1)
Add vertex O(1) O(|V|^2)
Are two vertexes adjacent? O(|V|) O(1)
Create graph O(|V|+|E|) O(|V|^2)
Remove edge O(|V|) O(1)
Remove vertex O(|E|) O(|V|^2)

Similar