Getting a glimpse of the tree line

-------------------------- go, goal great route!

Tree line bit by bit:

Start with some intuitive perspective:

 

 

The figure is a dichotomy Ah! Questions to myself,

For a given interval [2,12] how it broken down into the above-mentioned range, the decomposition why?

Decomposition method: bottom-up consolidation - is conducive to understanding

First consider the lowermost layer of the tree, all click in the interval [2,12] inside, and then, if the parent node immediately adjacent to the same point,

Then use this instead of the two parent nodes (parent nodes on a layer). After this operation, the remaining layer is present up to two nodes.

If the leftmost selected node is the right child of its parent node, then the node will be left. If the far right of the selected node is the left subtree of its parent node, then the node will be left.

All intermediate nodes have been substituted with a parent node. After completion of the lowermost processing, considering that the layer, the same processing is continued.

Continue to follow the above chart Ah primer:

This segment tree is n = 13, the interval [2,12], the process of following the above described FIG:

 

 

 

 

It can be seen from FIG: n = the segment tree 13, [2, 12] = [2] + [3,4] + [5,7] + [8,10] + [11,12].

Decomposition Method Two: top-down decomposition - in favor computing

 

 

 First, in the range [1,13], calculates (1 + 13) / 2 = 7, then the interval [2,12] "cut" would be [2,7] and [8,12].

Wherein the [2,7] position of the node in [1,7] and [2,7] <[1,7] Therefore continue value decomposition (1 + 7) / 2 = 4, then the [2,7] Cutting to [2,4] and [5,7].

 

 [5,7] at the node position [5,7], so do not continue to decompose, [2,4] in the interval [1,4] position, so continue to break down into [2] and [3,4].

Finally, [2] <[1,2], so the calculation (1 + 2) / 2 = 1, [2] with a cut, the left side is empty, the right side is [2]

Of course, the recursive procedure is calculated, not the calculated layer by layer, shows only the calculation method of FIG, does not represent the order of evaluation.

 -----------------------------------------------------------------------------------------------------------------感谢诗鸿提供的博客图片。

Guess you like

Origin www.cnblogs.com/dragondragon/p/11241530.html