new results on binary comparison search treesgolin/talks/bcst_talk.pdfhu-tucker binary comparison...

172
New Results on Binary Comparison Search Trees 1 Marek Chrobak, Neal Young UC Riverside Ian Munro U Waterloo Mordecai Golin HKUST

Upload: others

Post on 13-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

New Results on Binary Comparison

Search Trees

1

Marek Chrobak, Neal Young UC Riverside

Ian Munro U Waterloo

Mordecai Golin HKUST

Page 2: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Early version of paper at arxiv.org

Optimal search trees with 2-way comparisons Marek Chrobak, Mordecai Golin, J. Ian Munro, Neal E. Young arXiv:1505.00357

2

Page 3: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

3

Main ResultConstructing Min-Cost Binary Comparison Search Trees

Page 4: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

3

Main ResultConstructing Min-Cost Binary Comparison Search Trees

Wasn’t this completely understood 45 years ago??!!

Page 5: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

3

Main ResultConstructing Min-Cost Binary Comparison Search Trees

Wasn’t this completely understood 45 years ago??!!

Yes and No …

Page 6: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Outline• History

• Binary Search Trees • Hu-Tucker Trees • AKKL Trees

• Optimal Binary Comparison Search Trees with Failures • Problem Models • List of New Results

• New Results • The Main Lemma • Structural Properties of OBCSTs • Dynamic Programming for OBCSTs • Proof of The Main Lemma (Sketch)

• Extensions and Open Problems

4

Page 7: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs

5

Page 8: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs • Knuth [1971] gave algorithm for constructing Optimal Binary

Search Trees

5

Page 9: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs • Knuth [1971] gave algorithm for constructing Optimal Binary

Search Trees

• Known: n keys K1, K2, …., Kn.

5

Page 10: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs • Knuth [1971] gave algorithm for constructing Optimal Binary

Search Trees

• Known: n keys K1, K2, …., Kn.

• Preprocess keys to create binary tree. Tree query compares query value Q to keys. and returns appropriate response from

• i such that Q = Ki

• i such that Ki < Q < Ki+1

• Q < K1 or Kn < Q

5

Page 11: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs • Knuth [1971] gave algorithm for constructing Optimal Binary

Search Trees

• Known: n keys K1, K2, …., Kn.

• Preprocess keys to create binary tree. Tree query compares query value Q to keys. and returns appropriate response from

• i such that Q = Ki

• i such that Ki < Q < Ki+1

• Q < K1 or Kn < Q

• Input: probability of successful and unsuccessful searches

5

�1,�2, . . . ,�n and ↵0,↵1, . . . ,↵n

�i = Pr(Q = Ki) ↵i = Pr(Ki < Q < Ki+1)

Page 12: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

6

Knuth’s Optimal BSTs

Page 13: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

6

Knuth’s Optimal BSTs

Q=A?

Q=C?Q<A

Q=B? C<Q

B<Q<CA<Q<B

α0

α1 α2

α3

β1

β3

β2

Q=B?

Q=C?Q=A?

C<QA<Q<BQ<A B<Q<C

β1

β2

β3

α0 α1 α2 α3

Page 14: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

6

Knuth’s Optimal BSTs

Q=A?

Q=C?Q<A

Q=B? C<Q

B<Q<CA<Q<B

α0

α1 α2

α3

β1

β3

β2

Q=B?

Q=C?Q=A?

C<QA<Q<BQ<A B<Q<C

β1

β2

β3

α0 α1 α2 α3

�1,�2, . . . ,�n and ↵0,↵1, . . . ,↵n

�i = Pr(Q = Ki) ↵i = Pr(Ki < Q < Ki+1)

Page 15: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs

7

Page 16: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs • Knuth [1971] gave algorithm for constructing Optimal Binary Search Trees

7

Page 17: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs • Knuth [1971] gave algorithm for constructing Optimal Binary Search Trees

• Input was probability of successful and unsuccessful searches

�1,�2, . . . ,�n and ↵0,↵1, . . . ,↵n

7

Page 18: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs • Knuth [1971] gave algorithm for constructing Optimal Binary Search Trees

• Input was probability of successful and unsuccessful searches

�i = Pr(Q = Ki)

�1,�2, . . . ,�n and ↵0,↵1, . . . ,↵n

↵i = Pr(Ki < Q < Ki+1)

7

Page 19: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs • Knuth [1971] gave algorithm for constructing Optimal Binary Search Trees

• Input was probability of successful and unsuccessful searches

• Cost of tree was average path length

�i = Pr(Q = Ki)

�1,�2, . . . ,�n and ↵0,↵1, . . . ,↵n

↵i = Pr(Ki < Q < Ki+1)

7

Page 20: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs • Knuth [1971] gave algorithm for constructing Optimal Binary Search Trees

• Input was probability of successful and unsuccessful searches

• Cost of tree was average path length

�i = Pr(Q = Ki)

�1,�2, . . . ,�n and ↵0,↵1, . . . ,↵n

↵i = Pr(Ki < Q < Ki+1)

7

nX

i=1

�i depth(�i) +nX

i=0

↵i depth(↵i)

Page 21: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs • Knuth [1971] gave algorithm for constructing Optimal Binary Search Trees

• Input was probability of successful and unsuccessful searches

• Cost of tree was average path length

• Dynamic Programming Algorithm

• Constructed O(n^2) DP table

• Knuth reduced O(n^3) running time to O(n^2)

• Technique later generalized as Quadrangle Inequality method by F. Yao

�i = Pr(Q = Ki)

�1,�2, . . . ,�n and ↵0,↵1, . . . ,↵n

↵i = Pr(Ki < Q < Ki+1)

7

nX

i=1

�i depth(�i) +nX

i=0

↵i depth(↵i)

Page 22: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs

8

Page 23: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs

Q=A?

Q=C?Q<A

Q=B? C<Q

B<Q<CA<Q<B

α0

α1 α2

α3

β1

β3

β2

Q=B?

Q=C?Q=A?

C<QA<Q<BQ<A B<Q<C

β1

β2

β3

α0 α1 α2 α3

8

Page 24: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs

Q=A?

Q=C?Q<A

Q=B? C<Q

B<Q<CA<Q<B

α0

α1 α2

α3

β1

β3

β2

Q=B?

Q=C?Q=A?

C<QA<Q<BQ<A B<Q<C

β1

β2

β3

α0 α1 α2 α3

(�1 + �3) + 2(↵0 + ↵1 + ↵2 + ↵3)(↵0 + �3) + 2(�2 + ↵3) + 3(↵1 + ↵2)

8

Page 25: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs

Q=A?

Q=C?Q<A

Q=B? C<Q

B<Q<CA<Q<B

α0

α1 α2

α3

β1

β3

β2

Q=B?

Q=C?Q=A?

C<QA<Q<BQ<A B<Q<C

β1

β2

β3

α0 α1 α2 α3

(�1 + �3) + 2(↵0 + ↵1 + ↵2 + ↵3)(↵0 + �3) + 2(�2 + ↵3) + 3(↵1 + ↵2)

(�1,�2,�3) = (.5, .1, .2)

↵i ⌘ .05 Cost = 0.85 Cost = 1.10

8

Page 26: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Knuth’s Optimal BSTs

Q=A?

Q=C?Q<A

Q=B? C<Q

B<Q<CA<Q<B

α0

α1 α2

α3

β1

β3

β2

Q=B?

Q=C?Q=A?

C<QA<Q<BQ<A B<Q<C

β1

β2

β3

α0 α1 α2 α3

(�1 + �3) + 2(↵0 + ↵1 + ↵2 + ↵3)(↵0 + �3) + 2(�2 + ↵3) + 3(↵1 + ↵2)

(�1,�2,�3) = (.5, .1, .2)

↵i ⌘ .05

(↵1,↵2,↵3,↵4) = (0.7, 0.1, 0.1, 0.1)

(�1,�2,�3) = (.3, .3, .3)

Cost = 0.85

Cost = 1.05

Cost = 1.10

Cost = 0.80

8

Page 27: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Hu-Tucker Binary Comparison Search Trees

9

Page 28: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Hu-Tucker Binary Comparison Search Trees

• Knuth constructed optimal binary search trees

9

Q=B

Q<B B<Q

Page 29: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Hu-Tucker Binary Comparison Search Trees

• Knuth constructed optimal binary search trees

9

Q=B

Q<B B<Q

Q<BQ=B

Q<B B<Q

B

• Trees structure was binary but nodes used ternary comparisons. Each node needed two binary comparisons to implement the search

Page 30: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Hu-Tucker Binary Comparison Search Trees

• Knuth constructed optimal binary search trees

9

Q=B

Q<B B<Q

Q<BQ=B

Q<B B<Q

B

• Trees structure was binary but nodes used ternary comparisons. Each node needed two binary comparisons to implement the search

• In a binary comparison search tree, each internal node performs only one comparison. Searches all terminate at leaves.

