dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class BinaryTree { Node root ; Node findLCA ( int n1 , int n2 ) { return findLCA ( root , n1 , n2 ) ; } Node findLCA ( Node node , int n1 , int n2 ) { if ( node == null ) return null ; if ( node . data == n1 node . data == n2 ) return node ; Node left_lca = findLCA ( node . left , n1 , n2 ) ; Node right_lca = findLCA ( node . right , n1 , n2 ) ; if ( left_lca != null && right_lca != null ) return node ; return ( left_lca != null ) ? left_lca : right_lca ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . right . left = new Node ( 6 ) ; tree . root . right . right = new Node ( 7 ) ; System . out . println ( " LCA ( 4 , ▁ 5 ) ▁ = ▁ " + tree . findLCA ( 4 , 5 ) . data ) ; System . out . println ( " LCA ( 4 , ▁ 6 ) ▁ = ▁ " + tree . findLCA ( 4 , 6 ) . data ) ; System . out . println ( " LCA ( 3 , ▁ 4 ) ▁ = ▁ " + tree . findLCA ( 3 , 4 ) . data ) ; System . out . println ( " LCA ( 2 , ▁ 4 ) ▁ = ▁ " + tree . findLCA ( 2 , 4 ) . data ) ; } }

Class/struct names: BinaryTree, Node
Java program:
class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class BinaryTree { Node root ; static boolean v1 = false , v2 = false ; Node findLCAUtil ( Node node , int n1 , int n2 ) { if ( node == null ) return null ; Node temp = null ; if ( node . data == n1 ) { v1 = true ; temp = node ; } if ( node . data == n2 ) { v2 = true ; temp = node ; } Node left_lca = findLCAUtil ( node . left , n1 , n2 ) ; Node right_lca = findLCAUtil ( node . right , n1 , n2 ) ; if ( temp != null ) return temp ; if ( left_lca != null && right_lca != null ) return node ; return ( left_lca != null ) ? left_lca : right_lca ; } Node findLCA ( int n1 , int n2 ) { v1 = false ; v2 = false ; Node lca = findLCAUtil ( root , n1 , n2 ) ; if ( v1 && v2 ) return lca ; return null ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . right . left = new Node ( 6 ) ; tree . root . right . right = new Node ( 7 ) ; Node lca = tree . findLCA ( 4 , 5 ) ; if ( lca != null ) System . out . println ( " LCA ( 4 , ▁ 5 ) ▁ = ▁ " + lca . data ) ; else System . out . println ( " Keys ▁ are ▁ not ▁ present " ) ; lca = tree . findLCA ( 4 , 10 ) ; if ( lca != null ) System . out . println ( " LCA ( 4 , ▁ 10 ) ▁ = ▁ " + lca . data ) ; else System . out . println ( " Keys ▁ are ▁ not ▁ present " ) ; } }

Boolean variables: v1, v2
Class/struct names: BinaryTree, Node
Java program:
import java . util . HashMap ; import java . util . Map ; class Node { int key ; Node left , right , parent ; Node ( int key ) { this . key = key ; left = right = parent = null ; } } class BinaryTree { Node root , n1 , n2 , lca ; Node insert ( Node node , int key ) { if ( node == null ) return new Node ( key ) ; if ( key < node . key ) { node . left = insert ( node . left , key ) ; node . left . parent = node ; } else if ( key > node . key ) { node . right = insert ( node . right , key ) ; node . right . parent = node ; } return node ; } Node LCA ( Node n1 , Node n2 ) { Map < Node , Boolean > ancestors = new HashMap < Node , Boolean > ( ) ; while ( n1 != null ) { ancestors . put ( n1 , Boolean . TRUE ) ; n1 = n1 . parent ; } while ( n2 != null ) { if ( ancestors . containsKey ( n2 ) != ancestors . isEmpty ( ) ) return n2 ; n2 = n2 . parent ; } return null ; } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = tree . insert ( tree . root , 20 ) ; tree . root = tree . insert ( tree . root , 8 ) ; tree . root = tree . insert ( tree . root , 22 ) ; tree . root = tree . insert ( tree . root , 4 ) ; tree . root = tree . insert ( tree . root , 12 ) ; tree . root = tree . insert ( tree . root , 10 ) ; tree . root = tree . insert ( tree . root , 14 ) ; tree . n1 = tree . root . left . right . left ; tree . n2 = tree . root . left ; tree . lca = tree . LCA ( tree . n1 , tree . n2 ) ; System . out . println ( " LCA ▁ of ▁ " + tree . n1 . key + " ▁ and ▁ " + tree . n2 . key + " ▁ is ▁ " + tree . lca . key ) ; } }

