what is the sum of the greatest and the smallest segments given below?
1) what is the sum of the length of the greatest
and Smallest segment given below?
Seg CB , Seg EB , Seg EQ , Seg QG
Answers
Answered by
2
To find the sum of the greatest and the smallest segments, we need to compute the sum of the elements in the given range by looping from l to r. Simply type arr[i] = x to modify a value. The second action only needs O(1) time, whereas the first operation takes O(n) time.
- 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.
- Recursion can be used to create a segment tree (bottom-up approach ). Update the corresponding changes in the nodes along the path from the leaves to the root beginning at the leaves and working your way up. One element is symbolised by leaves. An internal parent node is created in each step using the information from two child nodes. Each internal node will represent the union of the intervals of its children. For various questions, merging may take different forms. Recursion will therefore arrive at the root node, which will stand in for the entire array.
- A simple solution is to compute the sum of the elements in the given range by looping from l to r. Simply type arr[i] = x to modify a value. The second action only needs O(1) time, whereas the first operation takes O(n) time.
Hence, to find the sum of the greatest and the smallest segments, we need to compute the sum of the elements in the given range by looping from l to r. Simply type arr[i] = x to modify a value. The second action only needs O(1) time, whereas the first operation takes O(n) time.
Learn more here
https://brainly.in/question/21250331
#SPJ1
Similar questions
Social Sciences,
1 month ago
Computer Science,
1 month ago
Science,
2 months ago
Math,
2 months ago
Physics,
10 months ago
History,
10 months ago
Math,
10 months ago