Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 46s1 days 16 hours 1 minutes 46 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 46s1 days 16 hours 1 minutes 46 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'.