The algorithm of Garsia and Wachs

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Quicksort
Advertisements

Greedy Algorithms Greed is good. (Some of the time)
Correctness of Constructing Optimal Alphabetic Trees Revisited Marek Karpinski, Lawrence L. Larmore, Wojciech Rytter Theoretical computer science 180 (1997)
B-Trees. Motivation for B-Trees Index structures for large datasets cannot be stored in main memory Storing it on disk requires different approach to.
Tirgul 5 AVL trees.
CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.
1 Minimize average access time Items have weights: Item i has weight w i Let W =  w i be the total weight of the items Want the search to heavy items.
Tirgul 6 B-Trees – Another kind of balanced trees Problem set 1 - some solutions.
Heap: A Special Kind of Tree
Chapter 10 Search Structures Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures.
2-3 Trees Professor Sin-Min Lee. Contents n Introduction n The 2-3 Trees Rules n The Advantage of 2-3 Trees n Searching For an Item in a 2-3 Tree n Inserting.
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
Fundamental Structures of Computer Science March 02, 2006 Ananda Guna Binomial Heaps.
1 B-Trees Section AVL (Adelson-Velskii and Landis) Trees AVL tree is binary search tree with balance condition –To ensure depth of the tree is.
Minimum Cost Binary Trees Speaker: Dana Moshkovitz.
B+ Tree What is a B+ Tree Searching Insertion Deletion.
Review Binary Tree Binary Tree Representation Array Representation Link List Representation Operations on Binary Trees Traversing Binary Trees Pre-Order.
Balanced Binary Search Trees
“On an Algorithm of Zemlyachenko for Subtree Isomorphism” Yefim Dinitz, Alon Itai, Michael Rodeh (1998) Presented by: Masha Igra, Merav Bukra.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
INTRODUCTION TO MULTIWAY TREES P INTRO - Binary Trees are useful for quick retrieval of items stored in the tree (using linked list) - often,
Order Statistics. Order statistics Given an input of n values and an integer i, we wish to find the i’th largest value. There are i-1 elements smaller.
Weight balance trees (Nievergelt & Reingold 73)
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
2-3 Tree. Slide 2 Outline  Balanced Search Trees 2-3 Trees Trees.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of CHAPTER 12: Multi-way Search Trees Java Software Structures: Designing.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
1 Biased 2-b trees (Bent, Sleator, Tarjan 1980). 2 Goal Keep sorted lists subject to the following operations: find(x,L) insert(x,L) delete(x,L) catenate(L1,L2)
CS 61B Data Structures and Programming Methodology Aug 7, 2008 David Sun.
Lecture 15 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Chapter 8 Maximum Flows: Additional Topics All-Pairs Minimum Value Cut Problem  Given an undirected network G, find minimum value cut for all.
1 Sorting an almost sorted input Suppose we know that the input is “almost” sorted Let I be the number of “inversions” in the input: The number of pairs.
Loop Invariants and Binary Search Chapter 4.4, 5.1.
Sorting Lower Bounds n Beating Them. Recap Divide and Conquer –Know how to break a problem into smaller problems, such that –Given a solution to the smaller.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
OCR A Level F453: Data structures and data manipulation Data structures and data manipulation a. explain how static data structures may be.
CSE15 Discrete Mathematics 03/06/17
Lecture Trees Professor Sin-Min Lee.
B-Trees B-Trees.
B-Trees B-Trees.
B-Trees B-Trees.
Binary Search Tree (BST)
B+ Tree.
Trees 4 The B-Tree Section 4.7
(edited by Nadia Al-Ghreimil)
Huffman Codes Let A1,...,An be a set of items.
Data Structures and Algorithms
Complexity Present sorting methods. Binary search. Other measures.
Multi-Way Search Trees
(2,4) Trees /26/2018 3:48 PM (2,4) Trees (2,4) Trees
A Kind of Binary Tree Usually Stored in an Array
Data Structures Review Session
CS200: Algorithm Analysis
Advanced Algorithms Analysis and Design
Advanced Algorithms Analysis and Design
Splay trees (Sleator, Tarjan 1983)
2-3-4 Trees Red-Black Trees
Minimum Spanning Tree Algorithms
CSIT 402 Data Structures II With thanks to TK Prasad
Chapter 16: Greedy algorithms Ming-Te Chi
(2,4) Trees /24/2019 7:30 PM (2,4) Trees (2,4) Trees
(edited by Nadia Al-Ghreimil)
Applied Combinatorics, 4th Ed. Alan Tucker
(2,4) Trees /6/ :26 AM (2,4) Trees (2,4) Trees
Clustering.
Algorithms Recurrences.
B-Trees.
B-Trees.
Mathematical Induction II
CS210- Lecture 13 June 28, 2005 Agenda Heaps Complete Binary Tree
Presentation transcript:

