CS6100: Topics in Design and Analysis of Algorithms
Range Searching John Augustine
CS6100 (Even 2012): Range Searching
CS6100: Topics in Design and Analysis of Algorithms Range Searching - - PDF document
CS6100: Topics in Design and Analysis of Algorithms Range Searching John Augustine CS6100 (Even 2012): Range Searching The Range Searching Problem Given a set P of n points in R d , for fixed integer d 1 , we want to preprocess and store
CS6100 (Even 2012): Range Searching
date of birth salary
19,500,000 19,559,999 3,000 4,000
born: Aug 19, 1954 salary: $3,500
19,500,000 19,559,999 3,000 4,000 2 4
CS6100 (Even 2012): Range Searching 1
CS6100 (Even 2012): Range Searching 2
µ µ′ 3 10 19 23 30 37 49 59 62 70 80 89 3 19 10 30 37 59 70 62 100 89 80 23 49 100 105
CS6100 (Even 2012): Range Searching 3
νsplit µ µ′ root(T) the selected subtrees
CS6100 (Even 2012): Range Searching 4
CS6100 (Even 2012): Range Searching 5
Head Pointer CS6100 (Even 2012): Range Searching 6
CS6100 (Even 2012): Range Searching 7
CS6100 (Even 2012): Range Searching 8
CS6100 (Even 2012): Range Searching 9
CS6100 (Even 2012): Range Searching 10
CS6100 (Even 2012): Range Searching 11
date of birth salary
19,500,000 19,559,999 3,000 4,000
born: Aug 19, 1954 salary: $3,500
CS6100 (Even 2012): Range Searching 12
ℓ P
left
P
right
CS6100 (Even 2012): Range Searching 13
p4 p1 p5 p3 p2 p7 p9 p10 p6 p8 ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓ8 ℓ9 p1 p2 ℓ8 ℓ4 ℓ2 ℓ1 ℓ5 p3 p4 p5 p6 p7 p8 p9 p10 ℓ7 ℓ6 ℓ9 ℓ3 Algorithm BUILDKDTREE(P,depth)
1. if P contains only one point 2. then return a leaf storing this point 3. else if depth is even 4. then Split P into two subsets with a vertical line ℓ through the median x-coordinate
1 be the set of points to the left of ℓ or on ℓ, and let
P
2 be the set of points to the right of ℓ.
5. else Split P into two subsets with a horizontal line ℓ through the median y- coordinate of the points in P. Let P
1 be the set of points below ℓ or on ℓ,
and let P
2 be the set of points above ℓ.
6. νleft ← BUILDKDTREE(P
1,depth+1)
7. νright ← BUILDKDTREE(P
2,depth+1)
8. Create a node ν storing ℓ, make νleft the left child of ν, and make νright the right child of ν. 9. return ν
CS6100 (Even 2012): Range Searching 14
CS6100 (Even 2012): Range Searching 15
ℓ1 ℓ2 ℓ3 ν region(ν) ℓ3 ℓ2 ℓ1
CS6100 (Even 2012): Range Searching 16
CS6100 (Even 2012): Range Searching 17
CS6100 (Even 2012): Range Searching 18
CS6100 (Even 2012): Range Searching 19
νsplit µ µ
CS6100 (Even 2012): Range Searching 20
T P(ν) ν Tassoc(ν) P(ν) binary search tree
binary search tree on x-coordinates Algorithm BUILD2DRANGETREE(P)
1. Construct the associated structure: Build a binary search tree Tassoc on the set P
y of y-
coordinates of the points in P. Store at the leaves of Tassoc not just the y-coordinate of the points in P
y, but the points themselves.
2. if P contains only one point 3. then Create a leaf ν storing this point, and make Tassoc the associated structure of ν. 4. else Split P into two subsets; one subset P
left contains the points with x-coordinate less
than or equal to xmid, the median x-coordinate, and the other subset P
right contains
the points with x-coordinate larger than xmid. 5. νleft ← BUILD2DRANGETREE(P
left)
6. νright ← BUILD2DRANGETREE(P
right)
7. Create a node ν storing xmid, make νleft the left child of ν, make νright the right child of ν, and make Tassoc the associated structure of ν. 8. return ν CS6100 (Even 2012): Range Searching 21
Algorithm 2DRANGEQUERY(T,[x : x′]×[y : y′])
1. νsplit ←FINDSPLITNODE(T,x,x′) 2. if νsplit is a leaf 3. then Check if the point stored at νsplit must be reported. 4. else (∗ Follow the path to x and call 1DRANGEQUERY on the subtrees right of the
5. ν ← lc(νsplit) 6. while ν is not a leaf 7. do if x xν 8. then 1DRANGEQUERY(Tassoc(rc(ν)),[y : y′]) 9. ν ← lc(ν) 10. else ν ← rc(ν) 11. Check if the point stored at ν must be reported. 12. Similarly, follow the path from rc(νsplit) to x′, call 1DRANGEQUERY with the range [y : y′] on the associated structures of subtrees left of the path, and check if the point stored at the leaf where the path ends must be reported. CS6100 (Even 2012): Range Searching 22
CS6100 (Even 2012): Range Searching 23