Miscellaneous
Segment & Binary Index Tree & Disjointed
SetsSegment Tree ( simple )
import java.util.*;
import java.io.*;
import java.lang.*;
class GFG {
static int getSum(int arr[], int qs, int qe) {
int sum = 0;
for (int i = qs; i <= qe; i++)
sum = sum + arr[i];
return sum;
}
static void update(int arr[], int i, int newVal) {
arr[i] = newVal;
}
public static void main(String args[]) {
int arr[] = { 10, 20, 30, 40, 50 }, n = 5;
System.out.print(getSum(arr, 0, 2) + " ");
System.out.print(getSum(arr, 1, 3) + " ");
update(arr, 1, 60);
System.out.print(getSum(arr, 0, 2) + " ");
System.out.print(getSum(arr, 1, 3) + " ");
}
}Segment Tree Prefix Sum
Constructing Segment Tree
Range Query on Segment Tree
Update Query on Segment Tree
Binary Indexed Tree ( Prefix Sum Implementation )
Binary Indexed Tree ( Update Operation )
Segment Tree ( simple )
Segment Tree Prefix Sum
Constructing Segment Tree
Range Query on Segment Tree
Update Query on Segment Tree
Binary Indexed Tree ( Prefix Sum Implementation )
Binary Indexed Tree ( Update Operation )
Last updated