Maintaining Dynamic Tree with Min Subject to Constraints Data Structures 2003 CS TAU
Multi Criteria Representation Consider a set of elements Each element is equipped with two keys (values): K1, K2 For simplicity: Assume each key appears at most once. Want to support: Insert(k1, k2), delete(k1,k2), find_min(k1), find_min(k2) Implementation: Double data structure, with pointers between the structures. 2/24/2019 Min s.t. Constraints, Hanoch Levy CS, TAU
Min s.t. Constraints, Hanoch Levy CS, TAU Example For each person: height + Grade Two 2-3 trees, HEIGHT, GRADE Insert in both Findmin on either Pointers between the two for member, deletions GRADE 8 50 81 97 HEIGHT 185 160 172 173 2/24/2019 Min s.t. Constraints, Hanoch Levy CS, TAU
Maintaining Minimum (Max) subject to constraint Consider a set of elements Each element is equipped with two keys (values): K1, K2 Want to support: Insert Delete Find MIN(K1) subject to K2 > k (or MAX) 2/24/2019 Min s.t. Constraints, Hanoch Levy CS, TAU
Min s.t. Constraints, Hanoch Levy CS, TAU Example Store student records Each student has GRADE, HEIGHT Assume all GRADEs are unique. Want: Insert (g,h): Insert the pair Delete (g,h): Delete the pair x= FINDMAX (height): FindMAX(grade) s.t. H<=h (find the maximal grade of the short students). 2/24/2019 Min s.t. Constraints, Hanoch Levy CS, TAU
Dual 2-3 Tree with leaf linked lists and mutual pointers Problematic Easy to find the set of students whose height >= h Finding the max grade on this is O(N) GRADE 8 50 81 97 HEIGHT 185 160 172 173 2/24/2019 Min s.t. Constraints, Hanoch Levy CS, TAU
Efficient Data Structure Want: minimum grade subject to height >=h E.g: height >= 165 Store constraint on a search tree (2-3 tree) The red recursion allows us to identify all the sub-trees that obey the constraint 172 173 185 162 165 169 189 160 172 173 185 HEIGHT 162 165 169 189 2/24/2019 Min s.t. Constraints, Hanoch Levy CS, TAU
Representing the Function minimized (grade) 172 173 185 162 165 169 189 160 Each leaf marked with its GRADE (not sorted!) Internal nodes keep the minimum grade of the sub-tree. Algorithm: Bring up black values which are roots of red trees. When two values brought up – take min and bring up 60 80 75 50 90 93 60 80 75 95 50 2/24/2019 Min s.t. Constraints, Hanoch Levy CS, TAU
Alternative Description of algorithm (recursive) 90 93 60 80 75 95 50 172 173 185 162 165 169 189 160 Children of node can be of 3 “types”: Black (no node in sub-tree is relevant) Red (all nodes in sub-tree are relevant) “gray” (some nodes in sub-tree are relevant) Algorithm Red: bring its value Black: disregard Gray: bring value computed recursively 2/24/2019 Min s.t. Constraints, Hanoch Levy CS, TAU
Min s.t. Constraints, Hanoch Levy CS, TAU Complexity 90 93 60 80 75 95 50 172 173 185 162 165 169 189 160 Each node has at most one gray Red – O(1) Black – O(1) Gray – continue deeper path of gray is of length O(h) = O(log N). Over all complexity for operation O(log N) 2/24/2019 Min s.t. Constraints, Hanoch Levy CS, TAU