Segment time complexity analysis

How can we prove that the operations updateand queryin the tree segments ( http://letuskode.blogspot.in/2013/01/segtrees.html ) (not to be confused with wood intervals) are O(log n)?

I thought about how to do this: on each node we make no more than two recursive calls on the left and right subtrees. If we could prove that one of these calls completes fairly quickly, the complexity of the time would be logarithmically limited. But how do we prove it?

+6
source share
3 answers

Lemma: no more than two nodes are used at each tree level (a level is a set of nodes with a fixed distance from the root).
Evidence. Suppose that at hleast 3 nodes were used at the level (let's call them L, Mand R). This means that the entire interval from the left border of the Lnode to the right border of the Rnode is within the query range. Therefore, the Mnode (let it be called UP) is completely covered from a level h - 1that lies completely within the range of requests. But this means that Mit cannot be visited at all, because the crawl will stop at UPnode or higher. Here are some pictures to clarify this step of the proof:

 h - 1:  UP          UP        UP
         /\          /\        /\
 h:     L  M R    L M  R    L  M   R

. log N , 2 * log N.

+10

, 2 , . . , .

enter image description here

, 3 , . , . , , . , . , , 2 , log⁡n, 2⋅logn = Θ (logn)

+1

, . , T(l, r) n = l - r, 2 * log n . , T(1, 17) 8 , 6. 2 * log n - 2, , 1. , 1. , , , node. T(1, 17), [1, 9) [9-17] 1. [1, 9), node, , .

0
source

All Articles