Class/struct names: BinaryTree, Node
Java program:
import java . util . HashMap ; import java . util . Map ; class Node { int key ; Node left , right , parent ; Node ( int key ) { this . key = key ; left = right = parent = null ; } } class BinaryTree { Node root , n1 , n2 , lca ; Node insert ( Node node , int key ) { if ( node == null ) return new Node ( key ) ; if ( key < node . key ) { node . left = insert ( node . left , key ) ; node . left . parent = node ; } else if ( key > node . key ) { node . right = insert ( node . right , key ) ; node . right . parent = node ; } return node ; } int depth ( Node node ) { int d = - 1 ; while ( node != null ) { ++ d ; node = node . parent ; } return d ; } Node LCA ( Node n1 , Node n2 ) { int d1 = depth ( n1 ) , d2 = depth ( n2 ) ; int diff = d1 - d2 ; if ( diff < 0 ) { Node temp = n1 ; n1 = n2 ; n2 = temp ; diff = - diff ; } while ( diff -- != 0 ) n1 = n1 . parent ; while ( n1 != null && n2 != null ) { if ( n1 == n2 ) return n1 ; n1 = n1 . parent ; n2 = n2 . parent ; } return null ; } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = tree . insert ( tree . root , 20 ) ; tree . root = tree . insert ( tree . root , 8 ) ; tree . root = tree . insert ( tree . root , 22 ) ; tree . root = tree . insert ( tree . root , 4 ) ; tree . root = tree . insert ( tree . root , 12 ) ; tree . root = tree . insert ( tree . root , 10 ) ; tree . root = tree . insert ( tree . root , 14 ) ; tree . n1 = tree . root . left . right . left ; tree . n2 = tree . root . right ; tree . lca = tree . LCA ( tree . n1 , tree . n2 ) ; System . out . println ( " LCA ▁ of ▁ " + tree . n1 . key + " ▁ and ▁ " + tree . n2 . key + " ▁ is ▁ " + tree . lca . key ) ; } }

Accumulator variables: diff
Class/struct names: BinaryTree, Node
Java program:
import java . util . LinkedList ; class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = null ; right = null ; } } class BinaryTree { static Node root ; static Node findLCA ( Node root , int n1 , int n2 ) { if ( root == null ) return null ; if ( root . data == n1 root . data == n2 ) return root ; Node left_lca = findLCA ( root . left , n1 , n2 ) ; Node right_lca = findLCA ( root . right , n1 , n2 ) ; if ( left_lca != null && right_lca != null ) return root ; return ( left_lca != null ) ? left_lca : right_lca ; } static boolean printAncestors ( Node root , int target ) { if ( root == null ) return false ; if ( root . data == target ) { System . out . print ( root . data + " ▁ " ) ; return true ; } if ( printAncestors ( root . left , target ) || printAncestors ( root . right , target ) ) { System . out . print ( root . data + " ▁ " ) ; return true ; } return false ; } static boolean findCommonNodes ( Node root , int first , int second ) { Node LCA = findLCA ( root , first , second ) ; if ( LCA == null ) return false ; printAncestors ( root , LCA . data ) ; return true ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . right . left = new Node ( 6 ) ; tree . root . right . right = new Node ( 7 ) ; tree . root . left . left . left = new Node ( 8 ) ; tree . root . right . left . left = new Node ( 9 ) ; tree . root . right . left . right = new Node ( 10 ) ; if ( findCommonNodes ( root , 9 , 7 ) == false ) System . out . println ( " No ▁ Common ▁ nodes " ) ; } }