• First such trees constructed by Hu-Tucker, also in 1971. O(n log n)

Page 31: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Hu-Tucker Binary Comparison Search Trees

10

Page 32: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Hu-Tucker Binary Comparison Search Trees

10

Q<C

Q<DQ<B

DBA Cβ1 β2 β3 β4

Q<D

Q<C

Q<B

D

B

A

C

β1

β2 β3

β4

Page 33: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Hu-Tucker Binary Comparison Search Trees

10

• Hu Tucker (1971) & Garsia-Wachs (1977)• Assumes all searches are successful;

no failures allowed. Input is only β1, β2, …, βn, with no αi s.

Q<C

Q<DQ<B

DBA Cβ1 β2 β3 β4

Q<D

Q<C

Q<B

D

B

A

C

β1

β2 β3

β4

Page 34: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Hu-Tucker Binary Comparison Search Trees

10

• Hu Tucker (1971) & Garsia-Wachs (1977)• Assumes all searches are successful;

no failures allowed. Input is only β1, β2, …, βn, with no αi s.

• Internal nodes are < comparisons. Searches all terminate at leaves

Q<C

Q<DQ<B

DBA Cβ1 β2 β3 β4

Q<D

Q<C

Q<B

D

B

A

C

β1

β2 β3

β4

Page 35: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Hu-Tucker Binary Comparison Search Trees

10

• Hu Tucker (1971) & Garsia-Wachs (1977)• Assumes all searches are successful;

no failures allowed. Input is only β1, β2, …, βn, with no αi s.

• Internal nodes are < comparisons. Searches all terminate at leaves

• Problem is to find tree with minimum weighted (average) external path length

Q<C

Q<DQ<B

DBA Cβ1 β2 β3 β4

Q<D

Q<C

Q<B

D

B

A

C

β1

β2 β3

β4

Page 36: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Hu-Tucker Binary Comparison Search Trees

10

• Hu Tucker (1971) & Garsia-Wachs (1977)• Assumes all searches are successful;

no failures allowed. Input is only β1, β2, …, βn, with no αi s.

• Internal nodes are < comparisons. Searches all terminate at leaves

• Problem is to find tree with minimum weighted (average) external path length

• O(n log n) algorithm

Q<C

Q<DQ<B

DBA Cβ1 β2 β3 β4

Q<D

Q<C

Q<B

D

B

A

C

β1

β2 β3

β4

Page 37: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Outline• History

• Binary Search Trees • Hu-Tucker Trees • AKKL Trees

• Optimal Binary Comparison Search Trees with Failures • Problem Models • List of New Results

• New Results • The Main Lemma • Structural Properties of OBCSTs • Dynamic Programming for OBCSTs • Proof of The Main Lemma (Sketch)

• Extensions and Open Problems

11

Page 38: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

12

Adding Equality Comparisons

Page 39: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

12

Adding Equality Comparisons The Knuth trees use three-way comparisons at each node. These are implemented in modern machines using two two-way comparisons (one < and one =). Hu-Tucker trees use only one two-way comparison (a <) at each node.

Page 40: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

12

Adding Equality Comparisons

. . . machines that cannot make three-way comparisons at once. . . will have to make two comparisons. . . it may well be best to have a binary tree whose internal nodes specify either an equality test or a less-than test but not both.

The Knuth trees use three-way comparisons at each node. These are implemented in modern machines using two two-way comparisons (one < and one =). Hu-Tucker trees use only one two-way comparison (a <) at each node.

Page 41: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

12

Adding Equality Comparisons

D. E. Knuth. The Art of Computer Programming, Volume 3: Sorting and Searching. Addison-Wesley, 2nd edition, 1998. [§6.2.2 ex. 33],

. . . machines that cannot make three-way comparisons at once. . . will have to make two comparisons. . . it may well be best to have a binary tree whose internal nodes specify either an equality test or a less-than test but not both.

The Knuth trees use three-way comparisons at each node. These are implemented in modern machines using two two-way comparisons (one < and one =). Hu-Tucker trees use only one two-way comparison (a <) at each node.

Page 42: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

13

Adding Equality Comparisons: AKKL[2001]

Page 43: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

13

Adding Equality Comparisons: AKKL[2001]

Q<D

Q<C

Q<B

D

B

A

C

β1

β2 β3

β4

Q<D

Q<C

Q=B

D

A

B

C

y n

n

n

y

y

β1

β2 β3

β4

Hu-Tucker Tree AKKL Tree

• AKKL trees are min cost trees with more power. instead of being restricted to be <, comparisons can be = OR <

Page 44: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

13

Adding Equality Comparisons: AKKL[2001]

Q<D

Q<C

Q<B

D

B

A

C

β1

β2 β3

β4

Q<D

Q<C

Q=B

D

A

B

C

y n

n

n

y

y

β1

β2 β3

β4

Hu-Tucker Tree AKKL Tree

• AKKL trees are min cost trees with more power. instead of being restricted to be <, comparisons can be = OR <

• AKKL trees include HT Trees

Page 45: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

13

Adding Equality Comparisons: AKKL[2001]

Q<D

Q<C

Q<B

D

B

A

C

β1

β2 β3

β4

Q<D

Q<C

Q=B

D

A

B

C

y n

n

n

y

y

β1

β2 β3

β4

Hu-Tucker Tree AKKL Tree

• AKKL trees are min cost trees with more power. instead of being restricted to be <, comparisons can be = OR <

• AKKL trees include HT Trees• AKKL trees can be cheaper than HT Trees if some βi much larger

than others

Page 46: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

13

Adding Equality Comparisons: AKKL[2001]

Q<D

Q<C

Q<B

D

B

A

C

β1

β2 β3

β4

Q<D

Q<C

Q=B

D

A

B

C

y n

n

n

y

y

β1

β2 β3

β4

Hu-Tucker Tree AKKL Tree

• AKKL trees are min cost trees with more power. instead of being restricted to be <, comparisons can be = OR <

• AKKL trees include HT Trees• AKKL trees can be cheaper than HT Trees if some βi much larger

than others• AKKL trees more difficult to construct

Page 47: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

14

Adding Equality Comparisons: AKKL[2001]

Page 48: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

• Anderson, Kannan, Karloff, Ladner [2002] extended Hu-Tucker by allowing = comparisons. AKKL find min-cost tree when the n-1 internal node comparisons are allowed to be in {=,<}.

14

Adding Equality Comparisons: AKKL[2001]

Page 49: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

• Anderson, Kannan, Karloff, Ladner [2002] extended Hu-Tucker by allowing = comparisons. AKKL find min-cost tree when the n-1 internal node comparisons are allowed to be in {=,<}.

• Useful when some βi are very large (relatively)

14

Adding Equality Comparisons: AKKL[2001]

Page 50: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

• Anderson, Kannan, Karloff, Ladner [2002] extended Hu-Tucker by allowing = comparisons. AKKL find min-cost tree when the n-1 internal node comparisons are allowed to be in {=,<}.

• Useful when some βi are very large (relatively)

• AKKL algorithm runs in O(n4) time.

14

Adding Equality Comparisons: AKKL[2001]

Page 51: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

• Anderson, Kannan, Karloff, Ladner [2002] extended Hu-Tucker by allowing = comparisons. AKKL find min-cost tree when the n-1 internal node comparisons are allowed to be in {=,<}.

• Useful when some βi are very large (relatively)

• AKKL algorithm runs in O(n4) time.• AKKL note this improves running time of O(n5) claimed by Spuler [1994]

in his thesis

14

Adding Equality Comparisons: AKKL[2001]

Page 52: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

• Anderson, Kannan, Karloff, Ladner [2002] extended Hu-Tucker by allowing = comparisons. AKKL find min-cost tree when the n-1 internal node comparisons are allowed to be in {=,<}.

• Useful when some βi are very large (relatively)

• AKKL algorithm runs in O(n4) time.• AKKL note this improves running time of O(n5) claimed by Spuler [1994]

in his thesis• Spuler only states O(n5) algorithm but doesn’t prove that it produces

optimal tree, so AKKL is really first polynomial time algorithm

14

Adding Equality Comparisons: AKKL[2001]

Page 53: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

• Anderson, Kannan, Karloff, Ladner [2002] extended Hu-Tucker by allowing = comparisons. AKKL find min-cost tree when the n-1 internal node comparisons are allowed to be in {=,<}.

• Useful when some βi are very large (relatively)

• AKKL algorithm runs in O(n4) time.• AKKL note this improves running time of O(n5) claimed by Spuler [1994]

in his thesis• Spuler only states O(n5) algorithm but doesn’t prove that it produces

optimal tree, so AKKL is really first polynomial time algorithm

• Reason problem is difficult is that equality nodes can create holes in ranges. This could dramatically (exponentially?) increase search space, destroying DP approach

14

Adding Equality Comparisons: AKKL[2001]

Page 54: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

