Visualizer is loading, please wait...

Graph Representations (Live Adjacency Matrix & List)

|V|=6, |E|=9Density: 0.30 (Sparse)
Adjacency Matrix (|V| x |V| Table, Space O(V²))Directed (Row -> Col)
u \ vABCDEF
A042000
B001500
C0008100
D000026
E000003
F000000
Adjacency List (Linked Chains, Space O(V + E))Optimal for Sparse Graphs
A
→
B(w:4)
C(w:2)
B
→
C(w:1)
D(w:5)
C
→
D(w:8)
E(w:10)
D
→
E(w:2)
F(w:6)
E
→
F(w:3)
F
→
[no outgoing edges]

Overview & Concept

The Graph List & Matrix Workbench visualizes the two primary representations of graph data structures: Adjacency Lists and Adjacency Matrices, alongside live pathfinding algorithms (BFS, DFS, Dijkstra).

How It Works

Adjacency List: Memory-efficient linked list or dynamic array for each vertex storing its outgoing neighbors (O(V + E) space).

Adjacency Matrix: V × V 2D matrix storing edge existence and weights, allowing O(1) edge lookups (O(V²) space).

Interactive 2D Canvas: Drag-and-drop node positioning with live edge weight manipulation.

Live Execution: Stepping through BFS, DFS, and Dijkstra shortest path finding with animated node discovery and edge relaxation.

Step-by-Step Execution

1. Node & Edge CreationAdd vertices and connect them with directed or undirected weighted edges.
2. Matrix & List SynchronizationInspect how the adjacency matrix cells and adjacency list pointers reflect edge additions.
3. Traversal ExecutionExecute BFS (queue-based), DFS (stack-based), or Dijkstra (priority queue shortest path).
4. Path HighlightingObserve the final shortest path tree highlighted in primary emerald.

Asymptotic Complexity Analysis

MetricBest CaseAverage CaseWorst CaseSpace Complexity
Complexity BoundO(V + E) BFS/DFSO((V + E) log V) DijkstraO(V²) dense matrixO(V + E) list / O(V²) matrix
ExplanationOptimal input arrangement minimizing operations.Expected time for uniformly distributed randomized inputs.Adversarial degenerate conditions requiring full traversal.Auxiliary memory allocated beyond original input size.

Pseudocode & Invariants

Algorithm Logic
// Dijkstra Shortest Path Algorithm
operation dijkstra(graph, source):
  dist[source] = 0
  pq.push({node: source, dist: 0})
  while not pq.isEmpty():
    {u, d} = pq.pop()
    if d > dist[u]: continue
    for {v, weight} in graph.adj[u]:
      if dist[u] + weight < dist[v]:
        dist[v] = dist[u] + weight
        parent[v] = u
        pq.push({node: v, dist: dist[v]})
Algorithmic Invariants
  • Matrix Symmetry: In undirected graphs, the adjacency matrix is strictly symmetric: M[i][j] == M[j][i].
  • Adjacency Sum: In adjacency lists, total entries across all lists equals 2|E| (undirected) or |E| (directed).
Correctness Guarantee: Invariants hold true prior to loop entry, are preserved during every iteration, and guarantee correct post-condition upon termination.

Advantages & Disadvantages

Key Advantages

  • •Dual representation demonstrates spatial trade-offs between sparse lists and dense matrices.
  • •Interactive visual workbench makes abstract graph algorithms concrete and intuitive.

Trade-offs & Limitations

  • •Dense matrix visualization becomes crowded beyond 20 vertices.

Real-World Applications

Road Network Routing

GPS road network navigation and transit planning.

Network Flow & Capacity

Telecommunication bandwidth routing and network capacity analysis.

Decision Guide: When to Use

Ideal Scenarios

  • ✓When studying or comparing graph representations and pathfinding algorithms.

Consider Alternatives When

  • ✕When simple linear arrays suffice for non-relational data.

Compare trade-offs and complexity across complementary tools in AlgoViz.