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+Vlog⁡Vlog⁡K)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(N3log⁡K)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).

Get the Android app

Or read this on Hacker News

Read more on:

Photo of paths

paths

Photo of length K

length K

Related news:

News photo

Finding paths of least action with gradient descent (2023)

News photo

Path is a utility for working with paths

News photo

MIT’s robot bees break pollination records with 1,000-second hover, flips and more | The robot reaches 35 cm/s, performs flips, and traces paths like “M-I-T,” highlighting control and endurance advances.