Professional Documents
Culture Documents
Prioritytrees
Prioritytrees
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 1 / 22
Priority Search Trees
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 2 / 22
windowing queries
Given a map, we zoom in on a window ⇒ windowing query.
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 3 / 22
problem statement
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 4 / 22
Priority Search Trees
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 5 / 22
the heap
The heap or priority queue is a binary tree
where every node has a higher priority than its children.
90 0
top 65
-
1
?
90 70 2
H
H -
65 70 21 3
@ @ 60 4
21 60 27 17 -
6 27 5
bottom
17 6
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 6 / 22
the construction of a heap
5 5
2 2
1 1
4 4
6 6
3 3
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 7 / 22
the construction of a heap continued
5 5
2 2
1 1
4 4
3 6 3 6
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 8 / 22
a heap for six points
2 5
HH
1 3 1
@ @
4 6 4 2
3 6
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 9 / 22
Priority Search Trees
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 10 / 22
definition of a priority search tree
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 11 / 22
making a priority search tree
Algorithm M AKE P RIORITY S EARCH T REE(P)
Input: P = {p1 , p2 , . . . , pn }, a set of n points in the plane.
Output: the root of the priority search tree for P.
1 if P = ∅ then return empty leaf
else
2 let pmin be the leftmost point of P: pmin = p ∈ P, px = min qx
q∈P
3 ymid is the median of the y -coordinates of P \ {pmid }
4 v = N ODE(pmin , ymid )
5 Pbelow = { p ∈ P \ {pmin } | py < pmid }
6 Pabove = { p ∈ P \ {pmin } | py > pmid }
7 L EFT C HILD(v ) = M AKE P RIORITY S EARCH T REE(Pbelow )
8 R IGHT C HILD(v ) = M AKE P RIORITY S EARCH T REE(Pabove )
9 return v
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 12 / 22
the cost of making a priority search tree
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 13 / 22
Priority Search Trees
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 14 / 22
a query window
qy0 5
1
HH
4
3 1
6 @ @
qy 6 4 2
3
qx
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 15 / 22
reporting in subtrees
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 16 / 22
the cost of reporting in subtrees
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 17 / 22
a split vertex
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 18 / 22
query a priority search tree
Algorithm Q UERY P RIORITY S EARCH T REE(T , W )
Input: T , a priority search tree,
W = (−∞ : qx ] × [qy : qy0 ], a query window.
Output: all points of T ∩ W .
1 let vsplit be the split vertex
2 for each node v on the search path from qy to qy0 do
3 if p(v ) ∈ W , then R EPORT p(v )
4 for each node v on path of qy in L EFT C HILD(vsplit ) do
5 if path goes left at v then
R EPORT I N S UB T REE(R IGHT C HILD(v ), qx )
6 for each node v on path of qy0 in R IGHT C HILD(vsplit ) do
7 if path goes right at v then
R EPORT I N S UB T REE(L EFT C HILD(v ), qx )
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 19 / 22
illustrate the query algorithm
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 20 / 22
the cost to query a priority search tree
Lemma (cost to query a priority search tree)
The Algorithm Q UERY P RIORITY S EARCH T REE on a search tree for n
points reports k points in the query window in O(log(n) + k ) time.
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 21 / 22
recommended assignments
Computational Geometry (MCS 481) Priority Search Trees L-30 3 April 2019 22 / 22