Background image of landing

Unrivalled
Education
Solutions for your
Family

What's the difference between an adjacency matrix and an adjacency list in graph representation?

An adjacency matrix is a square matrix utilized to represent a finite graph, whereas an adjacency list consists of a collection of unordered lists serving the same purpose.

An adjacency matrix is a two-dimensional array of size V×VV \times V, where VV denotes the number of vertices in the graph. The entries of this matrix indicate whether pairs of vertices are adjacent. Each vertex has a corresponding list that outlines the vertices it is directly connected to. The size of the matrix is V2V^2, making it particularly suitable for dense graphs—those in which the number of edges is close to V2V^2.

In contrast, an adjacency list comprises separate lists, with each list detailing the set of neighbors for a specific vertex. This structure is more space-efficient for sparsely connected graphs, where the number of edges is significantly less than V2V^2. In an adjacency list, each vertex maintains its own list of connected vertices, resulting in a total size of 2E2E, where EE represents the number of edges.

When considering time complexity, the performance of various operations differs between the two representations. For instance, checking whether an edge (u,v)(u, v) exists in the graph requires O(1)O(1) time for an adjacency matrix, while it takes O(V)O(V) time for an adjacency list. However, when it comes to iterating over the edges, the adjacency matrix incurs a cost of O(V2)O(V^2), whereas the adjacency list operates in O(V+E)O(V + E) time.

In conclusion, the decision to use an adjacency matrix or an adjacency list hinges on the characteristics of the graph and the specific operations to be performed. If the graph is dense and edge lookups are frequently needed, an adjacency matrix is preferable. Conversely, if the graph is sparse and edge iteration is a common operation, an adjacency list is the more efficient choice.

Answered by: Prof. Lucas Scott
A-Level Computer Science Tutor
Medal Icon

100%

Globe Icon

Global

Crest Icon

97%

Professional Tutors

International Tuition

Independent School Entrance Success

All of our elite tutors are full-time professionals, with at least five years of tuition experience and over 5000 accrued teaching hours in their subject.

Based in Cambridge, with operations spanning the globe, we can provide our services to support your family anywhere.

Our families consistently gain offers from at least one of their target schools, including Eton, Harrow, Wellington and Wycombe Abbey.

Medal Icon

100%

Professional Tutors

All of our elite tutors are full-time professionals, with at least five years of tuition experience and over 5000 accrued teaching hours in their subject.

Globe Icon

Global

International Tuition

Based in Cambridge, with operations spanning the globe, we can provide our services to support your family anywhere.

Crest Icon

97%

Independent School Entrance Success

Our families consistently gain offers from at least one of their target schools, including Eton, Harrow, Wellington and Wycombe Abbey.

Book a free
30-minute consultation
session

At the Beyond Tutors we recognise that no two students are the same. 

That’s why we’ve transcended the traditional online tutoring model of cookie-cutter solutions to intricate educational problems. Instead, we devise a bespoke tutoring plan for each individual student, to support you on your path to academic success.

To help us understand your unique educational needs, we provide a free 30-minute consultation with one of our founding partners, so we can devise the tutoring plan that’s right for you.

To ensure we can best prepare for this consultation, we ask you to fill out the short form below.

Hire a Tutor

All the form fields are optional, but we ask you to provide as much information as possible so that we are in a better position to quickly meet your tutoring requirements.

Still have questions?
Let's get in touch