Daa Ha1
Daa Ha1
a Segment Tree, also known as a statistic tree, is a tree data structure used for storing
information about intervals, or segments. It allows querying which of the stored segments
contain a given point. It is, in principle, a static structure; that is, it’s a structure that cannot be
modified once it’s built. A similar data structure is the interval tree.
A segment tree for a set I of n intervals uses O(n log n) storage and can be built in O(n
log n) time. Segment trees support searching for all the intervals that contain a query point in
time O(log n + k), k being the number of retrieved intervals or segments.
–––-
Representation :
Leaf Nodes are the elements of the input array.
Each internal node represents some merging of the leaf nodes. The
merging may be different for different problems. For this problem,
merging is sum of leaf nodes under a node.
An array representation of tree is used to represent Segment Trees.
For each node at index i, the left child is at index (2*i+1), right child
at (2*i+2) and the parent is at (⌊(i – 1) / 2⌋).