Graph Theory37 sections · 1633 units
Open in Course

Undirected Graphs

(Symmetric distance matrix)

For undirected graphs, the distance matrix is symmetric: dist[i][j] = dist[j][i]. When reading edges, set both dist[i][j] and dist[j][i] to the edge weight. Floyd-Warshall works the same way for undirected graphs.

The symmetry is preserved after the algorithm. You can save space by storing only the upper triangle, but in practice the 2D2D array is simpler. Most implementations use the full matrix for clarity.