Graph Data Structure Performance Analysis

Interactive benchmarking suite comparing Adjacency Matrix, Adjacency List, Combined, Object-Oriented, and advanced graph representations

Estimated Operations: 476,000
Adjacency Matrix (AM)

Compact bitset representation using Uint32Array. Each edge stored as a single bit.

SPACE
O(V²)
LOOKUP
O(1)
TRAVERSAL
O(V)

Advantages

  • Constant-time edge queries
  • Cache-friendly for dense graphs
  • Memory-efficient bit packing

Limitations

  • Quadratic memory usage
  • Slow vertex traversal
  • Poor for sparse graphs
const bits = new Uint32Array(Math.ceil((n * n) / 32));
const hasEdge = (u, v) => {
  const idx = u * n + v;
  return (bits[idx >>> 5] >>> (idx & 31)) & 1;
};
Adjacency List (AL)

Array of neighbor lists with Set-based fast lookups. Optimal for sparse graphs.

SPACE
O(V + E)
LOOKUP
O(1) avg
TRAVERSAL
O(degree)

Advantages

  • Linear memory usage
  • Fast neighbor iteration
  • Scales with edges

Limitations

  • Hash set overhead
  • Variable lookup time
  • Memory fragmentation
const adjList = Array(n).fill(null).map(() => []);
const adjSets = adjList.map(list => new Set(list));
const hasEdge = (u, v) => adjSets[u].has(v);
Combined (AM+AL)

Hybrid approach maintaining both representations for optimal access patterns.

SPACE
O(V² + E)
LOOKUP
O(1)
TRAVERSAL
O(degree)

Advantages

  • Best of both worlds
  • Flexible queries
  • Optimized operations

Limitations

  • Highest memory usage
  • Update complexity
  • Implementation overhead
const matrix = new AdjacencyMatrix(n);
const list = new AdjacencyList(n);
// Maintain both structures
const addEdge = (u, v) => {
  matrix.addEdge(u, v);
  list.addEdge(u, v);
};
Object-Oriented (OOP)

Node and Link objects with method-based interface. Similar to LiteGraph architecture.

SPACE
O(V + E)
LOOKUP
O(degree)
TRAVERSAL
O(degree)

Advantages

  • Intuitive API
  • Extensible design
  • Rich metadata support

Limitations

  • Method call overhead
  • Object allocation cost
  • Memory fragmentation
class Node {
  constructor(id) {
    this.id = id;
    this.outputs = [];
    this.inputs = [];
  }
}
const hasEdge = (u, v) => 
  nodes[u].outputs.some(link => link.to === v);

Current Configuration

Node Counts
10, 50, 200
Lookup Samples
5,000
Traversal Reps
200
Average Out-Degree
8

Data Structures

AM: Adjacency Matrix
AL: Adjacency List
AM+AL: Combined
OOP: Object-Oriented

Performance Insights

Dense vs Sparse

Use AM for dense graphs (>50% edges), AL for sparse graphs (<10% edges)

Lookup Speed

AM provides O(1) lookups but AL with Sets achieves similar performance

Scalability

AL scales linearly with edges, AM scales quadratically with vertices

Real-world Usage

Social networks: AL, Road networks: AM, Game engines: OOP

💡 Pro Tip

Start with small node counts (10-100) to understand performance patterns, then scale up based on your specific use case.

Complexity Reference

Space Complexity
AM:O(V²)
AL:O(V + E)
AM+AL:O(V² + E)
OOP:O(V + E + overhead)
Edge Lookup
AM:O(1)
AL:O(1) avg
AM+AL:O(1)
OOP:O(degree)
Add Edge
AM:O(1)
AL:O(1) avg
AM+AL:O(1)
OOP:O(1)
Get Neighbors
AM:O(V)
AL:O(degree)
AM+AL:O(degree)
OOP:O(degree)
Remove Vertex
AM:O(V²)
AL:O(V + E)
AM+AL:O(V²)
OOP:O(V + E)

V = number of vertices, E = number of edges, degree = avg edges per vertex