• Anderson, Kannan, Karloff, Ladner [2002] extended Hu-Tucker by allowing = comparisons. AKKL find min-cost tree when the n-1 internal node comparisons are allowed to be in {=,<}.

• Useful when some βi are very large (relatively)

• AKKL algorithm runs in O(n4) time.• AKKL note this improves running time of O(n5) claimed by Spuler [1994]

in his thesis• Spuler only states O(n5) algorithm but doesn’t prove that it produces

optimal tree, so AKKL is really first polynomial time algorithm

• Reason problem is difficult is that equality nodes can create holes in ranges. This could dramatically (exponentially?) increase search space, destroying DP approach• AKKL show that if equality comparison exists, then it is always largest

probability in range. Allows recovering DP approach with ranges of description size O(n3) (compared to Knuth’s O(n2))

14

Adding Equality Comparisons: AKKL[2001]

Page 55: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

15

Adding Equality Comparisons: AKKL[2001]

Q<D

Q<C

Q<B

D

B

A

C

β1

β2 β3

β4

Q<D

Q<C

Q=B

D

A

B

C

y n

n

n

y

y

β1

β2 β3

β4

Hu-Tucker Tree AKKL Tree

• Comment 1 : Other problem in AKKL is how to deal with repeated weights This was hardest part.

• Comment 2: Both Hu-Tucker and AKKL only work when failures don’t occur.I.e., only βi are allowed and not αi.

Page 56: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

16

So Far + Obvious Open Problem

Page 57: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

16

So Far + Obvious Open Problem • Optimal Binary Search Trees

• Input: • O(n2) Knuth

• Optimal Binary Comparison Search Trees • Input: • C = {<}: O(n logn) Hu-Tucker & Garsia-Wachs • C = {=,<}: O(n4) AKKL

�i = Pr(Q = Ki); ↵i = Pr(Ki�1 < Q < Ki)

�i = Pr(Q = Ki); failures not allowed

Page 58: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

16

So Far + Obvious Open Problem • Optimal Binary Search Trees

• Input: • O(n2) Knuth

• Optimal Binary Comparison Search Trees • Input: • C = {<}: O(n logn) Hu-Tucker & Garsia-Wachs • C = {=,<}: O(n4) AKKL

�i = Pr(Q = Ki); ↵i = Pr(Ki�1 < Q < Ki)

�i = Pr(Q = Ki); failures not allowed

• Obvious Questions • Can we build OBCSTs that allow failures?

• If yes, for which sets of comparisons? • Answer is yes, (for all sets of comparisons)

but first need to define problem models

Page 59: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Outline• History

• Binary Search Trees • Hu-Tucker Trees • AKKL Trees

• Optimal Binary Comparison Search Trees with Failures • Problem Models • List of New Results

• New Results • The Main Lemma • Structural Properties of OBCSTs • Dynamic Programming for OBCSTs • Proof of The Main Lemma (Sketch)

• Extensions and Open Problems

17

Page 60: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

18

BCSTs with Failure Probabilities

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q=BQ<A

Q<B

B<Q<CBA<Q<BQ<A

y n

nn yy

Q=A

Q<C

A

y

y

n

n

α0 α1 α2

α3 α4

β1

β2

β3 β4

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

Page 61: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

18

BCSTs with Failure Probabilities

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q=BQ<A

Q<B

B<Q<CBA<Q<BQ<A

y n

nn yy

Q=A

Q<C

A

y

y

n

n

α0 α1 α2

α3 α4

β1

β2

β3 β4

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

• Allows Failures (βi and αi). • Call this complete input. HT has restricted input.

Page 62: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

18

BCSTs with Failure Probabilities

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q=BQ<A

Q<B

B<Q<CBA<Q<BQ<A

y n

nn yy

Q=A

Q<C

A

y

y

n

n

α0 α1 α2

α3 α4

β1

β2

β3 β4

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

• Allows Failures (βi and αi). • Call this complete input. HT has restricted input.

• Tree for n keys has 2n+1 leaves

Page 63: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

18

BCSTs with Failure Probabilities

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q=BQ<A

Q<B

B<Q<CBA<Q<BQ<A

y n

nn yy

Q=A

Q<C

A

y

y

n

n

α0 α1 α2

α3 α4

β1

β2

β3 β4

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

• Allows Failures (βi and αi). • Call this complete input. HT has restricted input.

• Tree for n keys has 2n+1 leaves• Distinguishing between Q==Ki and Ki < Q < Ki+1

always requires querying (Q=Ki)

Page 64: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

19

Using Different Types of Comparisons

Q=D

Q<D

D<QD

C<Q<D

y n

ny

Q<B

Q=A

A<Q<B

A

y n

n

n

y

y

Q=C

Q≤C

C

y

y

n

n

Q=BQ<A

Q<A B B<Q<Cα0 α1 α2

α3

α4β1

β2

β3

β4

y n

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

Page 65: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

19

Using Different Types of Comparisons

• Left Tree uses {<,=}. Right Tree uses {<, ≤, =} • Minimum cost BCST is minimum taken over all trees using

given set of comparisons C, e.g., C={<,=} or C={<, ≤, =}

Q=D

Q<D

D<QD

C<Q<D

y n

ny

Q<B

Q=A

A<Q<B

A

y n

n

n

y

y

Q=C

Q≤C

C

y

y

n

n

Q=BQ<A

Q<A B B<Q<Cα0 α1 α2

α3

α4β1

β2

β3

β4

y n

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

Page 66: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

19

Using Different Types of Comparisons

• Left Tree uses {<,=}. Right Tree uses {<, ≤, =} • Minimum cost BCST is minimum taken over all trees using

given set of comparisons C, e.g., C={<,=} or C={<, ≤, =}• C is input to the problem.

• Algorithm is different for different Cs.

Q=D

Q<D

D<QD

C<Q<D

y n

ny

Q<B

Q=A

A<Q<B

A

y n

n

n

y

y

Q=C

Q≤C

C

y

y

n

n

Q=BQ<A

Q<A B B<Q<Cα0 α1 α2

α3

α4β1

β2

β3

β4

y n

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

Page 67: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

20

How Much Information is Needed for Failure?

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q=A

A Q<A OR A<Q<B OR B<Q<C

y n

Q=B

Q<C

B

y

y

n

n

α0 + α1+ α2 α3 α4

β2

β1 β3 β4

Page 68: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

20

How Much Information is Needed for Failure?

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

• Tree on left shows Explicit Failure • every failure leaf reports unique failure interval, Ki < Q < Ki+1.

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q=A

A Q<A OR A<Q<B OR B<Q<C

y n

Q=B

Q<C

B

y

y

n

n

α0 + α1+ α2 α3 α4

β2

β1 β3 β4

Page 69: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

20

How Much Information is Needed for Failure?

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

• Tree on left shows Explicit Failure • every failure leaf reports unique failure interval, Ki < Q < Ki+1.

• Tree on right shows Non-Explicit Failure: • Failure leaves only report failure. Don’t need to specify exact

interval. Leaf can be concatenation of successive failure intervals .

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q=A

A Q<A OR A<Q<B OR B<Q<C

y n

Q=B

Q<C

B

y

y

n

n

α0 + α1+ α2 α3 α4

β2

β1 β3 β4

Page 70: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

21

Permitted Comparisons Failure Type Time CommentsC = {=} Explicit — Can not occur

Non-Explicit O(n log n) Trivial. Similar to Linked ListC = {<,} Explicit O(n log n) O(n) Reduction to Hu-Tucker

Non-Explicit — Can not occurC = {=, <}, C = {=,} Explicit O(n4) Follows from Main Lemma

Non-Explicit O(n4) ”C = {=, <,} Explicit O(n4) ”

Non-Explicit O(n4) ”

• DP Algorithms for last 4 cases are very similar • Differ slightly in

• Design of Recurrence Relations • {=,<} and {=,<, ≤) yield slightly different recurrences

• Initial conditions • Explicit and Non-Explicit Failures force different I.C.s

New Algorithms: OBCSTs with Failures

Page 71: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Outline• History

• Binary Search Trees • Hu-Tucker Trees • AKKL Trees

• Optimal Binary Comparison Search Trees with Failures • Problem Models • List of New Results

• New Results • The Main Lemma • Structural Properties of OBCSTs • Dynamic Programming for OBCSTs • Proof of The Main Lemma (Sketch)

• Extensions and Open Problems

22

Page 72: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

23

Main Lemma:

Lemma Let T be a Optimal BCST. If (Q=Kk) is a Descendant of (Q=Ki) Then βk ≤βi

Q = Ki

Q = Kk

T3

Q < Kj

T1

Ki

Kk

βi

βk

Page 73: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

23

Main Lemma:

Lemma Let T be a Optimal BCST. If (Q=Kk) is a Descendant of (Q=Ki) Then βk ≤βi

Note: This is true regardless of which inequality comparisons are used and which model BCST is used

