Segment Trees
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlwcfVpLbRwsIpCuOcd0FEdOVAAQ0ouoNDJoqSNjFJKmOj607y2ShsKmNqIT9RnqxQ0yQG3OhmmpZ5iylITS6yGzI0SwtGGaa5ptqAiuhU0g8DjyPO0EvaxklhvrM2o7GmIeuDG3BHASE/w482-h284/image.png)
What is segment tree? 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 Minimum Query problem) of all the elements in an array from indices L to R. A segment tree is a heap-like data structure that can be used for making update/query operations upon array intervals in logarithmic time. We define the segment tree for the interval [i, j] in the following recursive manner: the first node will hold the information for the interval [i, j] if i<j the left and right son will hold the information for the intervals [i, (i+j)/2] and [(i+j)/2+1, j] Notice that the height of a segment tree for an interval with N elements is [logN] + 1. Here is how a segment tree for the interval [0, 9] would look like: Some easy problems to exercise your segment trees knowledge: Range sum query - mutable M...