Posts

Showing posts with the label Update Range

Segment Tree

Image
Segment Tree is used in cases where there are multiple range queries on array and modifications of elements of the same array. For example, finding the sum of all the elements in an array from indices  L  to  R , or finding the minimum (famously known as Range Minumum Query problem) of all the elements in an array from indices  L  to  R . These problems can be easily solved with one of the most versatile data structures,  Segment Tree .       Notes: The root of the segment tree contains the whole array A[0: N-1] There are N leaves representing theN elements of the array.  The number of internal nodes is N−1.  Total number of nodes are 2*N-1. Operations( Templates) :- Build :  void build ( int node , int start , int end ) { if ( start == end ) { // Leaf node will have a single element tree [ node ] = A [ start ]; } else { int m...