There are 2 popular ways of representing an undirected graph.

**Adjacency List**

Each list describes the set of neighbors of a vertex in the graph.

**Adjacency Matrix**

The elements of the matrix indicate whether pairs of vertices are adjacent or not in the graph.

Here’s an implementation of the above in Python:

**Output:**

Advertisements