BITS Pilani
BITS Logo
CS G526: Advanced Algorithms and Complexity

Shortest Paths & Matrix Powers

Lecture 14 |2026-09-07
Tulasimohan Molli
BITS Pilani, Hyderabad Campus

Agenda

  1. The Shortest Path Problem: Formulation & Cost Semantics
  2. Weighted vs. Unweighted Graphs: Real-World Applications
  3. The Shortest Paths Landscape: Classical Complexities
  4. The Matrix Powering Perspective: Walks & Distances
  5. How to Compute A^k: Repeated Squaring in O(\log k) Steps
  6. Reachability & Path Existence via A, A^2, \dots, A^n
  7. The Resolvent Trick: Summing Powers via (I - A)^{-1}

What is the Shortest Path Problem?

Given a graph G = (V, E) (directed or undirected) with n = |V| vertices and m = |E| edges:

Formal Definition

A path p from source s to destination t is a sequence of vertices p = (v_0, v_1, v_2, \dots, v_k) where v_0 = s, v_k = t, and (v_{i-1}, v_i) \in E for all i \in \{1, \dots, k\}.

s w(e₁) = 4 v₁ w(e₂) = 2 v₂ w(e₃) = 5 t w(p) = 4+2+5 = 11
  • Weight Function: Each edge e = (u,v) \in E has a weight w(e) \in \mathbb{R}.
  • Path Weight: Total cost w(p) = \sum_{i=1}^k w(v_{i-1}, v_i).
  • Shortest Distance: \text{dist}(u, v) = \min_{p: u \rightsquigarrow v} w(p).

Graph Models: Weighted vs. Unweighted

Unweighted Graph (w = 1)
u v 1 1 1
Cost = Number of Hops  |  BFS: O(m + n)
Weighted Graph (w ∈ ℝ)
w = 12 (Direct/Fast) 1 + 2 + 1 = 4 (Shortest!) u v
Fewest hops ≠ Minimum total cost!
  • Unweighted: Every edge is a uniform hop. Solvable in O(m + n) time via Breadth-First Search (BFS).
  • Weighted: Edges model latency or distance. Greedy choice applies only when w \ge 0 (Dijkstra).

Real-World Applications: Key Domains

Shortest paths are among the most pervasive algorithmic primitives in modern computing:

🚗 Road Navigation & Traffic
Intersections & Road Segments (Google / Apple Maps)
Minimizes travel time, fuel burn, or toll cost.
🌐 Internet Packet Routing
Routers & Fiber / Satellite Links (OSPF, BGP)
Routes packets with lowest millisecond latency and packet drop.
👥 Social & Collaboration Networks
Users & Follows / Friendships (LinkedIn, X)
"Degrees of separation", mutual recommendations, influence spread.
📈 Currency Arbitrage & Finance
Currencies & Exchange Rates (w = −log r)
Negative cycles correspond to guaranteed riskless trading profits!

Real-World Applications: Problem Mapping

How practical domains map to our graph-theoretic models:

Domain Weight Model Vertices (V) & Edges (E) Cost Semantics
GPS Navigation Weighted (w \ge 0) Intersections & Roads Travel duration / Distance
Internet Routing Weighted (w > 0) Routers & Network Links Latency & Link Congestion
Social Networks Unweighted (w = 1) Users & Connections Number of friend / follower hops
Robotics & Motion Weighted (w \ge 0) Configuration States Actuator energy / Path clearance
Financial Arbitrage Arbitrary (w \in \mathbb{R}) Currencies & Rates -\log(\text{rate}): negative cycles = profit
  • Unweighted domains (social networks, hop routing) naturally target BFS and Seidel.
  • Non-negative weights fit Dijkstra; arbitrary weights (arbitrage, potentials) require Bellman–Ford.

The Shortest Paths Landscape