Q = Ki

Q = Kk

T3

Q < Kj

T1

Ki

Kk

βi

βk

Page 74: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

23

Main Lemma:

Lemma Let T be a Optimal BCST. If (Q=Kk) is a Descendant of (Q=Ki) Then βk ≤βi

Note: This is true regardless of which inequality comparisons are used and which model BCST is used

Corollary: If T is an OBCST and (Q=Kk) an internal node in T, then βk ≤ βj for all (Q=Kj) on the path from the root to (Q=Kk),i.e., equality weights decrease walking down the tree

Q = Ki

Q = Kk

T3

Q < Kj

T1

Ki

Kk

βi

βk

Page 75: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Outline• History

• Binary Search Trees • Hu-Tucker Trees • AKKL Trees

• Optimal Binary Comparison Search Trees with Failures • Problem Models • List of New Results

• New Results • The Main Lemma • Structural Properties of OBCSTs • Dynamic Programming for OBCSTs • Proof of The Main Lemma (Sketch)

• Extensions and Open Problems

24

Page 76: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

25

Structural Properties of BCSTs

Page 77: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

25

Structural Properties of BCSTs Henceforth assume distinct key weights, i.e., all of the β1, β2, …, βn are differentAlso assume C={<,=}

Page 78: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

25

Structural Properties of BCSTs Henceforth assume distinct key weights, i.e., all of the β1, β2, …, βn are differentAlso assume C={<,=}

Every tree node N corresponds to search range of subtree rooted at N

Page 79: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

25

Structural Properties of BCSTs Henceforth assume distinct key weights, i.e., all of the β1, β2, …, βn are differentAlso assume C={<,=}

Every tree node N corresponds to search range of subtree rooted at N• Root of BSCT is search range [K0,Kn+1)

(where K0=-∞ and Kn+1=∞)

Page 80: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

25

Structural Properties of BCSTs Henceforth assume distinct key weights, i.e., all of the β1, β2, …, βn are differentAlso assume C={<,=}

Every tree node N corresponds to search range of subtree rooted at N• Root of BSCT is search range [K0,Kn+1)

(where K0=-∞ and Kn+1=∞)• Comparisons cuts ranges

• A (Q<Ki) splits [Ki,Kj) into [Ki,Kk) and [Kk,Ki) • A (Q=Ki) removing Ki from range,

Page 81: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

25

Structural Properties of BCSTs Henceforth assume distinct key weights, i.e., all of the β1, β2, …, βn are differentAlso assume C={<,=}

Every tree node N corresponds to search range of subtree rooted at N• Root of BSCT is search range [K0,Kn+1)

(where K0=-∞ and Kn+1=∞)• Comparisons cuts ranges

• A (Q<Ki) splits [Ki,Kj) into [Ki,Kk) and [Kk,Ki) • A (Q=Ki) removing Ki from range,

• Range of subtree rooted at N is some [Ki,Kj) with some keys removed

Page 82: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

25

Structural Properties of BCSTs Henceforth assume distinct key weights, i.e., all of the β1, β2, …, βn are differentAlso assume C={<,=}

Every tree node N corresponds to search range of subtree rooted at N• Root of BSCT is search range [K0,Kn+1)

(where K0=-∞ and Kn+1=∞)• Comparisons cuts ranges

• A (Q<Ki) splits [Ki,Kj) into [Ki,Kk) and [Kk,Ki) • A (Q=Ki) removing Ki from range,

• Range of subtree rooted at N is some [Ki,Kj) with some keys removed

• Keys removed (holes) are Kk s.t. (Q=Kk) is on the path from N to the root of T.

Page 83: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

25

Structural Properties of BCSTs Henceforth assume distinct key weights, i.e., all of the β1, β2, …, βn are differentAlso assume C={<,=}

Every tree node N corresponds to search range of subtree rooted at N• Root of BSCT is search range [K0,Kn+1)

(where K0=-∞ and Kn+1=∞)• Comparisons cuts ranges

• A (Q<Ki) splits [Ki,Kj) into [Ki,Kk) and [Kk,Ki) • A (Q=Ki) removing Ki from range,

• Range of subtree rooted at N is some [Ki,Kj) with some keys removed

• Keys removed (holes) are Kk s.t. (Q=Kk) is on the path from N to the root of T.

[-∞,∞)

Page 84: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

25

Structural Properties of BCSTs Henceforth assume distinct key weights, i.e., all of the β1, β2, …, βn are differentAlso assume C={<,=}

Every tree node N corresponds to search range of subtree rooted at N• Root of BSCT is search range [K0,Kn+1)

(where K0=-∞ and Kn+1=∞)• Comparisons cuts ranges

• A (Q<Ki) splits [Ki,Kj) into [Ki,Kk) and [Kk,Ki) • A (Q=Ki) removing Ki from range,

• Range of subtree rooted at N is some [Ki,Kj) with some keys removed

• Keys removed (holes) are Kk s.t. (Q=Kk) is on the path from N to the root of T.

[-∞,∞)

[-∞,C) [C,∞)

Page 85: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

25

Structural Properties of BCSTs Henceforth assume distinct key weights, i.e., all of the β1, β2, …, βn are differentAlso assume C={<,=}

Every tree node N corresponds to search range of subtree rooted at N• Root of BSCT is search range [K0,Kn+1)

(where K0=-∞ and Kn+1=∞)• Comparisons cuts ranges

• A (Q<Ki) splits [Ki,Kj) into [Ki,Kk) and [Kk,Ki) • A (Q=Ki) removing Ki from range,

• Range of subtree rooted at N is some [Ki,Kj) with some keys removed

• Keys removed (holes) are Kk s.t. (Q=Kk) is on the path from N to the root of T.

[-∞,∞)

[-∞,C) [C,∞)

[-∞,C)-{B}

Page 86: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

25

Structural Properties of BCSTs Henceforth assume distinct key weights, i.e., all of the β1, β2, …, βn are differentAlso assume C={<,=}

Every tree node N corresponds to search range of subtree rooted at N• Root of BSCT is search range [K0,Kn+1)

(where K0=-∞ and Kn+1=∞)• Comparisons cuts ranges

• A (Q<Ki) splits [Ki,Kj) into [Ki,Kk) and [Kk,Ki) • A (Q=Ki) removing Ki from range,

• Range of subtree rooted at N is some [Ki,Kj) with some keys removed

• Keys removed (holes) are Kk s.t. (Q=Kk) is on the path from N to the root of T.

[-∞,∞)

[-∞,C) [C,∞)

[-∞,C)-{B} [C,D) [D,∞)

Page 87: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

25

Structural Properties of BCSTs Henceforth assume distinct key weights, i.e., all of the β1, β2, …, βn are differentAlso assume C={<,=}

Every tree node N corresponds to search range of subtree rooted at N• Root of BSCT is search range [K0,Kn+1)

(where K0=-∞ and Kn+1=∞)• Comparisons cuts ranges

• A (Q<Ki) splits [Ki,Kj) into [Ki,Kk) and [Kk,Ki) • A (Q=Ki) removing Ki from range,

• Range of subtree rooted at N is some [Ki,Kj) with some keys removed

• Keys removed (holes) are Kk s.t. (Q=Kk) is on the path from N to the root of T.

[-∞,∞)

[-∞,C) [C,∞)

[-∞,C)-{B}

[-∞,C)-{A,B}

[C,D) [D,∞)

Page 88: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Q=DQ=C

Q<D

D<QDC<Q<DC

y n

nn yy

Q<A

Q<B

Q=A

B<Q<C

A

A<Q<B

Q<A

y n

n

n

y

y

Q=B

Q<C

B

y

y

n

n

α0

α1 α2

α3 α4

β2

β1 β3 β4

25

Structural Properties of BCSTs Henceforth assume distinct key weights, i.e., all of the β1, β2, …, βn are differentAlso assume C={<,=}

Every tree node N corresponds to search range of subtree rooted at N• Root of BSCT is search range [K0,Kn+1)

(where K0=-∞ and Kn+1=∞)• Comparisons cuts ranges

• A (Q<Ki) splits [Ki,Kj) into [Ki,Kk) and [Kk,Ki) • A (Q=Ki) removing Ki from range,

• Range of subtree rooted at N is some [Ki,Kj) with some keys removed

• Keys removed (holes) are Kk s.t. (Q=Kk) is on the path from N to the root of T.

[-∞,∞)

[-∞,C) [C,∞)

[-∞,C)-{B}

[-∞,C)-{A,B}

[A,C)-{A,B}

[C,D) [D,∞)

Page 89: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

26

Structural Properties of OBCSTs

T’

N

Root

Q = Kk

Q = Kk’

Page 90: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

26

Structural Properties of OBCSTs • Range associated with Node N is

[Ki,Kj) with some (h) keys Kk removed.

• Kk removed are s.t. (Q=Kk) are equality nodes on path from N to root (that fall within [Ki,Kj))