Class/struct names: BinaryTree, Node
Java program:
public class PrintPost { static int preIndex = 0 ; void printPost ( int [ ] in , int [ ] pre , int inStrt , int inEnd ) { if ( inStrt > inEnd ) return ; int inIndex = search ( in , inStrt , inEnd , pre [ preIndex ++ ] ) ; printPost ( in , pre , inStrt , inIndex - 1 ) ; printPost ( in , pre , inIndex + 1 , inEnd ) ; System . out . print ( in [ inIndex ] + " ▁ " ) ; } int search ( int [ ] in , int startIn , int endIn , int data ) { int i = 0 ; for ( i = startIn ; i < endIn ; i ++ ) if ( in [ i ] == data ) return i ; return i ; } public static void main ( String ars [ ] ) { int in [ ] = { 4 , 2 , 5 , 1 , 3 , 6 } ; int pre [ ] = { 1 , 2 , 4 , 5 , 3 , 6 } ; int len = in . length ; PrintPost tree = new PrintPost ( ) ; tree . printPost ( in , pre , 0 , len - 1 ) ; } }

Index/key variables: i, inIndex
Accumulator variables: i, preIndex
Iterator variables: i
Class/struct names: PrintPost
Java program:
class Node { int key ; Node left , right ; public Node ( int item ) { key = item ; left = right = null ; } }

Class/struct names: Node
Java program:
class Node { int key ; Node left , right ; public Node ( int key ) { this . key = key ; left = right = null ; } } class Res { int r = Integer . MIN_VALUE ; } public class BinaryTree { Node root ; int maxDiffUtil ( Node t , Res res ) { if ( t == null ) return Integer . MAX_VALUE ; if ( t . left == null && t . right == null ) return t . key ; int val = Math . min ( maxDiffUtil ( t . left , res ) , maxDiffUtil ( t . right , res ) ) ; res . r = Math . max ( res . r , t . key - val ) ; return Math . min ( val , t . key ) ; } int maxDiff ( Node root ) { Res res = new Res ( ) ; maxDiffUtil ( root , res ) ; return res . r ; } void inorder ( Node root ) { if ( root != null ) { inorder ( root . left ) ; System . out . print ( root . key + " " ) ; inorder ( root . right ) ; } } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 8 ) ; tree . root . left = new Node ( 3 ) ; tree . root . left . left = new Node ( 1 ) ; tree . root . left . right = new Node ( 6 ) ; tree . root . left . right . left = new Node ( 4 ) ; tree . root . left . right . right = new Node ( 7 ) ; tree . root . right = new Node ( 10 ) ; tree . root . right . right = new Node ( 14 ) ; tree . root . right . right . left = new Node ( 13 ) ; System . out . println ( " Maximum ▁ difference ▁ between ▁ a ▁ node ▁ and " + " ▁ its ▁ ancestor ▁ is ▁ : ▁ " + tree . maxDiff ( tree . root ) ) ; } }

