Cell Probe Complexity

advertisement
Analysis of Algorithms
Minimum Mean-Weight Cycles
Uri Zwick
Tel Aviv University
December 2015
Last modified: December 9, 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≤π‘˜<𝑛
𝑛−π‘˜
∗
πœ‡∗ – 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 ≤ π‘˜ < 𝑛, 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 𝑒 + 𝑀 𝑒, 𝑣 | 𝑒, 𝑣 ∈ 𝐸 , π‘˜ > 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≤π‘˜<𝑛
𝑛−π‘˜
πœ‡∗ – 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≤π‘˜<𝑛
𝑛−π‘˜
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≤π‘˜<𝑛
𝑛−π‘˜
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 ≤ π‘˜ < 𝑛.
𝐢
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)
𝛿𝑛 𝑣 ≤ 𝑀 𝑃 + π‘Ž ≤ π›Ώπ‘˜ (𝑣)
𝑣
π‘Ž
𝑒
𝑠
𝐢
𝑃
−π‘Ž
Download