T’

N

Root

Q = Kk

Q = Kk’

Page 91: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

26

Structural Properties of OBCSTs • Range associated with Node N is

[Ki,Kj) with some (h) keys Kk removed.

• Kk removed are s.t. (Q=Kk) are equality nodes on path from N to root (that fall within [Ki,Kj))

• From previous Lemma, if T is an OBCST, βi of nodes path to N are larger than βi of all equality nodes in T’.

• ∀k, (Q=Kk) appears somewhere in T. Immediately implies that the h missing keys must be the largest weighted keys in [Ki,Kj)

T’

N

Root

Q = Kk

Q = Kk’

Page 92: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

26

Structural Properties of OBCSTs • Range associated with Node N is

[Ki,Kj) with some (h) keys Kk removed.

• Kk removed are s.t. (Q=Kk) are equality nodes on path from N to root (that fall within [Ki,Kj))

• From previous Lemma, if T is an OBCST, βi of nodes path to N are larger than βi of all equality nodes in T’.

• ∀k, (Q=Kk) appears somewhere in T. Immediately implies that the h missing keys must be the largest weighted keys in [Ki,Kj)

• Define punctured range [i,j: h) to be range [Ki,Kj) with the h highest weighted keys in [Ki,Kj) removed

T’

N

Root

Q = Kk

Q = Kk’

Page 93: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

26

Structural Properties of OBCSTs • Range associated with Node N is

[Ki,Kj) with some (h) keys Kk removed.

• Kk removed are s.t. (Q=Kk) are equality nodes on path from N to root (that fall within [Ki,Kj))

• From previous Lemma, if T is an OBCST, βi of nodes path to N are larger than βi of all equality nodes in T’.

• ∀k, (Q=Kk) appears somewhere in T. Immediately implies that the h missing keys must be the largest weighted keys in [Ki,Kj)

• Define punctured range [i,j: h) to be range [Ki,Kj) with the h highest weighted keys in [Ki,Kj) removed

• => every range associated with an internal node of an OBCST is a punctured range

T’

N

Root

Q = Kk

Q = Kk’

Page 94: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

27

Structural Properties of OBCSTs

T’

N

Root

Q = Kk

Q = Kk’

Page 95: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

27

Structural Properties of OBCSTs • [i,j: h) is range [Ki,Kj) with the h highest

weighted keys in [Ki,Kj) removed

• Range associated with an internal node of an OBCST is some [i,j: h)

T’

N

Root

Q = Kk

Q = Kk’

Page 96: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

27

Structural Properties of OBCSTs • [i,j: h) is range [Ki,Kj) with the h highest

weighted keys in [Ki,Kj) removed

• Range associated with an internal node of an OBCST is some [i,j: h)

• Define OPT(i,j: h) to be the cost of an optimal BCST for range [i,j: h)

• Goal is to find OPT(0,n+1: 0) and associated tree

• Will use Dynamic programming to fill in table.Table has size O(n3)We will (recursively) evaluate OPT(i,j: h) in O(j-i) time, yielding a O(n4) algorithm.

T’

N

Root

Q = Kk

Q = Kk’

[i,j:h)

[0,n+1:0)

Page 97: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Outline• History

• Binary Search Trees • Hu-Tucker Trees • AKKL Trees

• Optimal Binary Comparison Search Trees with Failures • Problem Models • List of New Results

• New Results • The Main Lemma • Structural Properties of OBCSTs • Dynamic Programming for OBCSTs • Proof of The Main Lemma (Sketch)

• Extensions and Open Problems

28

Page 98: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

29

Dynamic programming for OBCSTs

Page 99: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

29

Dynamic programming for OBCSTs

•Let T be an OBCST for [i,j: h) •T Has two possible structures OPT(i,j:h)

Page 100: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

29

Dynamic programming for OBCSTs

•Let T be an OBCST for [i,j: h) •T Has two possible structures OPT(i,j:h)

OPT(i,j:h+1)

Q=Kk

Kk1. Root is a (Q=Kk)

Page 101: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

29

Dynamic programming for OBCSTs

•Let T be an OBCST for [i,j: h) •T Has two possible structures OPT(i,j:h)

OPT(i,j:h+1)

Q=Kk

Kk1. Root is a (Q=Kk)

2. Root is a (Q<Kk) OPT(i,k:h1) OPT(k,j:h2)

Q<Kk

Page 102: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

30

Dynamic programing for OBCSTs 1. Root of OPT(i,j: h) is a (Q=Kk)

OPT(i,j:h+1)

Q=Kk

Kk

Page 103: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

30

Dynamic programing for OBCSTs 1. Root of OPT(i,j: h) is a (Q=Kk)

OPT(i,j:h+1)

Q=Kk

Kk• Kk must be largest key weight in [i,j: h) which is (h+1)st largest key weight in [i,j) • Right subtree missing h+1 largest weights in [i,j) so right subtree is OPT(i,j: h+1)

Page 104: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

30

Dynamic programing for OBCSTs 1. Root of OPT(i,j: h) is a (Q=Kk)

OPT(i,j:h+1)

Q=Kk

Kk• Kk must be largest key weight in [i,j: h) which is (h+1)st largest key weight in [i,j) • Right subtree missing h+1 largest weights in [i,j) so right subtree is OPT(i,j: h+1)

Cost of full tree is sum of • cost of left subtree 0 • cost of right subtree OPT(i,j: h+1) • Total weight of left + right subtree Wi,j:h

where Wi,j:h = sum of all βi,αi in (i,j: h]

Page 105: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

30

Dynamic programing for OBCSTs 1. Root of OPT(i,j: h) is a (Q=Kk)

OPT(i,j:h+1)

Q=Kk

Kk• Kk must be largest key weight in [i,j: h) which is (h+1)st largest key weight in [i,j) • Right subtree missing h+1 largest weights in [i,j) so right subtree is OPT(i,j: h+1)

Cost of full tree is sum of • cost of left subtree 0 • cost of right subtree OPT(i,j: h+1) • Total weight of left + right subtree Wi,j:h

where Wi,j:h = sum of all βi,αi in (i,j: h]

EQ(i, j : h) = Wi,j:h +OPT (i, j : h+ 1)

Page 106: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

31

Dynamic programing for OBCSTs

2. Root of OPT(i,j: h) is a (Q<Kk)

OPT(i,k:h1) OPT(k,j:h2)

Q<Kk

Page 107: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

31

Dynamic programing for OBCSTs

• Range is split into <k and ≥k• h holes (largest keys) in [i,j) are split, with h1(k) on left and h2(k) =h-h1(k) on right

2. Root of OPT(i,j: h) is a (Q<Kk)

OPT(i,k:h1) OPT(k,j:h2)

Q<Kk

Page 108: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

31

Dynamic programing for OBCSTs

• Range is split into <k and ≥k• h holes (largest keys) in [i,j) are split, with h1(k) on left and h2(k) =h-h1(k) on right• h1(k) keys must be heaviest in [i,k) h2(k) keys must be heaviest in [k,j)• So left and right subtrees are OBCSTs for [i,k: h1(k)) and [k,j: h2(k))

2. Root of OPT(i,j: h) is a (Q<Kk)

OPT(i,k:h1) OPT(k,j:h2)

Q<Kk

Page 109: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

31

Dynamic programing for OBCSTs