Class/struct names: BinaryTree, Node, Res
Java program:
import java . util . ArrayList ; public class PrintCommonPath { static boolean v1 = false , v2 = false ; class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } static Node findLCAUtil ( Node node , int n1 , int n2 ) { if ( node == null ) return null ; Node temp = null ; if ( node . data == n1 ) { v1 = true ; temp = node ; } if ( node . data == n2 ) { v2 = true ; temp = node ; } Node left_lca = findLCAUtil ( node . left , n1 , n2 ) ; Node right_lca = findLCAUtil ( node . right , n1 , n2 ) ; if ( temp != null ) return temp ; if ( left_lca != null && right_lca != null ) return node ; return ( left_lca != null ) ? left_lca : right_lca ; } static boolean find ( Node root , int k ) { if ( root == null ) return false ; if ( root . data == k || find ( root . left , k ) || find ( root . right , k ) ) return true ; return false ; } static Node findLCA ( Node root , int n1 , int n2 ) { Node lca = findLCAUtil ( root , n1 , n2 ) ; if ( v1 && v2 || v1 && find ( lca , n2 ) || v2 && find ( lca , n1 ) ) return lca ; return null ; } static boolean hasPath ( Node root , ArrayList < Integer > arr , int x ) { if ( root == null ) return false ; arr . add ( root . data ) ; if ( root . data == x ) return true ; if ( hasPath ( root . left , arr , x ) || hasPath ( root . right , arr , x ) ) return true ; arr . remove ( arr . size ( ) - 1 ) ; return false ; } static void printCommonPath ( Node root , int n1 , int n2 ) { ArrayList < Integer > arr = new ArrayList < > ( ) ; Node lca = findLCA ( root , n1 , n2 ) ; if ( lca != null ) { if ( hasPath ( root , arr , lca . data ) ) { for ( int i = 0 ; i < arr . size ( ) - 1 ; i ++ ) System . out . print ( arr . get ( i ) + " - > " ) ; System . out . print ( arr . get ( arr . size ( ) - 1 ) ) ; } } else System . out . print ( " No ▁ Common ▁ Path " ) ; } public static void main ( String args [ ] ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right . left = new Node ( 6 ) ; root . right . right = new Node ( 7 ) ; root . left . right . left = new Node ( 8 ) ; root . right . left . right = new Node ( 9 ) ; int n1 = 4 , n2 = 8 ; printCommonPath ( root , n1 , n2 ) ; } }

Accumulator variables: i
Iterator variables: i
Boolean variables: v1, v2
Class/struct names: Node, PrintCommonPath
Java program:
import java . util . Vector ; class GFG { static int cnt ; static void dfs ( Vector < Integer > [ ] g , int u , int parent , int [ ] timeIn , int [ ] timeOut ) { timeIn [ u ] = cnt ++ ; for ( int i = 0 ; i < g [ u ] . size ( ) ; i ++ ) { int v = g [ u ] . get ( i ) ; if ( v != parent ) dfs ( g , v , u , timeIn , timeOut ) ; } timeOut [ u ] = cnt ++ ; } static void preProcess ( int [ ] [ ] edges , int V , int [ ] timeIn , int [ ] timeOut ) { @ SuppressWarnings ( " unchecked " ) Vector < Integer > [ ] g = new Vector [ V ] ; for ( int i = 0 ; i < g . length ; i ++ ) g [ i ] = new Vector < Integer > ( ) ; for ( int i = 0 ; i < V - 1 ; i ++ ) { int u = edges [ i ] [ 0 ] ; int v = edges [ i ] [ 1 ] ; g [ u ] . add ( v ) ; g [ v ] . add ( u ) ; } cnt = 0 ; dfs ( g , 0 , - 1 , timeIn , timeOut ) ; } static String isAncestor ( int u , int v , int [ ] timeIn , int [ ] timeOut ) { boolean b = ( timeIn [ u ] <= timeIn [ v ] && timeOut [ v ] <= timeOut [ u ] ) ; return ( b ? " yes " : " no " ) ; } public static void main ( String [ ] args ) { int edges [ ] [ ] = { { 0 , 1 } , { 0 , 2 } , { 1 , 3 } , { 1 , 4 } , { 2 , 5 } , { 4 , 6 } , { 5 , 7 } } ; int E = edges . length ; int V = E + 1 ; int [ ] timeIn = new int [ V ] ; int [ ] timeOut = new int [ V ] ; preProcess ( edges , V , timeIn , timeOut ) ; int u = 1 ; int v = 6 ; System . out . println ( isAncestor ( u , v , timeIn , timeOut ) ) ; u = 1 ; v = 7 ; System . out . println ( isAncestor ( u , v , timeIn , timeOut ) ) ; } }

