The algorithm of Garsia and Wachs - PowerPoint PPT Presentation

About This Presentation
Title:

The algorithm of Garsia and Wachs

Description:

We are after a binary tree with w1, w2 . . . . wn at the leaves from left to right such that ... Otherwise, we delete b1 and b2 from B and combine them to create b' ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 60
Provided by: abula5
Category:

less

Transcript and Presenter's Notes

Title: The algorithm of Garsia and Wachs


1
The algorithm of Garsia and Wachs
Presentation by a more recent proof of Karpinski
et al.
2
The problem
  • We will identify the items with their weights w1,
    w2 . . . . wn , wi 0
  • We are after a binary tree with w1, w2 . . . . wn
    at the leaves from left to right such that

depth(i)
is minimized
3
Observation 1
  • If we new the dis (depths) then we could build
    the tree easily in O(n) time






2
4
4
1
3
4
Observation 1 (Cont)
  • So we will focus on how to find the depths

1
2
3





2
3
4
4
1
5
Definitions
6
The algorithm
13
8
5
7
6
9
14
7
The algorithm (in words)
Combine an LMP put the resulting node right
before the first node to the right which is
larger or equal
Claim The depths defined by the resulting tree
are the depths of an optimal alphabetic tree.
Ok, great, suppose we believe it, how do we
implement this efficiently ?
8
Implementation (Bob Tarjan)
We will always combine the rightmost LMP.
  • Maintain the current list of weights broken into
    sublists and singletons. The following invariant
    should hold
  • In a list of length at least 3 aj aj2
  • In a list of length at least 2 the next to last
    element is smaller than the element following the
    list.

9
Where can we have LMP
  • All pairs in a list except the leftmost are not
    LMPs.
  • If the list is of length at least 2 then the
  • Rightmost element and the following on are not
    LMP.

10
Implementation (Cont)
We pick the last two lists A and B and check
whether b1 and b2 are LMP. If not we simply
catenate A and B and repeat. Otherwise, we delete
b1 and b2 from B and combine them to create b.
We search for the first item in B which is no
smaller than b We split B just before that item
that item to B1 and B2 and add b to the end of B1
11
Implementation (Cont)
We represent sublists as search tree
12
Implementation (Cont)
13
8
5
7
6
9
14
7
6
9
5
14
8
13
5
7
7
9
14
We can find the first item from the left that is
greater than or equal to some value in
logarithmic time
13
Implementation (Cont)
7
6
9
5
14
8
13
5
7
7
9
14
14
Implementation
Each combination of LMP triggers a constant
number of search tree operations. (2 deletion,
search, split, insertion)
Number of sublists is O(n), since there are n
items and n-1 combinations of LMPs. Therefore the
number of catenations is O(n)
Total running time is therefore O(nlogn)
15
  • But why does this algorithm produce the optimal
    tree ??

16
Notation
17
Definitions (Cont)
18
Theorem 1 (correctness of GW)
By induction on the length of the sequence,
correctness reduces to
19
We will prove more
lexi trees over p
opt
20
lexi trees over p
A
opt
21
lexi trees over p
lexi trees over p such that i, i1, are at the
same depth
opt
opt
22
B
lexi trees over p
lexi trees over p such that i, i1, are at the
same depth
opt
opt
23
C
lexi trees over p
lexi trees over p such that i, i1, are at the
same depth
opt
opt
24
C
lexi trees over p
lexi trees over p such that i, i1, are at the
same depth
opt
opt
25
Theorem 1 (correctness of GW)
26
Theorem 1 (correctness of GW)
Let T be an opt. lexi. over pi,j among all trees
where i and i1 are siblings
gt T is an opt. lexi. over pi,j among all trees
where i and i1 have the same level
gt There is T opt. lexi. over p among trees
where i and i1 have the same level, such that T
? T
gt T is opt. over p
27
Shift Operations
28
LeftShift Example
29
LeftShift Example
30
LeftShift Example
31
LeftShift Example
32
LeftShift Example
33
LeftShift Example
34
LeftShift Example
35
LeftShift Example
36
LeftShift Example
37
Shift Operations
38
lexi trees over p
A
opt
39
Proof of A
There is an optimal lexi tree in which i, and i1
are at the same level.
40
(No Transcript)
41
B
lexi trees over p
lexi trees over p such that i, i1, are at the
same depth
opt
opt
42
Proof of B
Among optimal trees over p in which i, and i1
are on the same level there is one in which they
are siblings.
So T is also optimal
43
Definition of Well Shaped Segments
  • A set S of leaves of T is h-isolated iff
  • For any u?S, depthT(u) h
  • For any u?S, w?S, depthT(LCA(u,w)) h

44
Definition of Well Shaped Segments
Si,j is left well shaped iff it is h-isolated
and depthT(i) depthT(i1) h1
Si,j is right well shaped iff it is
h-isolated and depthT(j)
depthT(j1) h1
Active Window
45
Movability Lemma
If the segment i,,j is left well shaped, then
the active pair (i,i1) can be moved to the other
side of the segment by locally rearranging
sub-trees in the active window without changing
the relative order of the other items and
without changing the depth function of the tree.
(similar lemma holds for segments which are
right well shaped)
46
Movability Lemma
47
Movability Lemma
48
Movability Lemma
49
Movability Lemma
50
Movability Lemma
51
Movability Lemma
52
Movability Lemma
53
Movability Lemma
54
Movability Lemma
55
Movability Lemma
56
Movability Lemma
57
Movability Lemma
58
The main theorem to establish C
THM (a) if T is optimal over p such that i,
i1 are at the same depth then the segment
i,.,j is left well shaped in T
(b) if T is optimal over p such that i, i1
are at the same depth then the segment
i2,.,j,i,i1 is right well shaped in T
Focus on (a)
59
Proof
  • First we have to show that every leaf u?i,,j,
    depth(u) h
  • where h depth(i)-1 depth(i1)-1

60
(No Transcript)
61
(No Transcript)
62
(No Transcript)
63
(No Transcript)
64
(No Transcript)
65
(No Transcript)
66
Homework
  • To finish we have to consider one more case where
    i, and i1 are siblings.
  • We also have to prove that depthT(LCA(j,j1)) h
  • Case (b) of the THM is similar

67
Hu-Tucker Algorithm
Transparent items and opaque items
Compatible pair No opaque items in the middle
Minimal compatible pair (mcp) compatible pair
(i,i1) where Weight(i) weight(i1) is minimal
Tie Breaking Rule
68
Hu-Tucker Algorithm
69
Hu-Tucker Algorithm
70
Hu-Tucker Algorithm
71
Hu-Tucker Algorithm
Write a Comment
User Comments (0)
About PowerShow.com