📚 College Credit Guide ✓ UPI Study 🕐 7 min read

What Are Adjacency Matrix and List Representations?

This article explains adjacency matrix and adjacency list graph storage, then compares space, speed, and the best times to use each one.

US
UPI Study Team Member
📅 October 18, 2026
📖 7 min read
US
About the Author
The UPI Study team works directly with students on credit transfer, degree planning, and course selection. We've helped thousands of students figure out what counts toward their degree and how to finish faster without paying more than they have to. This post is written the way we'd explain it to you directly.
🦉

Adjacency matrix and list representations are two common ways to store a graph in discrete mathematics and computer science. A matrix uses a grid of rows and columns, while a list stores the neighbors for each vertex. Both can show edges, and both can store weights like 7 or 12, but they do it in very different ways. That difference matters fast in a discrete mathematics course or a data structures assignment. A graph with 5 vertices and 4 edges can fit in either form, but the storage choice changes memory use, lookup speed, and how easy it feels to write code. If you are checking whether edge A→B exists, a matrix gives you a direct spot to inspect. If you are walking through all neighbors of vertex 3, a list usually feels cleaner. Students often miss the real point. These structures do not just “hold a graph.” They shape the cost of every later step, from printing an edge list to running BFS or Dijkstra's algorithm. That is why professors care about them in week 2 or week 3, not near the end of the term. A sloppy choice can make a small homework graph feel bigger than it is, and a good choice can make a 100-vertex problem much easier to handle.

Discrete Mathematics
College credit · ACE & NCCRS reviewed · self-paced
View course
Man in glasses focusing on math problems, struggling with complex equations on chalkboard — UPI Study

How Do Adjacency Matrix and List Store Graphs?

In a discrete mathematics course, adjacency matrix and list representations store the same graph in 2 different shapes: a matrix uses a V×V table, and a list keeps one neighbor list for each vertex. In a data structures assignment with 4 vertices labeled 0, 1, 2, and 3, a matrix puts each vertex on both axes, so cell [1][3] tells you whether edge 1→3 exists, and a weighted graph can place 8 or 2.5 in that cell instead of a plain 1. That setup feels very direct, and I think that is why teachers like it for first graph problems.

A list works differently. Vertex 0 might store [1, 3], vertex 1 might store [2], and vertex 3 might store [0, 2, 4] if the graph has 5 vertices total. Each entry records a neighbor, and the list can also store a weight beside that neighbor, like (2, 7) or (4, 11). If the graph is undirected, you record the edge in 2 places, one for each endpoint. If the graph is directed, you only record the direction that exists, which keeps the structure smaller and more honest.

The catch: A matrix always reserves space for every possible pair of vertices, even when the graph has only 6 real edges out of 36 possible spots. A list only writes down edges that actually exist, so it wastes less room on a sparse graph.

The simple mental picture I use in class: a matrix says, “Look at row 2 and column 4,” while a list says, “Check vertex 2’s neighbor box.” That difference sounds small, but in a 30-node homework graph it changes how you think about the whole problem. A matrix shines when you want a yes-or-no answer fast. A list shines when you want to walk through nearby vertices one by one.

For weights, both structures can store them, but they hide the weight in different places. A matrix puts the weight right in the cell, and a list puts it beside the neighbor. That is clean, but the matrix uses more memory and the list makes edge lookup less direct.

Which Graph Details Does Each Representation Capture?

A graph representation should match the exact 3-5 features your problem uses, because a bad translation can break a whole homework solution in 10 minutes. Directed edges, weights, self-loops, and vertex labels all need a clear plan before you code or hand-draw the graph.

Worth knowing: A messy conversion can flip a directed graph into an undirected one, and that single mistake ruins shortest-path work in Dijkstra or Floyd-Warshall.

I have seen students lose points because they copied the labels right but forgot the edge direction. That is a small error with a big penalty.

A matrix also makes loops and missing edges easier to spot on paper, which helps during a 50-minute quiz.

Discrete Mathematics UPI Study Course

Learn Discrete Mathematics Online for College Credit

This is one topic inside the full Discrete Mathematics course on UPI Study — a self-paced, online class that earns real college credit. Credits are ACE and NCCRS evaluated and transfer to partner colleges across the US and Canada. Courses start at $250 with no deadlines and lifetime access.

Browse Discrete Math Course →

Why Is An Adjacency Matrix Usually Larger?

An adjacency matrix usually takes more space because it stores V² cells, while an adjacency list uses about V + E slots, and that gap gets huge when E stays small. If a graph has 20 vertices, the matrix needs 400 cells whether it has 5 edges or 190 edges. A list grows with the real edges, so a graph with 20 vertices and 18 edges stays much lighter in memory.