Index/key variables: V, i, u, v
Accumulator variables: cnt, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . ArrayList ; public class PrintPath { class Node { int data ; Node left , right ; Node ( int data ) { this . data = data ; left = right = null ; } } ; public static boolean hasPath ( Node root , ArrayList < Integer > arr , int x ) { if ( root == null ) return false ; arr . add ( root . data ) ; if ( root . data == x ) return true ; if ( hasPath ( root . left , arr , x ) || hasPath ( root . right , arr , x ) ) return true ; arr . remove ( arr . size ( ) - 1 ) ; return false ; } public static void printPath ( Node root , int x ) { ArrayList < Integer > arr = new ArrayList < > ( ) ; if ( hasPath ( root , arr , x ) ) { for ( int i = 0 ; i < arr . size ( ) - 1 ; i ++ ) System . out . print ( arr . get ( i ) + " - > " ) ; System . out . print ( arr . get ( arr . size ( ) - 1 ) ) ; } else System . out . print ( " No ▁ Path " ) ; } public static void main ( String args [ ] ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right . left = new Node ( 6 ) ; root . right . right = new Node ( 7 ) ; int x = 5 ; printPath ( root , x ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: Node, PrintPath
Java program:
class Node { int data ; Node left , right , nextRight ; Node ( int item ) { data = item ; left = right = nextRight = null ; } } class BinaryTree { Node root ; boolean printAncestors ( Node node , int target ) { if ( node == null ) return false ; if ( node . data == target ) return true ; if ( printAncestors ( node . left , target ) || printAncestors ( node . right , target ) ) { System . out . print ( node . data + " ▁ " ) ; return true ; } return false ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . left . left . left = new Node ( 7 ) ; tree . printAncestors ( tree . root , 7 ) ; } }

Class/struct names: BinaryTree, Node
Java program:
class Solution { static class Node { int data ; Node left , right ; } ; static Node temp = null ; static int k ; static Node kthAncestorDFS ( Node root , int node ) { if ( root == null ) return null ; if ( root . data == node || ( temp = kthAncestorDFS ( root . left , node ) ) != null || ( temp = kthAncestorDFS ( root . right , node ) ) != null ) { if ( k > 0 ) k -- ; else if ( k == 0 ) { System . out . print ( " Kth ▁ ancestor ▁ is : ▁ " + root . data ) ; return null ; } return root ; } return null ; } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } public static void main ( String args [ ] ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; k = 2 ; int node = 5 ; Node parent = kthAncestorDFS ( root , node ) ; if ( parent != null ) System . out . println ( " - 1" ) ; } }

Accumulator variables: k
Class/struct names: Node, Solution
Java program:
import java . util . * ; class GFG { static class Node { int key ; Node left , right ; } ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . key = key ; temp . left = temp . right = null ; return ( temp ) ; } static Vector < Boolean > struc ; static Vector < Integer > data ; static Node root ; static void EncodeSuccinct ( Node root ) { if ( root == null ) { struc . add ( false ) ; return ; } struc . add ( true ) ; data . add ( root . key ) ; EncodeSuccinct ( root . left ) ; EncodeSuccinct ( root . right ) ; } static Node DecodeSuccinct ( ) { if ( struc . size ( ) <= 0 ) return null ; boolean b = struc . get ( 0 ) ; struc . remove ( 0 ) ; if ( b == true ) { int key = data . get ( 0 ) ; data . remove ( 0 ) ; Node root = newNode ( key ) ; root . left = DecodeSuccinct ( ) ; root . right = DecodeSuccinct ( ) ; return root ; } return null ; } static void preorder ( Node root ) { if ( root != null ) { System . out . print ( " key : ▁ " + root . key ) ; if ( root . left != null ) System . out . print ( " ▁ left ▁ child : ▁ " + root . left . key ) ; if ( root . right != null ) System . out . print ( " ▁ right ▁ child : ▁ " + root . right . key ) ; System . out . println ( ) ; preorder ( root . left ) ; preorder ( root . right ) ; } } public static void main ( String [ ] args ) { Node root = newNode ( 10 ) ; root . left = newNode ( 20 ) ; root . right = newNode ( 30 ) ; root . left . left = newNode ( 40 ) ; root . left . right = newNode ( 50 ) ; root . right . right = newNode ( 70 ) ; System . out . print ( "Given TreeNEW_LINE"); preorder ( root ) ; struc = new Vector < > ( ) ; data = new Vector < > ( ) ; EncodeSuccinct ( root ) ; System . out . print ( " Encoded Tree "); System . out . print ( "Structure ListNEW_LINE"); for ( boolean si : struc ) { if ( si == true ) System . out . print ( 1 + " ▁ " ) ; else System . out . print ( 0 + " ▁ " ) ; } System . out . print ( " Data List "); for ( int di : data ) System . out . print ( di + " ▁ " ) ; Node newroot = DecodeSuccinct ( ) ; System . out . print ( " Preorder traversal " ▁ + ▁ " of decoded tree "); preorder ( newroot ) ; } }

Iterator variables: di, si
Class/struct names: GFG, Node
Java program:
class GfG { static void update ( int arr [ ] , int l , int r , int val ) { arr [ l ] += val ; if ( r + 1 < arr . length ) arr [ r + 1 ] -= val ; } static int getElement ( int arr [ ] , int i ) { int res = 0 ; for ( int j = 0 ; j <= i ; j ++ ) res += arr [ j ] ; return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 0 , 0 , 0 , 0 , 0 } ; int n = arr . length ; int l = 2 , r = 4 , val = 2 ; update ( arr , l , r , val ) ; int index = 4 ; System . out . println ( " Element ▁ at ▁ index ▁ " + index + " ▁ is ▁ " + getElement ( arr , index ) ) ; l = 0 ; r = 3 ; val = 4 ; update ( arr , l , r , val ) ; index = 3 ; System . out . println ( " Element ▁ at ▁ index ▁ " + index + " ▁ is ▁ " + getElement ( arr , index ) ) ; } }