Problem Algorithm Time Complexity Graph Model / Allowed Weights
SSSP Dijkstra O(m + n \log n) Directed/Undirected, Non-negative (w \ge 0)
SSSP Bellman–Ford O(mn) Directed, Arbitrary weights (no negative cycles)
APSP Floyd–Warshall \Theta(n^3) Dense graphs, Arbitrary weights
APSP n \times \text{BFS} O(nm) \to \mathbf{O(n^3)} Unweighted (w = 1)
APSP Seidel’s Algorithm \mathbf{\tilde{O}(n^\omega) \approx O(n^{2.372})} Undirected, Unweighted (w = 1)
  • The Classical APSP Barrier: For dense graphs (m \approx n^2), both Floyd–Warshall and n \times \text{BFS} require \Theta(n^3) time.
  • The Algebraic Breakthrough: Seidel (1995) showed that fast matrix multiplication over \mathbb{Z} breaks the cubic barrier for unweighted APSP, achieving \tilde{O}(n^{2.372})!

The Matrix Powering Perspective: Walks & Paths

Can linear algebra compute shortest paths?

  • Let A be the unweighted adjacency matrix of graph G.

  • Matrix Multiplication Property: (A^k)_{u,v} = \sum_{i_1, i_2, \dots, i_{k-1}} A_{u, i_1} A_{i_1, i_2} \cdots A_{i_{k-1}, v}

  • (A^k)_{u,v} counts the exact number of walks of length k from u to v.

  • Unweighted Shortest Path Distance: d(u,v) = \min \{ k \ge 0 \mid (A^k)_{u,v} > 0 \}

  • In ordinary matrix algebra over ring (\mathbb{R}, +, \times), computing A^2 takes O(n^\omega) time (\omega < 2.372).

How to Compute A^k

Can we compute high powers A^k without performing k sequential multiplications?

Repeated Squaring (Binary Exponentiation)

Compute powers by repeatedly squaring previous results: A \longrightarrow A^2 \longrightarrow A^4 \longrightarrow A^8 \longrightarrow \cdots \longrightarrow A^{2^{\lfloor \log_2 k \rfloor}}

  • Recursive Formulation: A^k = \begin{cases} (A^{k/2})^2 & \text{if } k \text{ is even} \\ A \cdot (A^{(k-1)/2})^2 & \text{if } k \text{ is odd} \end{cases}

  • Operation Count: Requires only \lceil \log_2 k \rceil matrix multiplications!

  • Total Runtime: O(n^\omega \log k)

  • When k = n, we can compute A^n in O(n^\omega \log n) time.

Reachability & Path Existence

Does there exist a path between u and v in G?

  • The Path Length Bound: In any graph with n vertices, any simple path has length at most n - 1.

  • The Reachability Criterion: \exists \text{ path } u \rightsquigarrow v \iff (A + A^2 + A^3 + \dots + A^{n-1})_{u,v} > 0

  • If (A^k)_{u,v} > 0 for any 1 \le k \le n - 1, there exists a walk (and hence a simple path) of length \le n - 1 between u and v.

  • Transitive Closure Matrix: T = \sum_{k=0}^{n-1} A^k A pair (u, v) is connected if and only if T_{u,v} > 0.

The Resolvent Trick: (I - A)^{-1}

Can we sum all powers of A in a single matrix inversion?

The Matrix Geometric Series (Neumann Series)

Recall the scalar geometric series: for |x| < 1, \sum_{k=0}^\infty x^k = \frac{1}{1 - x}. For a matrix A (scaled so spectral radius \rho(A) < 1): \sum_{k=0}^\infty A^k = (I - A)^{-1}

  • Algebraic Verification: (I - A) \big(I + A + A^2 + \dots + A^k\big) = I - A^{k+1}

  • If A^{k+1} \to 0 (or working over formal power series \mathbb{R}[[A]]): (I - A) \sum_{k=0}^\infty A^k = I \implies \sum_{k=0}^\infty A^k = (I - A)^{-1}

  • Algorithmic Takeaway: The entries of (I - \epsilon A)^{-1} encode all-paths reachability and walk counts across all lengths simultaneously!

Next Lecture

Seidel’s Algorithm & The Isolation Lemma — Solving unweighted APSP in \tilde{O}(n^\omega) via fast matrix multiplication over \mathbb{Z}, and parallel matchings via the MVV Isolation Lemma.