⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 19m 32s17 days 22 hours 19 minutes 32 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 19m 32s17 days 22 hours 19 minutes 32 seconds.

Sign in to watch this lesson
Advanced - Graphs · 4:07
The k-th power of a graph's adjacency matrix counts the walks with exactly k edges between every pair of vertices, and binary exponentiation computes it in O(n³ log k). Swapping (+, ×) for (min, +) turns the same code into the cheapest walk with exactly k edges, which is the matrix form of Bellman–Ford. Giving every vertex a twin with a loop turns 'exactly k + 1 edges' into 'at most k edges'.