Graphs

The following table shows the complexities of graphs:

Node/ Edge Management Storage Size Add Vertex Add Edge Remove Vertex Remove Edge Query
Adjacency list O (|V| + |E|) O(1) O(1) O (|V| + |E|) O(|E|) O(|V|)
Adjacency matrix O(|V|2) O(|V|2) O(1) O(|V|2) O(1) O(1)

Get Learning JavaScript Data Structures and Algorithms - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.