File 1714029217 66059 Graph
File 1714029217 66059 Graph
File 1714029217 66059 Graph
Adjacency Matrix:
● a 2D array is used to store information about the edges between
vertices.
● The entry at position (i, j) in the matrix indicates whether there is an edge
between vertex i and vertex j.
● For an undirected graph, the matrix is symmetric, and for a weighted
graph, the matrix may contain weights.
Graph Representation:
Adjacency List:
● Each vertex maintains a list of its adjacent vertices.
● This representation is suitable for sparse graphs where the number of
edges is much less than the maximum possible edges.
● It saves space by only storing information about existing edges.