Posted inComputer Science Data Structures Graphs
How to Represent an Undirected Unweighted Graph with an Adjacency Matrix
Represent an undirected unweighted graph as an adjacency matrix of ones and zeros. A one in the cell at row i and column j means an edge exists between those nodes. Because the graph is undirected the matrix is symmetric across the diagonal. Changing a cell from zero to one adds an edge and changing it back removes the edge. Self-loops appear on the diagonal. This representation stores only the connection relationships and supports constant-time edge checks.
