S
S
Sergey2012-01-15 12:50:50
Algorithms
Sergey, 2012-01-15 12:50:50

Nested Sets VS Nested Intervals?

Actually, I stumbled upon the implementation of storing tree structures using nested intervals. Searches didn't turn up much, other than the fact that this method is an attempt to improve on the nested set method. I did not find more detailed information about possible pitfalls, as well as explicit arguments (besides reducing the number of reindexing operations) FOR.
At the moment, I choose a method of storing tree structures, where insert / move / delete operations will be many orders of magnitude rarer than branch selection. So here the optimization of these operations is not essential. But for the future I would like to know which is better.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Sundukov, 2012-01-15
@alekciy

On the vskidka for NI, there is such a minus - the exhaustion of the sizes of the left and right keys, when you have to switch from, say, int to bigint. Depends on the ratio of the size of the tree and the pitch for the holes in the keys. In principle, not a problem, it just takes a little more resources. But it’s worth thinking about such things in advance, so that it doesn’t turn out that at the most inopportune moment there will not be enough resources.
Algorithmic minus compared to NS - knowing the left and right keys of the node, it is impossible to calculate the number of descendants, but in NS it is possible. For example, if the catalog of goods is stored in NS, then for the current category (node) you can specify the number of goods / number of subsections / other simply by getting this category and not getting its descendants.
In general, these or those pluses/minuses can be considered in the context of the size of the tree, the ratio of number_of_selections/number_of_inserts, and hardware resources.

M
max_mara, 2012-01-15
@max_mara

In nested sets, the problem I encountered is that there must be a root category, otherwise everything fell like a forest for me. From time to time, my keys were knocked off and the structure of the tree also crumbled.
Therefore, in addition to keys, we always have a parent_id, by which we can always restore the tree. There were no more problems.
We are pleased with the convenience of sampling, if there is deep nesting, you do not need to get all the branches by recursion, everything is done in one query.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question