Lecture 6-cs345-2014
-
Upload
rajiv-omar -
Category
Technology
-
view
67 -
download
0
Transcript of Lecture 6-cs345-2014
Design and Analysis of Algorithms(CS345/CS345A)
Lecture 6
Augmented BST for • Dynamic sequences
• Orthogonal range searching
1
The fundamental question we answered in last class
Question: What makes BST pervasive in the world of data structures ?
Answer: Augmentation : “storing extra fields at each node”
: Additional information
DATA STRUCTURES FORDYNAMIC SEQUENCES
3
Dynamic Sequence
4
OR
OR
Representing sequence using a BST
8
4
1 2
1
3
1 1
: size field
6
u
7
T
We need to do the rebalancing of
height later on.
Example 2: sequence of numbers
8
Performing Add(T,i,j,x)
9
iT
View the entire tree T from perspective of the paths from i
and j to the root. How will T look like ?
j
LCA(i,j)
Performing Add(T,i,j,x)
10
T
j
i
LCA(i,j)
What are the nodes whose values has to be incremented by x ?
Performing Add(T,i,j,x)
11
T
What are the nodes whose values has to be incremented by x ?
j
i
LCA(i,j)
Performing Add(T,i,j,x)
12
T
What are the nodes whose values has to be incremented by x ?
j
i
LCA(i,j)
Performing Add(T,i,j,x)
13
Key observations about the data structure
14
Homework
15
Example 2: sequence of bits
16
Example 3: sequence of numbers
17
ORTHOGONAL RANGE SEARCHING
Hopefully you have got a fair amount of understanding of augmenting a BST by now. Think over this problem for a while before proceeding
further.
18
Orthogonal Range searching
19
Rectangle
No. of points in query rectangle
Orthogonal Range searching
20
Rectangle
Orthogonal Range searching
21
22
T
LCA
• Binary search tree on x-coordinates
23
T
LCA
• Binary search tree on x-coordinates
24
T
LCA
• Binary search tree on x-coordinates
25
T
LCA
How should we augment each node?
26
left right
valueColor-bit
Augment each node v with a pointer to another BSTstoring all points of T(v) according to y-oordinates.
Y-tree
v
BST storing T(v)
according to y-coordinate
27
T
LCA
Homework
28
Space of the data structure
29
T
1
2
3
4
. . .. . .
BST before augmentation
Space of the data structure
30
T
. . .
. . .
BST before augmentation
Total time to build the data structure
31
p