The algorithm of Garsia and Wachs Presentation by a more recent proof of Karpinski et al.

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 wi  depth(i) is minimized

Observation 1 If we new the di’s (depths) then we could build the tree easily in O(n) time 1 2 3 2 3 4 4 1

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

Definitions

The algorithm 13 8 5 7 6 9 14 12 14 13 8 5 7 6 9 14 12 12 13 8 5 7 6 9 14 21 13 12 15 23

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 ?

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 ≤ aj+2 In a list of length at least 2 the next to last element is smaller than the element following the list.

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.

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

Implementation (Cont) We represent sublists as search tree

Implementation (Cont) 13 8 5 7 6 9 14 13 8 5 7 6 9 14 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

Implementation (Cont) 13 8 5 7 6 9 14 5 7 7 9 14 6 9 14 8 13 7 5 7 6 9 14 5 8 13

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)

But why does this algorithm produce the optimal tree ??

Notation

Definitions (Cont)

Theorem 1 (correctness of GW) By induction on the length of the sequence, correctness reduces to:

We will prove more lexi trees over π lexi trees over π such that i, i+1, are at the same depth opt opt

lexi trees over π A lexi trees over π such that i, i+1, are at the same depth opt opt

lexi trees over π lexi trees over π’ such that i, i+1, are at the same depth lexi trees over π’ such that i, i+1, are siblings lexi trees over π such that i, i+1, are at the same depth opt opt opt

B lexi trees over π lexi trees over π ‘ such that i, i+1, are at the same depth lexi trees over π such that i, i+1, are at the same depth opt lexi trees over π ‘ such that i, i+1, are siblings opt opt

C lexi trees over π lexi trees over π ‘ such that i, i+1, are at the same depth lexi trees over π such that i, i+1, are at the same depth opt lexi trees over π ‘ such that i, i+1, are siblings opt opt

C lexi trees over π lexi trees over π’ such that i, i+1, are at the same depth lexi trees over π such that i, i+1, are at the same depth opt lexi trees over π’ such that i, i+1, are siblings opt opt

Theorem 1 (correctness of GW)

lexi trees over π A lexi trees over π such that i, i+1, are at the same depth opt opt

Proof of A There is an optimal lexi tree in which i, and i+1 are at the same level.

B lexi trees over π lexi trees over π’ such that i, i+1, are at the same depth lexi trees over π such that i, i+1, are at the same depth opt lexi trees over π’ such that i, i+1, are siblings opt opt

Proof of B Among optimal trees over π’ in which i, and i+1 are on the same level there is one in which they are siblings. So T’ is also optimal

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

Definition of Well Shaped Segments S=[i,…j] is left well shaped iff it is h-isolated and depthT(i) =depthT(i+1) = h+1 S=[i,…j] is right well shaped iff it is h-isolated and depthT(j) =depthT(j+1) = h+1 Active Window

Movability Lemma If the segment [i,…,j] is left well shaped, then the active pair (i,i+1) 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)

Movability Lemma

Movability Lemma

Movability Lemma

Movability Lemma

Movability Lemma

Movability Lemma

Movability Lemma

Movability Lemma

Movability Lemma

Movability Lemma

Movability Lemma

Movability Lemma

The main theorem to establish C THM: (a) if T is optimal over π such that i, i+1 are at the same depth then the segment [i,….,j] is left well shaped in T (b) if T’ is optimal over π’ such that i, i+1 are at the same depth then the segment [i+2,….,j,i,i+1] is right well shaped in T Focus on (a)

Proof First we have to show that every leaf u[i,…,j], depth(u) ≥ h where h = depth(i)-1= depth(i+1)-1

Homework To finish we have to consider one more case where i, and i+1 are siblings. We also have to prove that depthT(LCA(j,j+1)) ≤ h Case (b) of the THM is similar

Hu-Tucker Algorithm Transparent items and opaque items Compatible pair – No opaque items in the middle Minimal compatible pair (mcp) – compatible pair (i,i+1) where Weight(i) + weight(i+1) is minimal Tie Breaking Rule

Hu-Tucker Algorithm

Hu-Tucker Algorithm

Hu-Tucker Algorithm

Hu-Tucker Algorithm