Adjacency Matrix
← Back to Graph Representations
2D array where matrix[i][j] indicates an edge from vertex i to j. Space O(V²). O(1) edge lookup. Best for dense graphs or when frequent edge-existence checks are needed (e.g., Floyd-Warshall).
← Back to Graph Representations
2D array where matrix[i][j] indicates an edge from vertex i to j. Space O(V²). O(1) edge lookup. Best for dense graphs or when frequent edge-existence checks are needed (e.g., Floyd-Warshall).