• Range is split into <k and ≥k• h holes (largest keys) in [i,j) are split, with h1(k) on left and h2(k) =h-h1(k) on right• h1(k) keys must be heaviest in [i,k) h2(k) keys must be heaviest in [k,j)• So left and right subtrees are OBCSTs for [i,k: h1(k)) and [k,j: h2(k)) • Cost of tree is Wi,j:h + OPT(i,k: h1(k)+ OPT(k,j: h2(k))

2. Root of OPT(i,j: h) is a (Q<Kk)

OPT(i,k:h1) OPT(k,j:h2)

Q<Kk

Page 110: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

31

Dynamic programing for OBCSTs

• Range is split into <k and ≥k• h holes (largest keys) in [i,j) are split, with h1(k) on left and h2(k) =h-h1(k) on right• h1(k) keys must be heaviest in [i,k) h2(k) keys must be heaviest in [k,j)• So left and right subtrees are OBCSTs for [i,k: h1(k)) and [k,j: h2(k)) • Cost of tree is Wi,j:h + OPT(i,k: h1(k)+ OPT(k,j: h2(k))

2. Root of OPT(i,j: h) is a (Q<Kk)

Don’t know what k is, so minimize over all possible k SPLIT (i, j : h) = min

i<k<j

�Wi,j:h +OPT (i, k : h1(k)) +OPT (k, j : h2(k))

OPT(i,k:h1) OPT(k,j:h2)

Q<Kk

Page 111: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

32

Dynamic programing for OBCSTs

Page 112: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

32

Dynamic programing for OBCSTs OPT(i,j: h) has two possible structures

Page 113: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

32

Dynamic programing for OBCSTs OPT(i,j: h) has two possible structures

OPT(i,j:h+1)

Q=Kk

Kk

1. Root is a (Q=Kk)

2. Root is a (Q<Kk)

OPT(i,j:h1) OPT(i,j:h2)

Q<Kk

Page 114: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

32

Dynamic programing for OBCSTs OPT(i,j: h) has two possible structures

OPT(i,j:h+1)

Q=Kk

Kk

1. Root is a (Q=Kk)

2. Root is a (Q<Kk)

OPT(i,j:h1) OPT(i,j:h2)

Q<Kk

EQ(i, j : h) = Wi,j:h +OPT (i, j : h+ 1)

SPLIT (i, j : h) = mini<k<j

�Wi,j:h +OPT (i, k : h1(k)) +OPT (k, j : h2(k))

Page 115: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

32

Dynamic programing for OBCSTs OPT(i,j: h) has two possible structures

OPT(i,j:h+1)

Q=Kk

Kk

1. Root is a (Q=Kk)

2. Root is a (Q<Kk)

OPT(i,j:h1) OPT(i,j:h2)

Q<Kk

EQ(i, j : h) = Wi,j:h +OPT (i, j : h+ 1)

This immediately impliesOPT (i, j : h) � min (EQ(i, j : h), SPLIT (i, j : h))

SPLIT (i, j : h) = mini<k<j

�Wi,j:h +OPT (i, k : h1(k)) +OPT (k, j : h2(k))

Page 116: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

32

Dynamic programing for OBCSTs OPT(i,j: h) has two possible structures

OPT(i,j:h+1)

Q=Kk

Kk

1. Root is a (Q=Kk)

2. Root is a (Q<Kk)

OPT(i,j:h1) OPT(i,j:h2)

Q<Kk

EQ(i, j : h) = Wi,j:h +OPT (i, j : h+ 1)

This immediately impliesOPT (i, j : h) � min (EQ(i, j : h), SPLIT (i, j : h))

But every case seen can construct a BCST with that cost, soOPT (i, j : h) = min (EQ(i, j : h), SPLIT (i, j : h))

SPLIT (i, j : h) = mini<k<j

�Wi,j:h +OPT (i, k : h1(k)) +OPT (k, j : h2(k))

Page 117: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

33

Dynamic programing for OBCSTs OPT (i, j : h) = min (EQ(i, j : h), SPLIT (i, j : h))

EQ(i, j : h) = Wi,j:h +OPT (i, j : h+ 1)

SPLIT (i, j : h) = mini<k<j

�Wi,j:h +OPT (i, k : h1(k)) +OPT (k, j : h2(k))

Page 118: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

33

Dynamic programing for OBCSTs OPT (i, j : h) = min (EQ(i, j : h), SPLIT (i, j : h))

EQ(i, j : h) = Wi,j:h +OPT (i, j : h+ 1)

SPLIT (i, j : h) = mini<k<j

�Wi,j:h +OPT (i, k : h1(k)) +OPT (k, j : h2(k))

Set initial conditions for ranges OPT(i,i+1,*)

Page 119: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

33

Dynamic programing for OBCSTs OPT (i, j : h) = min (EQ(i, j : h), SPLIT (i, j : h))

EQ(i, j : h) = Wi,j:h +OPT (i, j : h+ 1)

SPLIT (i, j : h) = mini<k<j

�Wi,j:h +OPT (i, k : h1(k)) +OPT (k, j : h2(k))

Set initial conditions for ranges OPT(i,i+1,*)OPT(i,i+1,1)=0 Ki<Q<Ki+1 αi

Ki<Q<Ki+1 αiKi=Qβi

Q=KiOPT(i,i+1,0)= βi + αi

Page 120: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

33

Dynamic programing for OBCSTs OPT (i, j : h) = min (EQ(i, j : h), SPLIT (i, j : h))

EQ(i, j : h) = Wi,j:h +OPT (i, j : h+ 1)

SPLIT (i, j : h) = mini<k<j

�Wi,j:h +OPT (i, k : h1(k)) +OPT (k, j : h2(k))

Set initial conditions for ranges OPT(i,i+1,*)OPT(i,i+1,1)=0 Ki<Q<Ki+1 αi

Ki<Q<Ki+1 αiKi=Qβi

Q=KiOPT(i,i+1,0)= βi + αi

Comments

Page 121: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

33

Dynamic programing for OBCSTs OPT (i, j : h) = min (EQ(i, j : h), SPLIT (i, j : h))

EQ(i, j : h) = Wi,j:h +OPT (i, j : h+ 1)

SPLIT (i, j : h) = mini<k<j

�Wi,j:h +OPT (i, k : h1(k)) +OPT (k, j : h2(k))

Set initial conditions for ranges OPT(i,i+1,*)OPT(i,i+1,1)=0 Ki<Q<Ki+1 αi

Ki<Q<Ki+1 αiKi=Qβi

Q=KiOPT(i,i+1,0)= βi + αi

Comments• Must restrict h ≤ j-i (can’t have more holes than keys in interval)

Page 122: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

33

Dynamic programing for OBCSTs OPT (i, j : h) = min (EQ(i, j : h), SPLIT (i, j : h))

EQ(i, j : h) = Wi,j:h +OPT (i, j : h+ 1)

SPLIT (i, j : h) = mini<k<j

�Wi,j:h +OPT (i, k : h1(k)) +OPT (k, j : h2(k))

Set initial conditions for ranges OPT(i,i+1,*)OPT(i,i+1,1)=0 Ki<Q<Ki+1 αi

Ki<Q<Ki+1 αiKi=Qβi

Q=KiOPT(i,i+1,0)= βi + αi

Comments• Must restrict h ≤ j-i (can’t have more holes than keys in interval) • Need to fill in table in proper order, e.g.,

(a) d= 0 to n, (b) i=0 to n-d, j=i+d+1, (c) h =(j-i) downto 0

Page 123: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

33

Dynamic programing for OBCSTs OPT (i, j : h) = min (EQ(i, j : h), SPLIT (i, j : h))

EQ(i, j : h) = Wi,j:h +OPT (i, j : h+ 1)

SPLIT (i, j : h) = mini<k<j

�Wi,j:h +OPT (i, k : h1(k)) +OPT (k, j : h2(k))

Set initial conditions for ranges OPT(i,i+1,*)OPT(i,i+1,1)=0 Ki<Q<Ki+1 αi

Ki<Q<Ki+1 αiKi=Qβi

Q=KiOPT(i,i+1,0)= βi + αi

Comments• Must restrict h ≤ j-i (can’t have more holes than keys in interval) • Need to fill in table in proper order, e.g.,

(a) d= 0 to n, (b) i=0 to n-d, j=i+d+1, (c) h =(j-i) downto 0• Need O(1) method for computing hi(k)

• => O(j-i) to calculate OPT(i,j: h) • => O(n^4) to fill in complete table

Page 124: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

33

Dynamic programing for OBCSTs OPT (i, j : h) = min (EQ(i, j : h), SPLIT (i, j : h))

EQ(i, j : h) = Wi,j:h +OPT (i, j : h+ 1)

SPLIT (i, j : h) = mini<k<j

�Wi,j:h +OPT (i, k : h1(k)) +OPT (k, j : h2(k))

Set initial conditions for ranges OPT(i,i+1,*)OPT(i,i+1,1)=0 Ki<Q<Ki+1 αi

Ki<Q<Ki+1 αiKi=Qβi

Q=KiOPT(i,i+1,0)= βi + αi

Comments• Must restrict h ≤ j-i (can’t have more holes than keys in interval) • Need to fill in table in proper order, e.g.,

(a) d= 0 to n, (b) i=0 to n-d, j=i+d+1, (c) h =(j-i) downto 0• Need O(1) method for computing hi(k)

• => O(j-i) to calculate OPT(i,j: h) • => O(n^4) to fill in complete table

• OPT(0,n+1:0) is optimal cost. Use standard DP backtracking to construct corresponding optimal tree

Page 125: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

34

Perturbing for Key Weight Uniqueness (I)

Page 126: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

34

Perturbing for Key Weight Uniqueness (I)• Strongly used assumption βi are all distinct to find `weightiest’ keys

• Assumption can be removed using perturbation argument

Page 127: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

34

Perturbing for Key Weight Uniqueness (I)• Strongly used assumption βi are all distinct to find `weightiest’ keys

• Assumption can be removed using perturbation argument

• All values constructed/compared in algorithm are subtree costs • in form ∑ aiαi + ∑biβi where 0 ≤ ai,bi ≤ 2n are integral node depths

Page 128: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

34

Perturbing for Key Weight Uniqueness (I)• Strongly used assumption βi are all distinct to find `weightiest’ keys

• Assumption can be removed using perturbation argument

• All values constructed/compared in algorithm are subtree costs • in form ∑ aiαi + ∑biβi where 0 ≤ ai,bi ≤ 2n are integral node depths

• Perturb input by setting α’i=αi , β’i = βi+i𝝐 where 𝝐 is very small • => β’i are all distinct

Page 129: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

34

Perturbing for Key Weight Uniqueness (I)• Strongly used assumption βi are all distinct to find `weightiest’ keys

• Assumption can be removed using perturbation argument

• All values constructed/compared in algorithm are subtree costs • in form ∑ aiαi + ∑biβi where 0 ≤ ai,bi ≤ 2n are integral node depths

• Perturb input by setting α’i=αi , β’i = βi+i𝝐 where 𝝐 is very small • => β’i are all distinct

• Since β’i are all distinct, algorithm gives correct result for α’i ,β’i • Easy to prove that optimum tree for α’i ,β’i is optimum for αi ,βi • => resulting tree is optimum for original α’i ,β’i

Page 130: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

34

Perturbing for Key Weight Uniqueness (I)• Strongly used assumption βi are all distinct to find `weightiest’ keys

• Assumption can be removed using perturbation argument

• All values constructed/compared in algorithm are subtree costs • in form ∑ aiαi + ∑biβi where 0 ≤ ai,bi ≤ 2n are integral node depths

• Perturb input by setting α’i=αi , β’i = βi+i𝝐 where 𝝐 is very small • => β’i are all distinct

• Since β’i are all distinct, algorithm gives correct result for α’i ,β’i • Easy to prove that optimum tree for α’i ,β’i is optimum for αi ,βi • => resulting tree is optimum for original α’i ,β’i

• In fact don’t actually need to know value of 𝝐

Page 131: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

35

Perturbing for Key Weight Uniqueness (II)

Page 132: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

35

Perturbing for Key Weight Uniqueness (II)• Perturb input: α’i=αi , β’i = βi+i𝝐 where 𝝐 is very small

• Need to find optimum tree for α’i ,β’i (which is also optimum for α’i ,β’i )

Page 133: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

35

Perturbing for Key Weight Uniqueness (II)• Perturb input: α’i=αi , β’i = βi+i𝝐 where 𝝐 is very small

• Need to find optimum tree for α’i ,β’i (which is also optimum for α’i ,β’i )

• Recall that algorithm only performs additions/comparisons • All values are subtree costs ∑ aiαi + ∑biβi where 0 ≤ ai,bi ≤ 2n are integral

Page 134: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

35

Perturbing for Key Weight Uniqueness (II)• Perturb input: α’i=αi , β’i = βi+i𝝐 where 𝝐 is very small

• Need to find optimum tree for α’i ,β’i (which is also optimum for α’i ,β’i )

• Recall that algorithm only performs additions/comparisons • All values are subtree costs ∑ aiαi + ∑biβi where 0 ≤ ai,bi ≤ 2n are integral

• Don’t actually need to know or store value of 𝝐

Page 135: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

35

Perturbing for Key Weight Uniqueness (II)• Perturb input: α’i=αi , β’i = βi+i𝝐 where 𝝐 is very small

• Need to find optimum tree for α’i ,β’i (which is also optimum for α’i ,β’i )

• Recall that algorithm only performs additions/comparisons • All values are subtree costs ∑ aiαi + ∑biβi where 0 ≤ ai,bi ≤ 2n are integral

• Don’t actually need to know or store value of 𝝐

• Every value in algorithm is in form x = x1+x2𝝐, where x2=O(n3) is an integer • Forget 𝝐. Store pair (x1,x2)

Page 136: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

35

Perturbing for Key Weight Uniqueness (II)• Perturb input: α’i=αi , β’i = βi+i𝝐 where 𝝐 is very small

• Need to find optimum tree for α’i ,β’i (which is also optimum for α’i ,β’i )

• Recall that algorithm only performs additions/comparisons • All values are subtree costs ∑ aiαi + ∑biβi where 0 ≤ ai,bi ≤ 2n are integral

• Don’t actually need to know or store value of 𝝐

• Every value in algorithm is in form x = x1+x2𝝐, where x2=O(n3) is an integer • Forget 𝝐. Store pair (x1,x2)

• (A) Addition is pairwise-addition • (x1,x2) + (y1,y2) = (x1+y1, x2+y2)

• (C) Comparison is lexicographic-comparison • (x1,x2) < (y1,y2) iff x1<y1 or x1=y1 and x2=<y2

Page 137: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

35

Perturbing for Key Weight Uniqueness (II)• Perturb input: α’i=αi , β’i = βi+i𝝐 where 𝝐 is very small

• Need to find optimum tree for α’i ,β’i (which is also optimum for α’i ,β’i )

• Recall that algorithm only performs additions/comparisons • All values are subtree costs ∑ aiαi + ∑biβi where 0 ≤ ai,bi ≤ 2n are integral

• Don’t actually need to know or store value of 𝝐

• Every value in algorithm is in form x = x1+x2𝝐, where x2=O(n3) is an integer • Forget 𝝐. Store pair (x1,x2)

• (A) Addition is pairwise-addition • (x1,x2) + (y1,y2) = (x1+y1, x2+y2)

• (C) Comparison is lexicographic-comparison • (x1,x2) < (y1,y2) iff x1<y1 or x1=y1 and x2=<y2

• Both (A) and (C) can be implemented in O(1) time without knowing 𝝐• Perturbed algorithm has same asymptotic running time as regular one

Page 138: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

36

Odds and Ends

Page 139: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

36

Odds and Ends • Designed O(n4) algorithm for constructing OBCSTs

when C={<,=} and need to report Exact Failures

Page 140: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

36

Odds and Ends • Designed O(n4) algorithm for constructing OBCSTs

when C={<,=} and need to report Exact Failures

• Strongly used assumption βi are all distinct • Assumption can be removed using perturbation argument

Page 141: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

36

Odds and Ends • Designed O(n4) algorithm for constructing OBCSTs

when C={<,=} and need to report Exact Failures

• Strongly used assumption βi are all distinct • Assumption can be removed using perturbation argument

• To solve problem C={<,=} with Non-Exact failures • only need to modify initial conditions

Page 142: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

36

Odds and Ends • Designed O(n4) algorithm for constructing OBCSTs

when C={<,=} and need to report Exact Failures

• Strongly used assumption βi are all distinct • Assumption can be removed using perturbation argument

• To solve problem C={<,=} with Non-Exact failures • only need to modify initial conditions

• Symmetry argument gives algorithms for C={≤, =}

Page 143: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

36

Odds and Ends • Designed O(n4) algorithm for constructing OBCSTs

when C={<,=} and need to report Exact Failures

• Strongly used assumption βi are all distinct • Assumption can be removed using perturbation argument

• To solve problem C={<,=} with Non-Exact failures • only need to modify initial conditions

• Symmetry argument gives algorithms for C={≤, =}

• Algorithms for C={<, ≤, =} requires only slight modifications of SPLIT(i,j: h)

Page 144: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

36

Odds and Ends • Designed O(n4) algorithm for constructing OBCSTs

when C={<,=} and need to report Exact Failures

• Strongly used assumption βi are all distinct • Assumption can be removed using perturbation argument

• To solve problem C={<,=} with Non-Exact failures • only need to modify initial conditions

• Symmetry argument gives algorithms for C={≤, =}

• Algorithms for C={<, ≤, =} requires only slight modifications of SPLIT(i,j: h)

• If C={<, ≤}, ranges have no holes and problem can be solved in O(n log n) similar to Hu-Tucker

Page 145: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Outline• History

• Binary Search Trees • Hu-Tucker Trees • AKKL Trees

• Optimal Binary Comparison Search Trees with Failures • Problem Models • List of New Results

• New Results • The Main Lemma • Structural Properties of OBCSTs • Dynamic Programming for OBCSTs • Proof of The Main Lemma (Sketch)

• Extensions and Open Problems

37

Page 146: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

38

Proof of Main Lemma

Q = x

Q = y

T3

Q < Kj

T1 Q < Kj

Q < z

T3

Q=x

Q=y

Page 147: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

38

Proof of Main LemmaLet T be an OBCST. Assume

Q = x

Q = y

T3

Q < Kj

T1 Q < Kj

Q < z

T3

Q=x

Q=y

Page 148: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

38

Proof of Main LemmaLet T be an OBCST. Assume• y<x (x>y is symmetric)

Q = x

Q = y

T3

Q < Kj

T1 Q < Kj

Q < z

T3

Q=x

Q=y

Page 149: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

38

Proof of Main LemmaLet T be an OBCST. Assume• y<x (x>y is symmetric)• (Q=x) is above (Q=y) Q = x

Q = y

T3

Q < Kj

T1 Q < Kj

Q < z

T3

Q=x

Q=y

Page 150: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

38

Proof of Main LemmaLet T be an OBCST. Assume• y<x (x>y is symmetric)• (Q=x) is above (Q=y)• => βx < βy will show contradiction

Q = x

Q = y

T3

Q < Kj

T1 Q < Kj

Q < z

T3

Q=x

Q=y

Page 151: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

38

Proof of Main LemmaLet T be an OBCST. Assume• y<x (x>y is symmetric)• (Q=x) is above (Q=y)• => βx < βy will show contradiction• => βx ≥ βy and Thm correct

Q = x

Q = y

T3

Q < Kj

T1 Q < Kj

Q < z

T3

Q=x

Q=y

Page 152: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

38

Proof of Main LemmaLet T be an OBCST. Assume• y<x (x>y is symmetric)• (Q=x) is above (Q=y)• => βx < βy will show contradiction• => βx ≥ βy and Thm correct

• All comparisons between (Q=x) and (Q=y) are inequalities • otherwise ∃ (Q=w) on path with either

βx < βw or βw < βy and can show contradiction with (x,w) or (w,y)

Q = x

Q = y

T3

Q < Kj

T1 Q < Kj

Q < z

T3

Q=x

Q=y

Page 153: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

38

Proof of Main LemmaLet T be an OBCST. Assume• y<x (x>y is symmetric)• (Q=x) is above (Q=y)• => βx < βy will show contradiction• => βx ≥ βy and Thm correct

• All comparisons between (Q=x) and (Q=y) are inequalities • otherwise ∃ (Q=w) on path with either

βx < βw or βw < βy and can show contradiction with (x,w) or (w,y)

• x,y ∈ Range((Q=x)) by definitionIf x,y ∈ Range((Q=y)) then could swap (Q=X) and (Q=y) to get cheaper tree.

Q = x

Q = y

T3

Q < Kj

T1 Q < Kj

Q < z

T3

Q=x

Q=y

Page 154: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

39

Proof of Main Lemma

Q = x

Q = y

T3

Q < Kj

T1 Q < Kj

Q < z

T3

Q=x

Q=y

x would be here

Page 155: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

39

Proof of Main LemmaLet T be an OBCST. Assume• y<x (x>y is symmetric)• (Q=x) is above (Q=y)• => βx < βy will show contradiction

• All comparisons between (Q=x) and (Q=y) are inequalities

Q = x

Q = y

T3

Q < Kj

T1 Q < Kj

Q < z

T3

Q=x

Q=y

x would be here

Page 156: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

39

Proof of Main LemmaLet T be an OBCST. Assume• y<x (x>y is symmetric)• (Q=x) is above (Q=y)• => βx < βy will show contradiction

• All comparisons between (Q=x) and (Q=y) are inequalities

• Since x∉ Range((Q=y) => Path (Q=x) to (Q=y) contains (Q<z) s.t z’s children’s ranges are [i,z,h’), [z,j,h’’) where y∈ [i,z) and x ∈[z,j). z is called splitter.

• P’ is (red) path from (Q=x) to (Q=y)

Q = x

Q = y

T3

Q < Kj

T1 Q < Kj

Q < z

T3

Q=x

Q=y

x would be here

Page 157: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

40

Proof of Main Lemma

Page 158: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

40

Proof of Main Lemma• P is path in T from (Q=x) to (Q=y). y< x. z is x-y splitter on P• P’ is path from (Q=x) to (Q=z)

Page 159: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

40

Proof of Main Lemma• P is path in T from (Q=x) to (Q=y). y< x. z is x-y splitter on P• P’ is path from (Q=x) to (Q=z)• Proof will be case analysis of structure of P’• For every P’, will show can build cheaper OBCST T’

contradicting optimality of T

Page 160: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

40

Proof of Main Lemma• P is path in T from (Q=x) to (Q=y). y< x. z is x-y splitter on P• P’ is path from (Q=x) to (Q=z)• Proof will be case analysis of structure of P’• For every P’, will show can build cheaper OBCST T’

contradicting optimality of T

Case 1: P’ is one edge

Page 161: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

40

Proof of Main Lemma• P is path in T from (Q=x) to (Q=y). y< x. z is x-y splitter on P• P’ is path from (Q=x) to (Q=z)• Proof will be case analysis of structure of P’• For every P’, will show can build cheaper OBCST T’

contradicting optimality of T

Case 1: P’ is one edgeQ = x

Q < z

x

A

B

Q < z

Q = x

A

x

B

) �1

+1

y

y

n

n

Page 162: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

40

Proof of Main Lemma• P is path in T from (Q=x) to (Q=y). y< x. z is x-y splitter on P• P’ is path from (Q=x) to (Q=z)• Proof will be case analysis of structure of P’• For every P’, will show can build cheaper OBCST T’

contradicting optimality of T

Case 1: P’ is one edgeQ = x

Q < z

x

A

B

Q < z

Q = x

A

x

B

) �1

+1

y

y

n

n

y∈A => Weight(A) ≥ βy > βx

Page 163: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

40

Proof of Main Lemma• P is path in T from (Q=x) to (Q=y). y< x. z is x-y splitter on P• P’ is path from (Q=x) to (Q=z)• Proof will be case analysis of structure of P’• For every P’, will show can build cheaper OBCST T’

contradicting optimality of T

Case 1: P’ is one edgeQ = x

Q < z

x

A

B

Q < z

Q = x

A

x

B

) �1

+1

y

y

n

n

y∈A => Weight(A) ≥ βy > βx

=> replacing left subtree by right subtree in T yields new BCST T’ with lower cost than T, contradicting T being OBCST

Page 164: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

41

Proof of Main Lemma• P is path in T from (Q=x) to (Q=y). y<x. z is x-y splitter on P • P’ is path from (Q=x) to (Q=z)

Case 2: P’ is two edges ≠≮ Q = x

Q < z1x

B1

B

Q < z

Q = x

A

x

B

)

�1+1

y

y

n

n

Q < z

A

Q < z1

B1 �1

Page 165: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

41

Proof of Main Lemma• P is path in T from (Q=x) to (Q=y). y<x. z is x-y splitter on P • P’ is path from (Q=x) to (Q=z)

Case 2: P’ is two edges ≠≮

y∈A => Weight(A) ≥ βy > βx Q = x

Q < z1x

B1

B

Q < z

Q = x

A

x

B

)

�1+1

y

y

n

n

Q < z

A

Q < z1

B1 �1

Page 166: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

41

Proof of Main Lemma• P is path in T from (Q=x) to (Q=y). y<x. z is x-y splitter on P • P’ is path from (Q=x) to (Q=z)

Case 2: P’ is two edges ≠≮

y∈A => Weight(A) ≥ βy > βx

=> again replacing left tree by right tree in T yields new BCST T’ with lower cost than T, contradicting T being OBCST

Q = x

Q < z1x

B1

B

Q < z

Q = x

A

x

B

)

�1+1

y

y

n

n

Q < z

A

Q < z1

B1 �1

Page 167: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

42

Proof of Main Lemma

Page 168: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

42

Proof of Main Lemma• P is path in T from (Q=x) to (Q=y). y<x. z is x-y splitter on P• P’ is path from (Q=x) to (Q=z)• Proof will be case analysis of structure of P’

Page 169: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

42

Proof of Main Lemma• P is path in T from (Q=x) to (Q=y). y<x. z is x-y splitter on P• P’ is path from (Q=x) to (Q=z)• Proof will be case analysis of structure of P’

• Already saw first two cases of P’ • Showed for each that assumptions allow replacing subtree

rooted at (Q=x) with cheaper subtree for some range. Replacement leads to cheaper BCST, contradicting optimalityof T

Page 170: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

42

Proof of Main Lemma• P is path in T from (Q=x) to (Q=y). y<x. z is x-y splitter on P• P’ is path from (Q=x) to (Q=z)• Proof will be case analysis of structure of P’

• Already saw first two cases of P’ • Showed for each that assumptions allow replacing subtree

rooted at (Q=x) with cheaper subtree for some range. Replacement leads to cheaper BCST, contradicting optimalityof T

• The full proof splits P’ into 7 cases. • For each, can show replacement with cheaper subtree,

contradicting optimality of T.

Page 171: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

Outline• History

• Binary Search Trees • Hu-Tucker Trees • AKKL Trees

• Optimal Binary Comparison Search Trees with Failures • Problem Models • List of New Results

• Our Results • The Main Lemma • Structural Properties of OBCSTs • Dynamic Programming for OBCSTs • Proof of The Main Lemma

• Extensions and Open Problems

43

Page 172: New Results on Binary Comparison Search Treesgolin/Talks/BCST_Talk.pdfHu-Tucker Binary Comparison Search Trees • Knuth constructed optimal binary search trees 9 Q=B Q

44

Extensions & Open Problems• If the βi,αi are probabilities (sum to 1) can show an O(n)

algorithm that constructs BCST within additive error 3 of optimal for Exact Failure Case • Modification of similar algorithm for Hu-Tucker case.

• O(n4) is quite high for worst case. • Can we do better?