Balanced Mobiles Yassine Hamoudi , Sophie Laplante , Roberto Mantaci - - PowerPoint PPT Presentation
Balanced Mobiles Yassine Hamoudi , Sophie Laplante , Roberto Mantaci - - PowerPoint PPT Presentation
Balanced Mobiles Yassine Hamoudi , Sophie Laplante , Roberto Mantaci May 17, 2017 ENS Lyon IRIF, Paris Diderot Mobile . Calder, 1932. 1 Introduction A mobile M is a full binary tree in which each leaf has a (positive) weight. 5 3 15 2 4
- Mobile. Calder, 1932.
1
Introduction
A mobile M is a full binary tree in which each leaf has a (positive) weight. 5 3 2 4 15
2
Introduction
The local imbalance δ of a node is the difference (in absolute value) be- tween the weights WL and WR of the left and right subtrees of the node. 5 3 2 4 15
13 2 9 2 2
Introduction
The imbalance ∆M of M is the sum of all the local imbalances. 5 3 2 4 15
13 2 9 2
∆M = 13 + 2 + 9 + 2 = 26
2
Introduction
The Balanced Mobiles problem consists in constructing, for a given set of weights {w1, . . . , wn}, a mobile of imbalance as small as possible. 5 3 2 4 15
13 2 9 2
∆M = 26 − → 2 5 3 4 15
3 1 1
∆M = 5
3
Contents
The Smallest algorithm All-Equal Weights Integer Linear Programming The Evaluation Trees problem Conclusion
4
The Smallest algorithm
The Smallest algorithm (∼ Huffman coding)
Input: weights w1 ≤ · · · ≤ wn Output: imbalance Smallest(w1, . . . , wn) if n = 2 then Return |w2 − w1| else Return |w2 − w1| + Smallest(Sort(w1 + w2, w3, . . . , wn))
5
The Smallest algorithm (∼ Huffman coding)
Input: weights w1 ≤ · · · ≤ wn Output: imbalance Smallest(w1, . . . , wn) if n = 2 then Return |w2 − w1| else Return |w2 − w1| + Smallest(Sort(w1 + w2, w3, . . . , wn)) 1 2 2 3 4 6
5
The Smallest algorithm (∼ Huffman coding)
Input: weights w1 ≤ · · · ≤ wn Output: imbalance Smallest(w1, . . . , wn) if n = 2 then Return |w2 − w1| else Return |w2 − w1| + Smallest(Sort(w1 + w2, w3, . . . , wn)) 1 2 3 2 3 4 6
5
The Smallest algorithm (∼ Huffman coding)
Input: weights w1 ≤ · · · ≤ wn Output: imbalance Smallest(w1, . . . , wn) if n = 2 then Return |w2 − w1| else Return |w2 − w1| + Smallest(Sort(w1 + w2, w3, . . . , wn)) 1 2 2 3 3 5 4 6
5
The Smallest algorithm (∼ Huffman coding)
Input: weights w1 ≤ · · · ≤ wn Output: imbalance Smallest(w1, . . . , wn) if n = 2 then Return |w2 − w1| else Return |w2 − w1| + Smallest(Sort(w1 + w2, w3, . . . , wn)) 1 2 2 3 4 7 5 6
5
The Smallest algorithm (∼ Huffman coding)
Input: weights w1 ≤ · · · ≤ wn Output: imbalance Smallest(w1, . . . , wn) if n = 2 then Return |w2 − w1| else Return |w2 − w1| + Smallest(Sort(w1 + w2, w3, . . . , wn)) 1 2 2 3 4 6 7 11
5
The Smallest algorithm (∼ Huffman coding)
Input: weights w1 ≤ · · · ≤ wn Output: imbalance Smallest(w1, . . . , wn) if n = 2 then Return |w2 − w1| else Return |w2 − w1| + Smallest(Sort(w1 + w2, w3, . . . , wn)) 1 2 2 3 4 6
1 1 1 1 4
∆ = 8
5
Non-optimality of Smallest
2
5 · 2k 10 5 2 2
1 1 1
5 · 2k 10 5 3 3
1 1 1
∆ = 4 + 2k − →
5 · 2k 10 5 2 3
1
5 · 2k 10 5 3 2
1
∆ = 2
6
Optimal cases for Smallest
Theorem The Smallest algorithm is optimal in the following cases: ❼ when the smallest possible imbalance is 0 or 1 ❼ when all the weights are equal ❼ when all the weights are powers of two It runs in O(n log n) time.
7
The R-Smallest algorithm
Given two mobiles of weights A and B, if w1 ≤ A ≤ B then this rotation does not increase the imbalance: A B w1 − → A B w1
8
The R-Smallest algorithm
Given two mobiles of weights A and B, if w1 ≤ A ≤ B then this rotation does not increase the imbalance: A B w1 − → A B w1 Lemma For any weights w1 ≤ · · · ≤ wn, there exists an optimal mobile in which the sibling of the leaf of weight w1 is also a leaf.
8
The R-Smallest algorithm
Given w1 ≤ · · · ≤ wn and a threshold δ, try for all i to find a mobile of imbalance ≤ δ − |w1 − wi| on {w1 + wi, w2, . . . , wi−1, wi+1, . . . , wn}.
9
The R-Smallest algorithm
Given w1 ≤ · · · ≤ wn and a threshold δ, try for all i to find a mobile of imbalance ≤ δ − |w1 − wi| on {w1 + wi, w2, . . . , wi−1, wi+1, . . . , wn}. Theorem For any weights w1, . . . , wn, the R-Smallest algorithm finds the
- ptimal imbalance ∆ in time O
- log(n)nmin(∆,n)+1
.
9
All-Equal Weights
∆n : optimal imbalance for the weights w1 = · · · = wn = 1 1 1 1 1 1
1 1
∆5 = 2
10
∆n : optimal imbalance for the weights w1 = · · · = wn = 1 1 1 1 1 1
1 1
∆5 = 2 → the Smallest algorithm is optimal in this case → a Partition algorithm (inspired from 2-Partition) is also optimal
10
Partition algorithm
1 1 1 1 1 1 1
11
Partition algorithm
1
1 1 1 1 1 1 1
11
Partition algorithm
1 1
1 1 1 1 1 1 1
11
Partition algorithm
1 1
1 1 1 1 1 1 1 ∆ = 2
11
First recurrence relation for ∆n
The optimal imbalance ∆n verifies: ∆1 = 0 ∆2n = 2∆n ∆2n+1 = 1 + ∆n + ∆n+1
12
Smallest algorithm
1 1 1 1 1 1 1 1 1
1 1 1
A mobile over 9 weights, built with Smallest.
13
Smallest algorithm
1 1 1 1 1 1 1 1 1 1
1 +1 1 +1 1 −1
A mobile over 10 weights, built with Smallest.
13
Smallest algorithm
1 1 1 1 1 1 1 1 1 1
1 +1 1 +1 1 −1
1
Increase of |001|0 − |001|1
13
Smallest algorithm
1 1 1 1 1 1 1 1 1 1
1 +1 1 +1 1 −1 1 2 3 4 5 6 7
1
Increase of |001|0 − |001|1 = |1001|0 − (|1001|1 − 1)
13
Smallest algorithm
1 1 1 1 1 1 1 1 1 1
1 +1 1 +1 1 −1 1 2 3 4 5 6 7
1
Increase of |001|0 − |001|1 =
- 23 + 1
- 0 − (
- 23 + 1
- 1 − 1)
13
Smallest algorithm
1 1 1 1 1 1 1 1 1 1
1 +1 1 +1 1 −1 1 2 3 4 5 6 7
1
Increase of |001|0 − |001|1 =
- 23 + 1
- 0 − (
- 23 + 1
- 1 − 1)
S10 = S9 + |9|0 − |9|1 + 1
13
Second recurrence relation for ∆n
The imbalance Sn obtained by Smallest verifies:
- S1 = 0
Sn+1 = Sn + |n|0 − |n|1 + 1
14
Second recurrence relation for ∆n
The imbalance Sn obtained by Smallest verifies:
- S1 = 0
Sn+1 = Sn + |n|0 − |n|1 + 1 Proposition Using ∆2n = 2∆n, ∆2n+1 = 1 + ∆n + ∆n+1 we prove Sn = ∆n.
14
The ∆n function
∆1 = 0 ∆2n = 2∆n ∆2n+1 = 1 + ∆n + ∆n+1 and
- ∆1 = 0
∆n+1 = ∆n + |n|0 − |n|1 + 1
15
The ∆n function
∆1 = 0 ∆2n = 2∆n ∆2n+1 = 1 + ∆n + ∆n+1 and
- ∆1 = 0
∆n+1 = ∆n + |n|0 − |n|1 + 1 If bkbk−1 . . . b0 is the binary representation of n : ∆n = 2 · (n mod 2k) +
k−1
- i=0
(−1)bi · (n mod 2i+1)
15
The ∆n function
∆1 = 0 ∆2n = 2∆n ∆2n+1 = 1 + ∆n + ∆n+1 and
- ∆1 = 0
∆n+1 = ∆n + |n|0 − |n|1 + 1 If bkbk−1 . . . b0 is the binary representation of n : ∆n = 2 · (n mod 2k) +
k−1
- i=0
(−1)bi · (n mod 2i+1) n ∆n
12 4 8 16 32 64 5 10 15 20 15
Integer Linear Programming
w1 w2 w3 w4 w5
16
1 2 3 4
w1 w2 w3 w4 w5
16
1 2 3 4
w1 w2 w3 w4 w5
1 2 3 4 w1 ℓ1,1 = 1 ℓ1,2 = 1 ℓ1,3 = 1 ℓ1,4 = 0 r1,1 = 0 r1,2 = 0 r1,3 = 0 r1,4 = 0 w2 ℓ2,1 = 1 ℓ2,2 = 1 ℓ2,3 = 0 ℓ2,4 = 0 r2,1 = 0 r2,2 = 0 r2,3 = 1 r2,4 = 0 w3 ℓ3,1 = 1 ℓ3,2 = 0 ℓ3,3 = 0 ℓ3,4 = 1 r3,1 = 0 r3,2 = 1 r3,3 = 0 r3,4 = 0 w4 ℓ4,1 = 1 ℓ4,2 = 0 ℓ4,3 = 0 ℓ4,4 = 0 r4,1 = 0 r4,2 = 1 r4,3 = 0 r4,4 = 1 w5 ℓ5,1 = 0 ℓ5,2 = 0 ℓ5,3 = 0 ℓ5,4 = 0 r5,1 = 1 r5,2 = 0 r5,3 = 0 r5,4 = 0
Define: ❼ ℓi,u = 1 if wi is in the left subtree of the node u, 0 otherwise ❼ ri,u = 1 if wi is in the right subtree of the node u, 0 otherwise
16
1 2 3 4
w1 w2 w3 w4 w5
1 2 3 4 w1 ℓ1,1 = 1 ℓ1,2 = 1 ℓ1,3 = 1 ℓ1,4 = 0 r1,1 = 0 r1,2 = 0 r1,3 = 0 r1,4 = 0 w2 ℓ2,1 = 1 ℓ2,2 = 1 ℓ2,3 = 0 ℓ2,4 = 0 r2,1 = 0 r2,2 = 0 r2,3 = 1 r2,4 = 0 w3 ℓ3,1 = 1 ℓ3,2 = 0 ℓ3,3 = 0 ℓ3,4 = 1 r3,1 = 0 r3,2 = 1 r3,3 = 0 r3,4 = 0 w4 ℓ4,1 = 1 ℓ4,2 = 0 ℓ4,3 = 0 ℓ4,4 = 0 r4,1 = 0 r4,2 = 1 r4,3 = 0 r4,4 = 1 w5 ℓ5,1 = 0 ℓ5,2 = 0 ℓ5,3 = 0 ℓ5,4 = 0 r5,1 = 1 r5,2 = 0 r5,3 = 0 r5,4 = 0
The imbalance is:
n−1
- u=1
- n
- i=1
wi(ℓi,u − ri,u)
- 16
1 2 3 4
w1 w2 w3 w4 w5
1 2 3 4 w1 ℓ1,1 = 1 ℓ1,2 = 1 ℓ1,3 = 1 ℓ1,4 = 0 r1,1 = 0 r1,2 = 0 r1,3 = 0 r1,4 = 0 w2 ℓ2,1 = 1 ℓ2,2 = 1 ℓ2,3 = 0 ℓ2,4 = 0 r2,1 = 0 r2,2 = 0 r2,3 = 1 r2,4 = 0 w3 ℓ3,1 = 1 ℓ3,2 = 0 ℓ3,3 = 0 ℓ3,4 = 1 r3,1 = 0 r3,2 = 1 r3,3 = 0 r3,4 = 0 w4 ℓ4,1 = 1 ℓ4,2 = 0 ℓ4,3 = 0 ℓ4,4 = 0 r4,1 = 0 r4,2 = 1 r4,3 = 0 r4,4 = 1 w5 ℓ5,1 = 0 ℓ5,2 = 0 ℓ5,3 = 0 ℓ5,4 = 0 r5,1 = 1 r5,2 = 0 r5,3 = 0 r5,4 = 0
The weight wi cannot be simultaneously in the left and right subtrees of the node u. ∀i, u, ℓi,u + ri,u ≤ 1
16
1 2 3 4
w1 w2 w3 w4 w5
1 2 3 4 w1 ℓ1,1 = 1 ℓ1,2 = 1 ℓ1,3 = 1 ℓ1,4 = 0 r1,1 = 0 r1,2 = 0 r1,3 = 0 r1,4 = 0 w2 ℓ2,1 = 1 ℓ2,2 = 1 ℓ2,3 = 0 ℓ2,4 = 0 r2,1 = 0 r2,2 = 0 r2,3 = 1 r2,4 = 0 w3 ℓ3,1 = 1 ℓ3,2 = 0 ℓ3,3 = 0 ℓ3,4 = 1 r3,1 = 0 r3,2 = 1 r3,3 = 0 r3,4 = 0 w4 ℓ4,1 = 1 ℓ4,2 = 0 ℓ4,3 = 0 ℓ4,4 = 0 r4,1 = 0 r4,2 = 1 r4,3 = 0 r4,4 = 1 w5 ℓ5,1 = 0 ℓ5,2 = 0 ℓ5,3 = 0 ℓ5,4 = 0 r5,1 = 1 r5,2 = 0 r5,3 = 0 r5,4 = 0
If the weight wi is the right (resp. left) child of the node u, then none of the other leaves can be in the right (resp. left) subtree of the node u. ∀i = j, ∀u,
- (1 − ℓi,u) +
v>u(ℓi,v + ri,v) ≥ ℓj,u
(1 − ri,u) +
v>u(ℓi,v + ri,v) ≥ rj,u 16
Minimize
n−1
- u=1
- n
- i=1
wi(ℓi,u − ri,u)
- subject to:
∀i, u, ℓi,u + ri,u ≤ 1 ∀i, ℓi,1 + ri,1 = 1 ∀u,
i ℓi,u > 0 and i ri,u > 0
∀i = j, ∀u,
- (1 − ℓi,u) +
v>u(ℓi,v + ri,v) ≥ ℓj,u
(1 − ri,u) +
v>u(ℓi,v + ri,v) ≥ rj,u
∀i = j, ∀u < v,
- ℓi,u + (ℓi,v + ri,v + ℓj,v + rj,v) ≤ 2 + ℓj,u
ri,u + (ℓi,v + ri,v + ℓj,v + rj,v) ≤ 2 + rj,u ∀i = j, ∀u < u′,
- 2 − ℓi,u − ℓj,u + u′
w=u+1(ℓi,w + ri,w) ≥ rj,u′ + rj,u′
2 − ri,u − rj,u + u′
w=u+1(ℓi,w + ri,w) ≥ ℓj,u′ + ℓj,u′ 17
The Evaluation Trees problem
Non-Abelian Evaluation Trees
Problem Given n elements x1, . . . , xn of a set X equipped with an associative
- perator ◦ : X × X → X and a cost function c : X × X → R+, find the
- ptimal evaluation tree to compute x1 ◦ x2 ◦ . . . ◦ xn.
18
Non-Abelian Evaluation Trees
Problem Given n elements x1, . . . , xn of a set X equipped with an associative
- perator ◦ : X × X → X and a cost function c : X × X → R+, find the
- ptimal evaluation tree to compute x1 ◦ x2 ◦ . . . ◦ xn.
- x1
x2 x3 x4 ((x1 ◦ x2) ◦ (x3 ◦ x4))
18
Non-Abelian Evaluation Trees
Problem Given n elements x1, . . . , xn of a set X equipped with an associative
- perator ◦ : X × X → X and a cost function c : X × X → R+, find the
- ptimal evaluation tree to compute x1 ◦ x2 ◦ . . . ◦ xn.
- x1
x2 x3 x4 ((x1 ◦ (x2 ◦ x3)) ◦ x4)
18
Non-Abelian Evaluation Trees
Problem Given n elements x1, . . . , xn of a set X equipped with an associative
- perator ◦ : X × X → X and a cost function c : X × X → R+, find the
- ptimal evaluation tree to compute x1 ◦ x2 ◦ . . . ◦ xn.
c(x1 ◦ x2 ◦ x3, x4) c(x1, x2 ◦ x3) c(x2, x3)
x1 x2 x3 x4 c(x1 ◦ x2 ◦ x3, x4) + c(x1, x2 ◦ x3) + c(x2, x3)
18
Ordered Balanced Mobiles
Given a sequence of weights (w1, . . . , wn), find a mobile of imbalance as small as possible with these weights in the same order from left to right. 4 8 3 5 7
3 4 1 2
An optimal mobile for the sequence (4, 8, 3, 5, 7).
19
Ordered Balanced Mobiles
Given a sequence of weights (w1, . . . , wn), find a mobile of imbalance as small as possible with these weights in the same order from left to right. This is a Non-Abelian Evaluation Trees problem with: ❼ xi = wi and X = N ❼ c(x, y) = |x − y| ❼ x ◦ y = x + y
19
Matrix Chain Multiplication
Given a sequence of matrices (M1, . . . , Mn) where dim(Mi) = (ni−1, ni), find the optimal way to compute the product M1 × · · · × Mn. ❼ ❼ ❼
20
Matrix Chain Multiplication
Given a sequence of matrices (M1, . . . , Mn) where dim(Mi) = (ni−1, ni), find the optimal way to compute the product M1 × · · · × Mn. This is a Non-Abelian Evaluation Trees problem with: ❼ xi = (ni−1, ni) and X = N × N ❼ c(x, y) = n × m × k where x = (n, m) and y = (m, k) ❼ x ◦ y = (n, k) where x = (n, m) and y = (m, k)
20
Matrix Chain Multiplication
Given a sequence of matrices (M1, . . . , Mn) where dim(Mi) = (ni−1, ni), find the optimal way to compute the product M1 × · · · × Mn. This is a Non-Abelian Evaluation Trees problem with: ❼ xi = (ni−1, ni) and X = N × N ❼ c(x, y) = n × m × k where x = (n, m) and y = (m, k) ❼ x ◦ y = (n, k) where x = (n, m) and y = (m, k) Dynamic programming in O
- n3
: C[i, j] =
- if i = j
min
i≤k<j {C[i, k] + C[k + 1, j] + c(xi ◦ · · · ◦ xk, xk+1 ◦ · · · ◦ xj), }
if i < j
20
Abelian Evaluation Trees
Problem Given n elements x1, . . . , xn of a set X equipped with an associative and commutative operator ◦ : X × X → X and a cost function c : X × X → R+, find the optimal evaluation tree to compute x1 ◦ x2 ◦ . . . ◦ xn.
- x3
x1 x4 x2 ((x3 ◦ (x1 ◦ x4)) ◦ x2)
21
Balanced Mobiles
Given a set of weights {w1, . . . , wn}, find a mobile of imbalance as small as possible with these weights. This is an Abelian Evaluation Trees problem with: ❼ xi = wi and X = N ❼ c(x, y) = |x − y| ❼ x ◦ y = x + y
22
Huffman Coding
Given an alphabet {a1, . . . , an} and the number of occurencies wi of each ai, find a prefix-free binary code (c1, . . . , cn) that minimizes
i wi · |ci|.
❼ ❼ ❼
23
Huffman Coding
Given an alphabet {a1, . . . , an} and the number of occurencies wi of each ai, find a prefix-free binary code (c1, . . . , cn) that minimizes
i wi · |ci|.
w2 w1 w4 w3 3w1 + w2 + 2w3 + 3w4 ❼ ❼ ❼
23
Huffman Coding
Given an alphabet {a1, . . . , an} and the number of occurencies wi of each ai, find a prefix-free binary code (c1, . . . , cn) that minimizes
i wi · |ci|.
w2 w1 w4 w3
w2 + (w1 + w3 + w4) (w1 + w4) + w3 w1 + w4
3w1 + w2 + 2w3 + 3w4 ❼ ❼ ❼
23
Huffman Coding
Given an alphabet {a1, . . . , an} and the number of occurencies wi of each ai, find a prefix-free binary code (c1, . . . , cn) that minimizes
i wi · |ci|.
w2 w1 w4 w3
w2 + (w1 + w3 + w4) (w1 + w4) + w3 w1 + w4
3w1 + w2 + 2w3 + 3w4 This is an Abelian Evaluation Trees problem with: ❼ xi = wi and X = N ❼ c(x, y) = x + y ❼ x ◦ y = x + y
23
Generalized Huffman Coding
The coding alphabet is made of two letters of unequal lengths α and β.
24
Generalized Huffman Coding
The coding alphabet is made of two letters of unequal lengths α and β. w3 w2 w1 w4
(2α + β)w1 + 2βw2 + αw3 + (α + 2β)w4
α β α β α β 24
Generalized Huffman Coding
The coding alphabet is made of two letters of unequal lengths α and β. w3 w2 w1 w4
(2α + β)w1 + 2βw2 + αw3 + (α + 2β)w4
αw3 + β(w1 + w2 + w4) α(w1 + w4) + βw2 αw1 + βw4
24
Generalized Huffman Coding
The coding alphabet is made of two letters of unequal lengths α and β. This is an Abelian Evaluation Trees problem with: ❼ xi = wi and X = N ❼ c(x, y) = αx + βy ❼ x ◦ y = x + y
24
Generalized Huffman Coding
The coding alphabet is made of two letters of unequal lengths α and β. ❼ The case α = β is Huffman Coding [Huf52]. This is solved in O(n log n) by Smallest. ❼ The case w1 = · · · = wn is solved in poly-time [Var71, GY96, CG01]. ❼ First known algorithm for the general case is an ILP [Kar61]. ❼ Dynamic programming algorithm in O
- nmax(α,β)
[GR98, BGLR02].
❼ PTAS [GMY12] No poly-time algorithm for the general case nor it is known to be NP-hard.
24
Dynamic programming
Using dynamic programming, compute for all S ⊆ {1, . . . , n} the optimal cost C(S) for ◦i∈Sxi. C(S) = min
S′⊆S,S′=∅ c
- i∈S′ xi,
- i∈S\S′ xi
- + C(S′) + C(S\S′)
It runs in 2O
(n) time and O(2n) space. 25
Integer Linear Programming (Balanced Mobiles)
Minimize
n−1
- u=1
- n
- i=1
(ℓi,u − ri,u) · wi
- subject to:
∀i, u, ℓi,u + ri,u ≤ 1 ∀i, ℓi,1 + ri,1 = 1 ∀u,
i ℓi,u > 0 and i ri,u > 0
∀i = j, ∀u,
- (1 − ℓi,u) +
v>u(ℓi,v + ri,v) ≥ ℓj,u
(1 − ri,u) +
v>u(ℓi,v + ri,v) ≥ rj,u
∀i = j, ∀u < v,
- ℓi,u + (ℓi,v + ri,v + ℓj,v + rj,v) ≤ 2 + ℓj,u
ri,u + (ℓi,v + ri,v + ℓj,v + rj,v) ≤ 2 + rj,u ∀i = j, ∀u < u′,
- 2 − ℓi,u − ℓj,u + u′
w=u+1(ℓi,w + ri,w) ≥ rj,u′ + rj,u′
2 − ri,u − rj,u + u′
w=u+1(ℓi,w + ri,w) ≥ ℓj,u′ + ℓj,u′ 26
Integer Linear Programming (Huffman Coding)
Minimize
n−1
- u=1
n
- i=1
(α · ℓi,u + β · ri,u) · wi subject to: ∀i, u, ℓi,u + ri,u ≤ 1 ∀i, ℓi,1 + ri,1 = 1 ∀u,
i ℓi,u > 0 and i ri,u > 0
∀i = j, ∀u,
- (1 − ℓi,u) +
v>u(ℓi,v + ri,v) ≥ ℓj,u
(1 − ri,u) +
v>u(ℓi,v + ri,v) ≥ rj,u
∀i = j, ∀u < v,
- ℓi,u + (ℓi,v + ri,v + ℓj,v + rj,v) ≤ 2 + ℓj,u
ri,u + (ℓi,v + ri,v + ℓj,v + rj,v) ≤ 2 + rj,u ∀i = j, ∀u < u′,
- 2 − ℓi,u − ℓj,u + u′
w=u+1(ℓi,w + ri,w) ≥ rj,u′ + rj,u′
2 − ri,u − rj,u + u′
w=u+1(ℓi,w + ri,w) ≥ ℓj,u′ + ℓj,u′ 27
R-Smallest algorithm
The R-Smallest algorithm can be used whenever the “rotation property” holds: ∀x ≤ y ≤ z, c(x, y) + c(x ◦ y, z) ≤ c(y, z) + c(y ◦ z, x) A B w1 − → A B w1
28
Enumeration of Trees
Enumerate all the leaf-labelled, unordered, full binary trees with n leaves. Bijection with perfect matchings over N = 2(n−1) vertices [Che90, BDN10]
1 2 3 4 5 6 7 8 9 10 11 12
There are N!! = O
- nn/2
such matchings.
29
Enumeration of Trees
Enumerate all the leaf-labelled, unordered, full binary trees with n leaves. Bijection with perfect matchings over N = 2(n−1) vertices [Che90, BDN10]
1 2 3 4 5 6 7 8 9 10 11 12
− →
12 11
There are N!! = O
- nn/2
such matchings.
29
Enumeration of Trees
Enumerate all the leaf-labelled, unordered, full binary trees with n leaves. Bijection with perfect matchings over N = 2(n−1) vertices [Che90, BDN10]
1 2 3 4 5 6 7 8 9 10 11 12
− →
2 12 11 10
There are N!! = O
- nn/2
such matchings.
29
Enumeration of Trees
Enumerate all the leaf-labelled, unordered, full binary trees with n leaves. Bijection with perfect matchings over N = 2(n−1) vertices [Che90, BDN10]
1 2 3 4 5 6 7 8 9 10 11 12
− →
2 4 12 11 10 9
There are N!! = O
- nn/2
such matchings.
29
Enumeration of Trees
Enumerate all the leaf-labelled, unordered, full binary trees with n leaves. Bijection with perfect matchings over N = 2(n−1) vertices [Che90, BDN10]
1 2 3 4 5 6 7 8 9 10 11 12
− →
2 4 5 12 11 10 9 8
There are N!! = O
- nn/2
such matchings.
29
Enumeration of Trees
Enumerate all the leaf-labelled, unordered, full binary trees with n leaves. Bijection with perfect matchings over N = 2(n−1) vertices [Che90, BDN10]
1 2 3 4 5 6 7 8 9 10 11 12
− →
2 4 5 1 7 12 11 10 9 8
There are N!! = O
- nn/2
such matchings.
29
Enumeration of Trees
Enumerate all the leaf-labelled, unordered, full binary trees with n leaves. Bijection with perfect matchings over N = 2(n−1) vertices [Che90, BDN10]
1 2 3 4 5 6 7 8 9 10 11 12
− →
2 4 3 6 5 1 7 12 11 10 9 8
There are N!! = O
- nn/2
such matchings.
29
Enumeration of Trees
Enumerate all the leaf-labelled, unordered, full binary trees with n leaves. Bijection with perfect matchings over N = 2(n−1) vertices [Che90, BDN10]
1 2 3 4 5 6 7 8 9 10 11 12
− → x2 x4 x3 x6 x5 x1 x7 There are N!! = O
- nn/2
such matchings.
29
Algorithms for Abelian Evaluation Trees
Time Space Dynamic Programming 2O
(n)
O(2n) Integer Programming* n2 variables and n4 constraints R-Smallest* O
- log(n)nmin(C,n)+1
O(n log n) Enumeration of Trees O
- nn/2
O(n log n)
30
Conclusion
Open questions
- 1. Is Balanced Mobiles NP-hard?
- 2. What are the polynomial-time instances of Abelian Evaluation
Trees?
- 3. For which instances is Smallest optimal?
- 4. Which instances admit an approximation scheme?
What if the shape of the mobile is fixed and one has just to find the permutation of the weights that minimizes the imbalance?
31
References i
- O. Bernardi, B. Duplantier, and P. Nadeau.
A bijection between well-labelled positive paths and matchings. In S´ eminaire Lotharingien de Combinatoire, volume 63, page B63e, 2010. Phillip G. Bradford, Mordecai J. Golin, Lawrence L. Larmore, and Wojciech Rytter. Optimal prefix-free codes for unequal letter costs: Dynamic programming with the Monge property. Journal of Algorithms, 42(2):277–303, 2002.
- V. Choi and M. J. Golin.
Lopsided trees, I: Analyses. Algorithmica, 31(3):240–290, 2001.
32
References ii
- W. Y. C. Chen.
A general bijective algorithm for trees.
- Proc. Nat. Acad. Sci. U.S.A.,, 87(24):9635—9639, 1990.
Mordecai J. Golin, Claire Mathieu, and Neal E. Young. Huffman coding with letter costs: A linear-time approximation scheme. SIAM J. Comput., 41(3):684–713, 2012.
- M. J. Golin and G. Rote.
A dynamic programming algorithm for constructing optimal prefix-free codes with unequal letter costs. IEEE Transactions on Information Theory, 44(5):1770–1781, Sep 1998.
33
References iii
Mordecai J. Golin and Neal Young. Prefix codes: Equiprobable words, unequal letter costs. SIAM Journal on Computing, 25(6):1281–1292, 1996. D.A. Huffman. A method for the construction of minimum-redundancy codes. Proceedings of the IRE, 40(9):1098–1101, Sept 1952. Richard M. Karp. Minimum-redundancy coding for the discrete noiseless channel. Information Theory, IRE Transactions on, 7(1):27–38, January 1961. Ben Varn. Optimal variable length codes (arbitrary symbol cost and equal code word probability). Information and Control, 19(4):289 – 301, 1971.
34
References iv
35
Powers-Of-Two Weights
Irregular mobiles
A mobile M is irregular if: ❼ it is an optimal mobile built on powers-of-two weights ❼ it cannot be built by Smallest ❼ its imbalance is less than the one obtained by Smallest on the same weights.
36
Irregular mobiles
A mobile M is irregular if: ❼ it is an optimal mobile built on powers-of-two weights ❼ it cannot be built by Smallest ❼ its imbalance is less than the one obtained by Smallest on the same weights. Proposition The Smallest algorithm is optimal for powers-of-two weights if and
- nly if there is no irregular mobiles.
36
A special irregular mobile
Assume by contradiction that there exist irregular mobiles. ❼ ❼
37
A special irregular mobile
Assume by contradiction that there exist irregular mobiles. Take such a mobile M with: ❼ the smallest maximum weight ❼ the smallest number of leaves (among the irregular mobiles having the smallest maximum weight) MR ML
37
A special irregular mobile
Note that: ❼ the maximum weight of M is at least 2 ❼ ❼ ❼
38
A special irregular mobile
Note that: ❼ the maximum weight of M is at least 2 ❼ M has at least one leaf of weight 1 ❼ ❼
38
A special irregular mobile
Note that: ❼ the maximum weight of M is at least 2 ❼ M has at least one leaf of weight 1 ❼ w.l.o.g. ML and MR are built by Smallest ❼
38
A special irregular mobile
Note that: ❼ the maximum weight of M is at least 2 ❼ M has at least one leaf of weight 1 ❼ w.l.o.g. ML and MR are built by Smallest ❼ ML and MR have at most one leaf of weight 1 each
38
A special irregular mobile
Note that: ❼ the maximum weight of M is at least 2 ❼ M has at least one leaf of weight 1 ❼ w.l.o.g. ML and MR are built by Smallest ❼ ML and MR have at most one leaf of weight 1 each MR ML
1 2a
First type ML
1 2a
MR
1 2b
Second type
38
First possible shape
MR ML
1 2a
MR ML
2 2a
Mobile M+ MR ML
2a
Mobile M− ∆M = 1
2∆M+ + 1 2∆M− + 2a−1 39
First possible shape
Take the (non-optimal) mobile Ms built by Smallest: Ms,R Ms,L
1 2b
40
First possible shape
Take the (non-optimal) mobile Ms built by Smallest: Ms,R Ms,L
1 2b
Ms,R Ms,L
2 2b
Mobile M+
s
Ms,R Ms,L
2b
Mobile M−
s
∆Ms = 1
2∆M+
s + 1
2∆M−
s + 2b−1
40
First possible shape
Note that: ❼ M+
s and M− s are also built by Smallest
❼ M+ and M− cannot be irregular ❼ 2b ≤ 2a
41
First possible shape
Note that: ❼ M+
s and M− s are also built by Smallest
❼ M+ and M− cannot be irregular ❼ 2b ≤ 2a Consequently: ∆M+
s ≤ ∆M+ and ∆M− s ≤ ∆M−
41
First possible shape
Note that: ❼ M+
s and M− s are also built by Smallest
❼ M+ and M− cannot be irregular ❼ 2b ≤ 2a Consequently: ∆M+
s ≤ ∆M+ and ∆M− s ≤ ∆M−
Thus : ∆Ms = 1 2∆M+
s + 1
2∆M−
s + 2b−1 ≤ 1
2∆M+ + 1 2∆M− + 2a−1 = ∆M It contradicts ∆Ms > ∆M.
41