2

Let us consider the following picture enter image description here

this is a so called range tree. I don't understand one thing, it looks similar to a binary search tree, so if we are inserting elements, we can use the same procedure as during binary search tree insertion. So what is the difference?

I have read a tutorial and guess that it is a varation of kd trees, query search trees (like geometric point searching, and so on) but how to construct it? Like binary search tree or does it need additional parameters? Maybe like this

struct  range
{
int lowerbound;
int upperbound,
int element;

};

and during insertion we have to check

 if(element>lowerbound && element <upperbound) 
then insert node

Please help me to understand correctly how to construct a range tree.

user541686
  • 205,094
  • 128
  • 528
  • 886

1 Answers1

3

In binary search tree when you insert a value you insert a new node.

The range search tree is more similar to binary index tree. These two data structures have fixed structures. When you add / subtract a point to a given range you update the values in the nodes, but do not introduce new nodes.

The construction of this structure is much similar to that of KD-tree: based on the given points you choose the most appropriate points of splitting.

When you learn new data structure always consider the supported operations - this will help you understand the structure faster. In your case it would have helped you distinguish between binary search tree and range tree.

Boris Strandjev
  • 46,145
  • 15
  • 108
  • 135
  • but at the begining when i have empty tree,have i create new node?i meant from starting position – Aleksi Beriashvili Sep 09 '12 at 09:36
  • @AleksiBeriashvili In the task you solve with range tree you are initially given a set of intervals with which you construct the tree. Thus you actually start with n nodes not empty tree. after the initial construction you just alter the values of the nodes, but do not add/delete nodes. – Boris Strandjev Sep 09 '12 at 09:43
  • so as i understood ,i just construct binary tree from initial intervals(like binary search tree) and then just update values right?sure update operation searching for some specific value is similar to binary search method right? – Aleksi Beriashvili Sep 09 '12 at 09:44
  • @AleksiBeriashvili I really think you do not understand the supported operations by the data structure. Please consider this pdf, I think it will be of help: http://people.csail.mit.edu/radu/6854proj.pdf – Boris Strandjev Sep 09 '12 at 09:50
  • @BorisStrandjev: It is explicitly cited in this paper that you may add or delete intervals, I would say that the tree structure will change if you do so... won't it ? – Matthieu M. Sep 09 '12 at 12:41
  • @MatthieuM. in this case inserting the interval does not change the tree: the considered tree should answer how many intervals a point fits in - thus adding an interval actually just changes the value of a node. – Boris Strandjev Sep 10 '12 at 07:20
  • Ah! This is not what I generally call an interval tree, so it makes sense now: I was thinking of something else :) – Matthieu M. Sep 18 '12 at 23:10