Representation of Graphs
In this lesson, we will cover two approaches for representing a graph.
We'll cover the following
Ways to Represent a Graph
The two most common ways to represent a graph are:
- Adjacency Matrix
- Adjacency List
Adjacency Matrix
The adjacency matrix is a two-dimensional matrix where each cell can contain a 0 or a 1. The row and column headings represent the vertices.
If a cell contains 1, there exists an edge between the corresponding vertices e.g., shows that an edge exists between vertex 0 and 1.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.