That is why sparse graphs favor lists. In a sparse graph, the edge count sits far below V², so a matrix spends space on mostly empty cells. Dense graphs can justify a matrix because the graph already has lots of edges, and the extra cells stop feeling wasteful. A complete graph with 8 vertices has 28 undirected edges, so a matrix no longer looks absurd; it starts to feel like a fair trade for simple checks.

Reality check: If your professor gives you a 100-vertex graph and only 120 edges, a matrix stores 10,000 cells for a problem that barely uses 1.2% of them. That is the kind of memory waste students notice in C++, Java, and Python all at once.

A list also fits better with normal homework limits. Many intro assignments cap the graph at 50 or 100 vertices, and the list often lets you finish inside a few megabytes instead of filling memory with empty slots. I like that this mirrors real programming habits: use space where the graph actually lives, not where it might have lived.

Matrices still have a place. They make sense when the graph is dense, when you need fast edge checks, or when the class asks for a clean V×V model on paper. But for most sparse homework graphs, a list feels smarter and less clumsy.

That trade-off shows up in Discrete Mathematics problems and in Data Structures and Algorithms work that asks you to code a graph from scratch.

How Fast Can You Find Edges In Each?

Speed matters because graph homework often asks 5 different operations in the same problem set. A matrix and a list handle those jobs with very different costs, so the best choice depends on whether you check edges, add edges, or walk through neighbors most often. That is the part students tend to miss when they memorize formulas but skip the meaning.

OperationAdjacency MatrixAdjacency List
Check if edge existsO(1)O(deg(v))
Add edgeO(1)O(1)
Delete edgeO(1)O(deg(v))
Iterate neighborsO(V)O(deg(v))
Space useV² cellsV + E slots

A matrix wins on direct edge checks, and that matters in exam questions that ask, “Does 3 connect to 9?” A list wins when you only care about the neighbors that exist, which is why BFS and DFS often pair well with lists. In my view, the matrix feels neat on a whiteboard, but the list usually feels better in real code.

Which Representation Should You Choose When?

Choose an adjacency matrix when your graph is dense, your class asks for lots of edge checks, or you want a simple V×V picture that is easy to grade. Choose an adjacency list when the graph is sparse, when memory matters, or when you plan to visit neighbors one by one in BFS, DFS, or shortest-path work. That rule fits most discrete mathematics and introductory computer science tasks, and it stays useful from week 1 through the final exam.

A matrix also works well when your assignment uses small graphs, like 4 to 10 vertices, because the space cost stays manageable and the code stays short. A list starts to win as the graph grows, especially past 20 or 50 vertices, because empty matrix cells pile up fast. If your professor gives you a road map, a social network, or a course prerequisite chart, you usually see a sparse graph, so the list makes more sense.

Bottom line: Pick the structure that matches the graph, not the one that looks easiest for a single example. A dense network of 12 nodes can justify a matrix, but a 200-node graph with 240 edges almost always wants a list.

One more thing: do not choose based only on the first operation you see. If the assignment asks for edge checks 30 times and neighbor scans only once, the matrix may fit better; if the assignment asks for traversal and path finding, the list usually saves time and memory. That is a practical habit, not a fancy one, and it pays off in every graph unit.

If you are studying this for a discrete mathematics course, compare the graph shape, the number of vertices, and the operations before you code anything.

Frequently Asked Questions about Adjacency Representations

Final Thoughts on Adjacency Representations

Adjacency matrix and adjacency list representations solve the same problem, but they solve it with very different trade-offs. A matrix gives you speed for edge checks and a clean grid for small or dense graphs. A list gives you lean storage and better neighbor scanning for sparse graphs. That difference sounds technical, but it shapes almost every graph problem you will see in a discrete mathematics course. If you remember only one rule, make it this: count the vertices, think about the edges, then ask what operation the problem uses most. A graph with 10 vertices and 45 edges points one way. A graph with 100 vertices and 120 edges points the other way. That simple habit saves time on homework, code, and exams. Students also get tripped up by details that seem tiny on paper. Direction, weights, self-loops, and missing edges all change how you write the structure. A graph is not just a picture. It is a set of choices about how much work you want the computer to do later. The best next step is practical: take one sample graph from class, write it as a matrix, then rewrite it as a list and compare the space and lookup costs yourself. That 10-minute drill makes the differences stick.

The way this actually clicks

Skip step 3 and the whole thing is wasted.

Ready to Earn College Credit?

ACE & NCCRS approved · Self-paced · Transfer to colleges · $250/course or $99/month

More on Discrete Mathematics
© UPI Study. This article and its educational content are solely owned by UPI Study and licensed under CC BY-NC-ND 4.0. It is not free to reuse or modify. Any citation must credit UPI Study with a direct link to this page.