Balanced Mobiles Yassine Hamoudi , Sophie Laplante , Roberto Mantaci - - PowerPoint PPT Presentation

balanced mobiles
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Balanced Mobiles

Yassine Hamoudi, Sophie Laplante, Roberto Mantaci May 17, 2017

ENS Lyon – IRIF, Paris Diderot

slide-2
SLIDE 2
  • Mobile. Calder, 1932.

1

slide-3
SLIDE 3

Introduction

A mobile M is a full binary tree in which each leaf has a (positive) weight. 5 3 2 4 15

2

slide-4
SLIDE 4

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

slide-5
SLIDE 5

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

slide-6
SLIDE 6

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

slide-7
SLIDE 7

Contents

The Smallest algorithm All-Equal Weights Integer Linear Programming The Evaluation Trees problem Conclusion

4

slide-8
SLIDE 8

The Smallest algorithm

slide-9
SLIDE 9

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

slide-10
SLIDE 10

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

slide-11
SLIDE 11

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

slide-12
SLIDE 12

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

slide-13
SLIDE 13

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

slide-14
SLIDE 14

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

slide-15
SLIDE 15

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

slide-16
SLIDE 16

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

slide-17
SLIDE 17

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

slide-18
SLIDE 18

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

slide-19
SLIDE 19

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

slide-20
SLIDE 20

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

slide-21
SLIDE 21

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

slide-22
SLIDE 22

All-Equal Weights

slide-23
SLIDE 23

∆n : optimal imbalance for the weights w1 = · · · = wn = 1 1 1 1 1 1

1 1

∆5 = 2

10

slide-24
SLIDE 24

∆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

slide-25
SLIDE 25

Partition algorithm

1 1 1 1 1 1 1

11

slide-26
SLIDE 26

Partition algorithm

1

1 1 1 1 1 1 1

11

slide-27
SLIDE 27

Partition algorithm

1 1

1 1 1 1 1 1 1

11

slide-28
SLIDE 28

Partition algorithm

1 1

1 1 1 1 1 1 1 ∆ = 2

11

slide-29
SLIDE 29

First recurrence relation for ∆n

The optimal imbalance ∆n verifies:      ∆1 = 0 ∆2n = 2∆n ∆2n+1 = 1 + ∆n + ∆n+1

12

slide-30
SLIDE 30

Smallest algorithm

1 1 1 1 1 1 1 1 1

1 1 1

A mobile over 9 weights, built with Smallest.

13

slide-31
SLIDE 31

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

slide-32
SLIDE 32

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

slide-33
SLIDE 33

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

slide-34
SLIDE 34

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

slide-35
SLIDE 35

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

slide-36
SLIDE 36

Second recurrence relation for ∆n

The imbalance Sn obtained by Smallest verifies:

  • S1 = 0

Sn+1 = Sn + |n|0 − |n|1 + 1

14

slide-37
SLIDE 37

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

slide-38
SLIDE 38

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

slide-39
SLIDE 39

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

slide-40
SLIDE 40

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

slide-41
SLIDE 41

Integer Linear Programming

slide-42
SLIDE 42

w1 w2 w3 w4 w5

16

slide-43
SLIDE 43

1 2 3 4

w1 w2 w3 w4 w5

16

slide-44
SLIDE 44

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

slide-45
SLIDE 45

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
slide-46
SLIDE 46

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

slide-47
SLIDE 47

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

slide-48
SLIDE 48

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

slide-49
SLIDE 49

The Evaluation Trees problem

slide-50
SLIDE 50

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

slide-51
SLIDE 51

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

slide-52
SLIDE 52

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

slide-53
SLIDE 53

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

slide-54
SLIDE 54

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

slide-55
SLIDE 55

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

slide-56
SLIDE 56

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

slide-57
SLIDE 57

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

slide-58
SLIDE 58

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

slide-59
SLIDE 59

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

slide-60
SLIDE 60

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

slide-61
SLIDE 61

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

slide-62
SLIDE 62

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

slide-63
SLIDE 63

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

slide-64
SLIDE 64

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

slide-65
SLIDE 65

Generalized Huffman Coding

The coding alphabet is made of two letters of unequal lengths α and β.

24

slide-66
SLIDE 66

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

slide-67
SLIDE 67

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

slide-68
SLIDE 68

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

slide-69
SLIDE 69

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

slide-70
SLIDE 70

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

slide-71
SLIDE 71

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

slide-72
SLIDE 72

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

slide-73
SLIDE 73

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

slide-74
SLIDE 74

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

slide-75
SLIDE 75

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

slide-76
SLIDE 76

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

slide-77
SLIDE 77

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

slide-78
SLIDE 78

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

slide-79
SLIDE 79

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

slide-80
SLIDE 80

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

slide-81
SLIDE 81

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

slide-82
SLIDE 82

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

slide-83
SLIDE 83

Conclusion

slide-84
SLIDE 84

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

slide-85
SLIDE 85

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

slide-86
SLIDE 86

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

slide-87
SLIDE 87

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

slide-88
SLIDE 88

References iv

35

slide-89
SLIDE 89

Powers-Of-Two Weights

slide-90
SLIDE 90

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

slide-91
SLIDE 91

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

slide-92
SLIDE 92

A special irregular mobile

Assume by contradiction that there exist irregular mobiles. ❼ ❼

37

slide-93
SLIDE 93

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

slide-94
SLIDE 94

A special irregular mobile

Note that: ❼ the maximum weight of M is at least 2 ❼ ❼ ❼

38

slide-95
SLIDE 95

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

slide-96
SLIDE 96

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

slide-97
SLIDE 97

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

slide-98
SLIDE 98

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

slide-99
SLIDE 99

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

slide-100
SLIDE 100

First possible shape

Take the (non-optimal) mobile Ms built by Smallest: Ms,R Ms,L

1 2b

40

slide-101
SLIDE 101

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

slide-102
SLIDE 102

First possible shape

Note that: ❼ M+

s and M− s are also built by Smallest

❼ M+ and M− cannot be irregular ❼ 2b ≤ 2a

41

slide-103
SLIDE 103

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

slide-104
SLIDE 104

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