# Cell Probe Complexity ```Analysis of Algorithms
Minimum Mean-Weight Cycles
Uri Zwick
Tel Aviv University
December 2015
1
Minimum Mean-Weight Cycles
Let 𝐺 = (𝑉, 𝐸, 𝑤), where 𝑤: 𝐸 → ℝ.
The mean (average) weight of a cycle 𝐶 is 𝑤(𝐶)/|𝐶|.
Find a cycle 𝐶 with minimum mean weight.
Generalizes the problem of finding a negative cycle.
Useful in several applications (e.g., min cost flow).
Finding a minimum weight cycle is NP-hard. (Hamiltonian cycle.)
If 𝑤: 𝐸 → {−𝑁, … , 0, … , 𝑁}, we can use Goldberg’s algorithm +
binary search to get an 𝑂 𝑛 𝑚 log 𝑁 log 𝑛𝑁 -time algorithm.
Can we get a strongly-polynomial time algorithm?
2
Karp’s algorithm [Karp (1978)]
𝛿𝑛 𝑣 − 𝛿𝑘 (𝑣)
𝜇 = min max
𝑣∈𝑉 0≤𝑘&lt;𝑛
𝑛−𝑘
∗
𝜇∗ – the minimum mean weight of a cycle in 𝐺.
𝛿𝑘 (𝑣) – the smallest weight of a 𝑘-edge path that ends at 𝑣.
Add a source vertex 𝑠 and 0-edges (𝑠, 𝑣) for all 𝑣 ∈ 𝑉.
𝛿𝑘 (𝑣) is then be the length of the shortest path
from 𝑠 to 𝑣 that uses exactly 𝑘 + 1 edges.
The values 𝛿𝑘 (𝑣), for every 𝑣 ∈ 𝑉 and 0 ≤ 𝑘 &lt; 𝑛, can be
computed in 𝑂(𝑚𝑛) time using the Bellman-Ford algorithm.
Total running time of Karp’s algorithm is thus 𝑂(𝑚𝑛).
Exercise: How do we find a minimum mean weight cycle?
(Variant of) Bellman-Ford
𝛿0 𝑣 = 0, for every 𝑣 ∈ 𝑉.
𝛿𝑘 𝑣 = min 𝛿𝑘−1 𝑢 + 𝑤 𝑢, 𝑣 | 𝑢, 𝑣 ∈ 𝐸 , 𝑘 &gt; 0 , 𝑣 ∈ 𝑉.
(How is this different from the “standard” Bellman-Ford?)
We may have 𝛿𝑘 𝑣 = ∞, for some 𝑘,
i.e., there is no 𝑘-edge path ending at 𝑣.
This does not cause any problems. (Why?)
We can also remove such vertices from consideration. (Why?)
Running time is 𝑂(𝑚𝑛).
Exercise: Implement Karp’s algorithm in 𝑂(𝑚𝑛) time
using only 𝑂(𝑛) extra space. (In particular, we cannot store
𝛿𝑘 (𝑣) for every 𝑘 and every 𝑣, as this requires Θ(𝑛2 ) space.)
Karp’s algorithm [Karp (1978)]
𝛿𝑛 𝑣 − 𝛿𝑘 (𝑣)
𝜇 = min max
𝑣∈𝑉 0≤𝑘&lt;𝑛
𝑛−𝑘
𝜇∗ – the minimum mean weight of a cycle in 𝐺.
Theorem: 𝜇∗ = 𝜇.
If we subtract 𝜇∗ from all edge weights then:
The minimum mean weight of a cycle in 𝐺
is decreased by 𝜇∗ and becomes 0.
𝛿𝑛 (𝑣) is decreased by 𝑛𝜇∗ , 𝛿𝑘 (𝑣) is decreased by 𝑘𝜇∗ .
Hence 𝜇 is also decreased by 𝜇∗ .
If it thus enough to prove the claim when 𝜇∗ = 0.
Karp’s algorithm [Karp (1978)]
𝛿𝑛 𝑣 − 𝛿𝑘 (𝑣)
𝜇 = min max
𝑣∈𝑉 0≤𝑘&lt;𝑛
𝑛−𝑘
Lemma: If 𝜇∗ = 0, then 𝜇 = 0.
Claim 1: If 𝜇∗ = 0, then 𝜇 ≥ 0.
∀𝑣 ∃𝑘 𝛿𝑘 𝑣 ≤ 𝛿𝑛 𝑣
As 𝜇 ∗ = 0, the are no negative cycles.
Thus, the distances in 𝐺 are well defined.
For every 𝑣 ∈ 𝑉, let 𝑘 = 𝑘(𝑣) be such that 𝛿 𝑣 = 𝛿𝑘 (𝑣),
i.e., where 𝛿 𝑣 is the distance from 𝑠 to 𝑣.
𝛿𝑘 𝑣 = 𝛿 𝑣 ≤ 𝛿𝑛 𝑣 .
max(𝛿𝑛 𝑣 − 𝛿𝑘 𝑣 )/(𝑛 − 𝑘) ≥ 0
𝑘
𝜇 = min𝑣 max(𝛿𝑛 𝑣 − 𝛿𝑘 𝑣 )/(𝑛 − 𝑘) ≥ 0
𝑘
Karp’s algorithm [Karp (1978)]
𝛿𝑛 𝑣 − 𝛿𝑘 (𝑣)
𝜇 = min max
𝑣∈𝑉 0≤𝑘&lt;𝑛
𝑛−𝑘
Lemma: If 𝜇∗ = 0, then 𝜇 = 0.
Claim 2: If 𝜇∗ = 0, then 𝜇 ≤ 0.
∃𝑣 ∀𝑘 𝛿𝑘 𝑣 ≥ 𝛿𝑛 𝑣
As 𝜇 ∗ = 0, the are no negative cycles.
There is a potential function 𝑝: 𝑉 → ℝ such that
𝑤𝑝 𝑢, 𝑣 = 𝑤 𝑢, 𝑣 + 𝑝 𝑢 − 𝑝 𝑣 ≥ 0 , for every 𝑢, 𝑣 ∈ 𝐸.
The expression above is unchanged if distances are
computed with respect to 𝑤𝑝 rather than 𝑤.
𝜇 𝑤 = 𝜇(𝑤𝑝 )
Karp’s algorithm [Karp (1978)]
Claim 2: If 𝜇∗ = 0, then 𝜇 ≤ 0.
∃𝑣 ∀𝑘 𝛿𝑘 𝑣 ≥ 𝛿𝑛 𝑣
Let 𝐶 be a 0-cycle.
Let 𝑢 be a node of 𝐶, and let 𝑃 be a shortest path from 𝑠 to 𝑢.
For every 𝑢, 𝑣 ∈ 𝐶 ∪ 𝑃, we have 𝑤𝑝 𝑢, 𝑣 = 0.
Let 𝑘 be the number of edges on 𝑃.
Follow 𝑛 − 𝑘 edges around the cycle starting from 𝑢.
Let 𝑣 be the final vertex reached.
0
𝑣
0
0
𝑠
0
0
0 𝑢
𝛿𝑛 𝑣 = 0 ≤ 𝛿𝑘 𝑣 ,
for every 0 ≤ 𝑘 &lt; 𝑛.
𝐶
0
0
0
Karp’s algorithm [Karp (1978)]
Claim 2: If 𝜇∗ = 0, then 𝜇 ≤ 0.
∃𝑣 ∀𝑘 𝛿𝑘 𝑣 ≥ 𝛿𝑛 𝑣
Same proof without potentials.
Let 𝑎 be the sum of weights along the cycle from 𝑢 to 𝑣.
The sum of the weight from 𝑣 to 𝑢 is then −𝑎.
𝛿𝑛 𝑣 ≤ 𝑤 𝑃 + 𝑎 (as this is a path of 𝑛 edges)
𝑤 𝑃 ≤ 𝛿𝑘 𝑣 − 𝑎 (as 𝑃 is a shortest path)
𝛿𝑛 𝑣 ≤ 𝑤 𝑃 + 𝑎 ≤ 𝛿𝑘 (𝑣)
𝑣
𝑎
𝑢
𝑠
𝐶
𝑃
−𝑎
```