We use a matrix with size V × V.
If the graph is a directed graph then we need to mark only one entry in the adjacency matrix.
Adjacency Matrix will be:
The adjacency matrix representation is good if the graphs are dense. The matrix requires O( V2) bits of storage and O( V2) time for initialization.
If the graph is sparse, the initialization of the matrix dominates the running time of the algorithm as it takes takes O( V2).
No comments:
Post a Comment