Post by Pavel PetrenkoPost by Pavel PetrenkoOk, makes sense. Can you clarify why this is not the case when
performing a range-search in a kd-tree (2d), which has complexity O(k +
root(n)), where k is the number of keys reported (and not the total
number of keys)?
The running time of range search in a kd tree is O(k + U)
Where k is number of reported points and U is the number of unsuccessful
searches.
U is bounded by root(n).
See slide 16 of module 7 for details.
Post by Pavel PetrenkoNever mind that, I think I get it. Isn't it possible that that (almost)
all points are at a height of h (which can be infinitely large)? So
wouldn't the complexity be O(n*h)?
I'm assuming your asking about quad-trees.
1. if (T is a leaf) then
2. if (T.point in R) then
3. report T.point
4. for each child C of T do
5. if C.region intersects R is not empty then
6. QTree-RangeSearch(C, R)
The analysis hard to explain.
You can view the algo. this way:
Traverse down the quad-tree until you reach a region that has 2 or more
children that intersects the range.
At most every point in this region will have to be visited and checked.
The traversal costs at most h (traverse until leaf node).
The visiting costs at most n (every point).
Therefore Theta(n+h) is the cost.
--
Patrick Lee
CS240 Tutor