11. Matrices and Graphs

Existence of a Walk

A walk of length exists between two nodes and if there exists any walks of length from to and an edge from to . Formally:

adjacency matrix

To check the existence of a path of length less than , add a self loop at every node.

Cheapest Walk

The cost of a walk of length is the cheapest walk from to some node of length and the weight of to .

adjacency matrix with 1s replaced by edge weight

Number of Walks

The number of walks from to of length equals the sum over all intermediate nodes of: walks from to of length number of edges from to .

adjacency matrix

Similarly to existence: add a self-edge of weight 0 to get the number of walk of length at least .

The formula above is identical to matrix multiplication. Therefore: .

Iterative Squaring

we can compute using two multiplications instead of 4. Formally:

That reduces the number of matrix multiplications from to .