Graph Data Structure Simulator
Create vertices and edges and watch the adjacency list and adjacency matrix update live, for directed or weighted graphs.
Edit the graph
Graph
Adjacency list
Each vertex lists its neighbours. Space-efficient for sparse graphs.
Adjacency matrix
Row → column. Cells hold the weight; 0 means none. Undirected graphs give a symmetric matrix.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| A | 0 | 4 | 0 | 7 | 0 |
| B | 4 | 0 | 2 | 0 | 5 |
| C | 0 | 2 | 0 | 0 | 0 |
| D | 7 | 0 | 0 | 0 | 3 |
| E | 0 | 5 | 0 | 3 | 0 |
Matrix uses V² = 25 cells. The list stores 10 entries.
About This Simulation
This graph data structure simulator lets you draw a graph by adding vertices and edges, then shows how it is stored as an adjacency list and as an adjacency matrix. Switch between directed and undirected, weighted and unweighted graphs and watch both representations update.
Features
- Add, move and delete vertices and edges on a canvas
- Directed or undirected, weighted or unweighted edges
- Adjacency list updated live, with degrees
- Adjacency matrix updated live
- Edge and vertex counts with the maximum possible edges
Topics covered
- Graphs
- Vertices and Edges
- Directed and Undirected Graphs
- Weighted Graphs
- Adjacency List
- Adjacency Matrix
Explanation
A graph is a set of vertices (nodes) connected by edges. Edges can be directed (one-way) or undirected (two-way), and can carry weights such as distances or costs. Graphs model networks such as roads, social connections, web links and computer networks.
How it works
- Adjacency matrix: a V × V grid where cell [i][j] holds 1 (or the weight) if there is an edge from vertex i to vertex j, and 0 otherwise.
- In an undirected graph the matrix is symmetric, because an edge A–B is also B–A.
- Adjacency list: each vertex keeps a list of its neighbours (and the edge weights).
- A matrix uses V² space but checks whether an edge exists in O(1); a list uses space proportional to V + E and is better for sparse graphs.
- The degree of a vertex is its number of edges; in a directed graph there is an in-degree and an out-degree.
Why it matters
Graphs are on the A Level syllabus and are central to CSE220 and CSE221. Graph algorithms such as BFS, DFS, Dijkstra, Prim and Kruskal all start from one of these two representations.
Frequently Asked Questions
When should I use an adjacency matrix instead of a list?
Use a matrix for dense graphs or when you need to check quickly whether two vertices are connected. Use a list for sparse graphs, where it saves a lot of memory.
What is a weighted graph?
A graph where each edge has a value, such as a distance, time or cost.
How many edges can a graph have?
An undirected simple graph with V vertices has at most V(V − 1)/2 edges; a directed graph has at most V(V − 1).
Related Simulations
Algorithms
BFS (Breadth First Search) Simulator
Build interactive graphs and watch BFS explore networks level-by-level using a visual queue.
Algorithms
DFS (Depth First Search) Simulator
Build interactive graphs and watch DFS plunge down deep paths and backtrack using a visual stack.
Algorithms
Dijkstra Simulator
Build interactive graphs and watch Dijkstra prioritize the lowest-cost paths to the target using a real-time priority queue.
Data Structures
B+ Tree
Insert, delete, search in a B+ tree visualiser

