Graph Representation in Data Structure – Adjacency Matrix – Adjacency List – Edge List

Graph Representation

Graphs can be represented in various ways:

  1. 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:

2 thoughts on “Graph Representation in Data Structure – Adjacency Matrix – Adjacency List – Edge List”

  1. M Ahsan Asmatullah

    Coding with Clicks is Great, Such Difficult Programming DSA Knowledge provided in very Easy way, This platform is Helping us so Much!!

    1. 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 🎯

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top