1 / 12

Maintaining A Dynamic Tree with Min Subject to Constraints

Maintaining A 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.

Download Presentation

Maintaining A Dynamic Tree with Min Subject to Constraints

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Maintaining ADynamic Tree with Min Subject to Constraints Data Structures 2003 CS TAU

  2. 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. Min s.t. Constraints, Hanoch Levy CS, TAU

  3. 97 8 50 81 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 HEIGHT 185 160 172 173 Min s.t. Constraints, Hanoch Levy CS, TAU

  4. 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) Min s.t. Constraints, Hanoch Levy CS, TAU

  5. 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). Min s.t. Constraints, Hanoch Levy CS, TAU

  6. 97 8 50 81 Real Life Example • Router • Packets arrive at arbitrary times • Want to schedule the earliest packetssubject to minimum grade • Or – another variation GRADE ARRIVAL TIME 185 160 172 173 Min s.t. Constraints, Hanoch Levy CS, TAU

  7. 97 8 50 81 An (inefficient) data structure: 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 HEIGHT 185 160 172 173 Min s.t. Constraints, Hanoch Levy CS, TAU

  8. HEIGHT 172 185 165 172 185 165 162 169 173 189 162 169 173 189 172 173 185 189 160 162 165 169 172 173 185 162 165 169 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 Min s.t. Constraints, Hanoch Levy CS, TAU

  9. 50 172 185 60 165 50 50 162 75 169 173 80 189 60 160 172 173 185 189 162 165 169 50 95 75 80 93 60 80 90 Representing the Function Being Minimized (Grade) • 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 Min s.t. Constraints, Hanoch Levy CS, TAU

  10. 50 172 185 60 165 50 50 162 75 169 173 80 189 60 160 172 173 185 189 162 165 169 50 95 75 80 93 60 80 90 Alternative Description of algorithm (recursive) • 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 • Child Red: bring its value • Child Black: disregard • Child Gray: bring value computed recursively Min s.t. Constraints, Hanoch Levy CS, TAU

  11. 50 172 185 60 165 50 50 162 75 169 173 80 189 60 160 172 173 185 189 162 165 169 50 95 75 80 93 60 80 90 How to identify “colors” and run recursion • If val(node) > h (e.g h=169) • Bring value of right child • Compute recursively on left Child • If val(node) = h • Bring value of right child • If val(node) < h • Compute recursively on right Child recursion goes only one side Min s.t. Constraints, Hanoch Levy CS, TAU

  12. 50 172 185 60 165 50 50 162 75 169 173 80 189 60 160 172 173 185 189 162 165 169 50 95 75 80 93 60 80 90 Complexity • 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) • Average complexity: Min s.t. Constraints, Hanoch Levy CS, TAU

More Related