Graph Representation
Graphs can be represented in various ways:
- Adjacency Matrix:
- A 2D array where A[i][j]=1(or the weight of the edge) if there is an edge between vertices i and j, otherwise A[i][j]=0.
- Space Complexity: O(V2).
- Good for dense graphs.
Matrix Representation:

The adjacency matrix is a VĂV table where:
- Rows and columns represent vertices.
- 1 indicates an edge from vertex i to vertex j.
- 0 indicates no edge.
2. Adjacency List:
- An array (or list) where each element contains a list of all adjacent vertices.
- Space Complexity: O(V+E).
- Good for sparse graphs.
List Representation:



3. Edge List:
- A list of all edges, where each edge is represented as a pair (u, v) (or triplet (u, v, w) for weighted graphs) of vertices.
- Space Complexity: O(E).
List Representation:



Coding with Clicks is Great, Such Difficult Programming DSA Knowledge provided in very Easy way, This platform is Helping us so Much!!
Thank you so much for your kind words! đđ Your support means a lot! I’m glad Coding With Clicks is making DSA and programming easier to understand. Stay tuned for more awesome content! đđť Keep learning and keep growing! đĄđĽ #CodingWithClicks đŻ