Graph Theory37 sections · 1633 units
Open in Course

Memory Layout

(Using 2D array efficiently)

Floyd-Warshall uses a 2D2D array dist[i][j] of size n×nn \times n. For n=1000n = 1000, this is 11 million entries (44-88 MB for integers). This fits in cache on modern machines. Initialize the array carefully: set diagonal to 00, edges to weights, rest to infinity (use a large constant like 10910^9).

Proper initialization is critical. If you mess up the initial state, the algorithm computes garbage. Memory layout affects performance on large inputs.