Index/key variables: j, l
Accumulator variables: j, res
Iterator variables: j
Class/struct names: GfG
Java program:
class GFG { final static int MAX = 1000 ; static int BITree [ ] = new int [ MAX ] ; public static void updateBIT ( int n , int index , int val ) { index = index + 1 ; while ( index <= n ) { BITree [ index ] += val ; index += index & ( - index ) ; } } public static void constructBITree ( int arr [ ] , int n ) { for ( int i = 1 ; i <= n ; i ++ ) BITree [ i ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) updateBIT ( n , i , arr [ i ] ) ; } public static int getSum ( int index ) { int sum = 0 ; index = index + 1 ; while ( index > 0 ) { sum += BITree [ index ] ; index -= index & ( - index ) ; } return sum ; } public static void update ( int l , int r , int n , int val ) { updateBIT ( n , l , val ) ; updateBIT ( n , r + 1 , - val ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 0 , 0 , 0 , 0 , 0 } ; int n = arr . length ; constructBITree ( arr , n ) ; int l = 2 , r = 4 , val = 2 ; update ( l , r , n , val ) ; int index = 4 ; System . out . println ( " Element ▁ at ▁ index ▁ " + index + " ▁ is ▁ " + getSum ( index ) ) ; l = 0 ; r = 3 ; val = 4 ; update ( l , r , n , val ) ; index = 3 ; System . out . println ( " Element ▁ at ▁ index ▁ " + index + " ▁ is ▁ " + getSum ( index ) ) ; } }

Index/key variables: MAX, i, index
Accumulator variables: i, index, sum
Iterator variables: i
Class/struct names: GFG