Segment Tree

Segment Tree | Set 1 (Sum of given range) Let us consider the following problem to understand Segment Trees. We have an array arr[0 . . . n-1]. We should be able to 1 Find the sum of elements from index l to r where 0 <= l <= r <= n-1 2 Change value of a specified element of the array arr[i] = x where 0 <= i <= n-1.


Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. Would be better if you explained what the variables in the code mean. Good work with the code though. Could improve it by not initializing the st array with all zeros, since if the tree is not complete it wastes space.

    ReplyDelete

Post a Comment