0

I understand that segment trees can be used to find the sum of sub array of A. And that this can done in O(logn) time according to the tutorial here.

However I'm not able to prove that the querying time is indeed O(logn). This link (and many others) say that we can prove that at each level, the maximum number of nodes processed is 4 and so O(4logn) == O(logn). But how do we prove this, perhaps by contradiction?

And if so, if we were to use segment trees for ranged sum of higher dimensional arrays, how would the proof be extended?

For example, I can think of finding a sub matrix sum by dividing the original matrix into 4 quadrants (similar to halving intervals in linear arrays) building a quadrant segment tree but the proof eludes me.

  • 1
    Hi. This doesn't seem to be [on-topic](http://stackoverflow.com/help/on-topic) for Stack Overflow because it doesn't relate to a *specific instance of* a programming problem. Perhaps you should try asking this on one of the [other](http://stackexchange.com/sites#technology) Stack Exchange [sites](http://stackexchange.com/sites#science) instead? – GoBusto Jan 26 '15 at 08:42
  • The _specific instance_ problem statement is to 'Given an integer array A, design a data structure that allows ranged sum queries (i.e. given an interval (i,j) where i <= j < A.Length return A[i] + A[i+1] + A[i+2] ...A[j]) and updating the array both in logarithmic time (O(logn)). – Arijit Choudhury Jan 27 '15 at 01:55
  • That's not quite what I meant by specific instance. Given that this is a general algorithm problem, this question might be more suited to the [Computer Science](http://cs.stackexchange.com/help/on-topic) or [Computational Science](http://scicomp.stackexchange.com/help/on-topic) Stack Exchange sites instead. – GoBusto Jan 27 '15 at 08:40
  • Ah, I see. Thanks! I'll post it there. – Arijit Choudhury Jan 27 '15 at 20:04

0 Answers0