Algorithms

Adjacency matrix

An n × n table for a graph of n vertices: cell (i, j) is 1 if there's an edge between i and j, and 0 if not. Checking an edge is O(1), but it takes O(n²).

Example

A 100-vertex graph takes 10,000 cells, even if it has only 150 edges.

Test yourself: Adjacency matrix

Graphs

An adjacency matrix for a graph with 100 vertices has ___ cells.

Lessons that use it

More algorithms terms

All terms →

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.