Download presentation
Presentation is loading. Please wait.
Published byJuniper Caldwell Modified over 8 years ago
1
CS 6310 Advanced Data Structures Tree Structures for Set of Intervals by Halil Ibrahim DURSUNOGLU
2
OUTLINE Interval Trees Segment Trees Trees for the Union of Intervals Trees for Sums of Weighted Intervals Trees for Interval-Restricted Maximum Sum Queries
3
Interval Trees Stores a set of intervals Returns for any query key all the intervals that contain this query value Each interval [ai,bi] The key of node is contained The interval is contained in the interrval associated with the node.
4
Interval Trees (Cont.)
5
If query_key < n_key we set list to n->left_list while list != NULL and list->key <= query_key Else query_key >= n->key we set list to n->right_list While list!=NULL and list->key >=query_key
6
Interval Trees (Cont.) Every level there is at most one associated node If query_key key left endpoint key <= right end point If query_key > node->key left endpoint key <= query_key <= right endpoint
7
OUTLINE Interval Trees Segment Trees Trees for the Union of Intervals Trees for Sums of Weighted Intervals Trees for Interval-Restricted Maximum Sum Queries
8
Segment Trees Keeping track of a set of n intervals Performance is worser than interval tree A number of more general tasks can be done
9
Segment Tree (Cont.)
10
OUTLINE Interval Trees Segment Trees Trees for the Union of Intervals Trees for Sums of Weighted Intervals Trees for Interval-Restricted Maximum Sum Queries
11
Trees for the Union of Intervals It comes with a problem whether it is possible to determine the measure (length) of a union of n intervals in time better than Theta(n logn). Simple solution: Sort interval endpoints Sweep from the smallest end point up Keep track of the number of intervals
12
Trees for the Union of Intervals Two dimensional measure problems: Structure maintaining measure of intervals under insertion and deletion Each node contains n->measure if n->interval_list != NULL n->measure is length of node interval of n if n is leaf and n->interval_list = NULL n->measure = 0 if n is interior and n->interval_list = NULL n->measure = n->left->measure + n->right->measure
13
Trees for the Union of Intervals We need associated intervals as concept n->measure is the measure of the intersection of the node with the union of all its associated intervals n->rightmax is the maximum right end point all of interval associated with n n->leftmin the minimum leftendpoint of all intervals associated with n
14
Trees for The Union of Intervals
15
Trees for the Union of Intervals In order to make query easier, we need to some additional fields n->leftmin n->leftmax n->rigtmin n->rightmax n->next // is the pointer to the leaf with next larger key
16
Trees for the Union of Intervals n->transfer // is the pointer to the highest node v with v->left->rightmin = n and v->left->rightmax->key >= v->key
17
OUTLINE Interval Trees Segment Trees Trees for the Union of Intervals Trees for Sums of Weighted Intervals Trees for Interval-Restricted Maximum Sum Queries
18
Trees for Sums of Weighted Intervals Simple but useful application Keeps track of a piecewise constant function
19
Trees for Sums of Weighted Intervals Some source like electricity Resource used by various system Time interval at a constant level To construct it, segment tree is used Ask only for the number of covering intervals
20
Trees for Sums of Weighted Intervals Easy to built but need extra fields n->summand To insert a weighted interval, firstly insert interval endpoint
21
OUTLINE Interval Trees Segment Trees Trees for the Union of Intervals Trees for Sums of Weighted Intervals Trees for Interval-Restricted Maximum Sum Queries
22
Same objects, piecewise constant functions or set of weighted invertal but supporting even stronger queries
23
Trees for Interval-Restricted Maximum Sum Queries
24
Built like Segment Trees Has additional fields to Trees for Sums of Weighted Intervals n->partial_sum O(logn)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.