...

/

How to Represent Graphs as Data Structures

How to Represent Graphs as Data Structures

Learn how graphs are stored and read on computers.

Graph data storage uses particular formats on a computer (or any machine). Let's see what some of these are.

Adjacency matrix

We can store graphs as adjacency matrices. These matrices are a neat way to represent graphs as a square matrix in which we denote the presence of an edge by 11 and the absence of one by 00.

Press + to interact
Undirected graph
Undirected graph

Here's an adjacency matrix of an undirected graph:

[ABCDA0101B1011C0100D1100]\begin{bmatrix} &A & B & C & D \\ A&0&1&0&1\\ B&1&0&1&1\\ C&0&1&0&0\\ D&1&1&0&0\\ \end{bmatrix} ...