Get the latest tech news
How many paths of length K are there between A and B? (2021)
's a (surprisingly interesting) programming problem: Given a directed unweighted graph with V vertices and E edges, how many paths of length K are there from node A to node B? Paths may visit the same node or edge multiple times[1]. To avoid dealing with very large numbers, assume that we're computing our answer modulo a large prime.
What if I told you, that drawing on concepts from coding theory, abstract algebra, and signal processing, we could solve this problem in O(EV+VlogVlogK)O(EV + V \log V \log K)O(EV+VlogVlogK) time? In fact, this is a special case of the more general algorithm to find the KKK-th term of any order NNN linear recurrence using matrix exponentiation in O(N3logK)O(N^3 \log K)O(N3logK) time. Corollary 22 of this paper states that the procedure outlined above succeeds with probability (1−1/q)2n(1-1/q)^{2n}(1−1/q)2n, where qqq is the cardinality of our finite field (how big our mod is).
Or read this on Hacker News