# 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)
πΏπ π£ ≤ π€ π + π ≤ πΏπ (π£)
π£
π
π’
π
πΆ
π
−π
```