Search⌘ K
AI Features

How to Represent Graphs as Data Structures

Explore different methods to represent graphs as data structures, including adjacency matrices, edge lists, and adjacency lists. Understand how these formats store graph relationships for undirected, directed, and weighted graphs. Gain foundational knowledge to manipulate graph data effectively in graph machine learning.

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.

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} ...