Download presentation
Presentation is loading. Please wait.
1
Chapter 14: Augmenting Data Structures
2
Dynamic order statistics
QUERY: OS(x,i) – the node containing the i-th smallest element in the subtree rooted at x How to augment so that the following can be done efficiently: The query itself Maintaining augmented data (under Insert, Delete)
3
Added field to red-black trees: size(x): # nodes in the subtree rooted at x
Process the query Determine the rank of an element x Count size[left[x]]+1. When climbing left (since right child of parent) increment count by size[left[parent[x]]]+1
4
Maintaining subtree sizes
Since the main tool for insert/delete Theorem: Query, Insert, Delete still take O(log n) time each
5
Interval trichotomy for 2 closed intervals i and i’
i and i’ can overlap in 4 ways or to not overlap in 2 ways: Each way is represented by conditions on (some subset of) low(i),high(i),low(i’),high(i’)
6
Interval trees Red Black tree by left(i) of intervals
INTERVAL-SEARCH(T,i) – find a node in T whose interval overlaps interval i or report: none exists Start with root. If i does not overlap current node x of T, then if max[left[x]]>=low(i) proceed to left[x]; else proceed to right[x]
7
Theorem: INTERVAL-SEARCH is correct
Proof: Case (a). INTERVAL-SEARCH goes right. No interval on left subtree can overlap I. Case (b). INTERVAL-SEARCH goes left. If no interval in left the subtree overlaps i, also no interval of of the right subtree could overlap i.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.