dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static class treeNode { int square_sum ; treeNode ( int square_sum ) { this . square_sum = square_sum ; } } ; static void buildTree ( char s [ ] , treeNode tree [ ] , int start , int end , int treenode ) { if ( start == end ) { tree [ treenode ] . square_sum = ( int ) Math . pow ( s [ start ] - ' a ' + 1 , 2 ) ; return ; } int mid = start + ( ( end - start ) / 2 ) ; buildTree ( s , tree , start , mid , 2 * treenode ) ; buildTree ( s , tree , mid + 1 , end , 1 + 2 * treenode ) ; tree [ treenode ] . square_sum = tree [ ( 2 * treenode ) ] . square_sum + tree [ ( 2 * treenode ) + 1 ] . square_sum ; } static int querySquareSum ( treeNode tree [ ] , int start , int end , int treenode , int l , int r ) { if ( ( l > end ) || ( r < start ) ) { return 0 ; } if ( ( l <= start ) && ( r >= end ) ) { return tree [ treenode ] . square_sum ; } int mid = start + ( ( end - start ) / 2 ) ; int X = querySquareSum ( tree , start , mid , 2 * treenode , l , r ) ; int Y = + querySquareSum ( tree , mid + 1 , end , 1 + 2 * treenode , l , r ) ; return X + Y ; } static void updateTree ( char s [ ] , treeNode tree [ ] , int start , int end , int treenode , int idx , char X ) { if ( ( start == end ) && ( idx == start ) ) { s [ idx ] = X ; tree [ treenode ] . square_sum = ( int ) Math . pow ( X - ' a ' + 1 , 2 ) ; return ; } int mid = start + ( ( end - start ) / 2 ) ; if ( idx <= mid ) { updateTree ( s , tree , start , mid , ( 2 * treenode ) , idx , X ) ; } else { updateTree ( s , tree , mid + 1 , end , ( 2 * treenode ) + 1 , idx , X ) ; } tree [ treenode ] . square_sum = tree [ ( 2 * treenode ) ] . square_sum + tree [ ( 2 * treenode ) + 1 ] . square_sum ; } static void PerformQuery ( String S , String Q [ ] [ ] ) { int n = S . length ( ) ; treeNode tree [ ] = new treeNode [ ( 4 * n ) + 1 ] ; for ( int i = 0 ; i <= ( 4 * n ) ; i = i + 1 ) { tree [ i ] = new treeNode ( 0 ) ; } char s [ ] = S . toCharArray ( ) ; buildTree ( s , tree , 0 , n - 1 , 1 ) ; for ( int i = 0 ; i < Q . length ; i ++ ) { if ( Q [ i ] [ 0 ] == " S " ) { int L = Integer . parseInt ( Q [ i ] [ 1 ] ) ; int R = Integer . parseInt ( Q [ i ] [ 2 ] ) ; System . out . println ( querySquareSum ( tree , 0 , n - 1 , 1 , L , R ) ) ; } else if ( Q [ i ] [ 0 ] == " U " ) { int I = Integer . parseInt ( Q [ i ] [ 1 ] ) ; updateTree ( s , tree , 0 , n - 1 , 1 , I , Q [ i ] [ 2 ] . charAt ( 0 ) ) ; } } } public static void main ( String [ ] args ) { String S = " geeksforgeeks " ; String Q [ ] [ ] = { { " S " , "0" , "2" } , { " S " , "1" , "2" } , { " U " , "1" , " a " } , { " S " , "0" , "2" } , { " S " , "4" , "5" } } ; PerformQuery ( S , Q ) ; } }

Index/key variables: i, idx, start, treenode
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, treeNode
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void lcsBySwapping ( String A , String B ) { int N = A . length ( ) ; int M = B . length ( ) ; int freq [ ] = new int [ 26 ] ; for ( int i = 0 ; i < N ; i ++ ) { freq [ A . charAt ( i ) - ' a ' ] += 1 ; } for ( int i = 0 ; i < M ; i ++ ) { freq [ B . charAt ( i ) - ' a ' ] += 1 ; } int cnt = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { cnt += freq [ i ] / 2 ; } System . out . println ( Math . min ( cnt , Math . min ( N , M ) ) ) ; } public static void main ( String [ ] args ) { String A = " abdeff " ; String B = " abbet " ; lcsBySwapping ( A , B ) ; } }

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void maximumLengthSubsequence ( String str ) { HashMap < Character , Integer > mp = new HashMap < > ( ) ; for ( char ch : str . toCharArray ( ) ) { mp . put ( ch , mp . getOrDefault ( ch , 0 ) + 1 ) ; } int ans = 0 ; for ( char ch : str . toCharArray ( ) ) { if ( mp . containsKey ( ( char ) ( ch - 1 ) ) ) { int curr_max = mp . get ( ch ) + mp . get ( ( char ) ( ch - 1 ) ) ; ans = Math . max ( ans , curr_max ) ; } } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { String S = " acbbebcg " ; maximumLengthSubsequence ( S ) ; } }

Iterator variables: ch
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static void countOperations ( String X , String Y , int K ) { char ch1 [ ] = X . toCharArray ( ) ; char ch2 [ ] = Y . toCharArray ( ) ; int count = 0 ; for ( int i = 0 ; i < X . length ( ) ; i ++ ) { int c = 0 ; if ( ch1 [ i ] == ch2 [ i ] ) continue ; else if ( ch1 [ i ] < ch2 [ i ] ) { if ( ( ( int ) ch2 [ i ] - ( int ) ch1 [ i ] ) >= K ) { c = ( ( int ) ch2 [ i ] - ( int ) ch1 [ i ] ) / K ; } c += ( ( int ) ch2 [ i ] - ( int ) ch1 [ i ] ) % K ; } else { int t = 90 - ( int ) ch1 [ i ] ; t += ( int ) ch2 [ i ] - 65 + 1 ; if ( t >= K ) c = t / K ; c += ( t % K ) ; } count += c ; } System . out . print ( count ) ; } public static void main ( String [ ] args ) { String X = " ABCT " , Y = " PBDI " ; int K = 6 ; countOperations ( X , Y , K ) ; } }

Index/key variables: i
Accumulator variables: c, count, i, t
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int minimumSwaps ( String s , int l , int r , int k ) { int n = s . length ( ) ; int tot_ones = 0 , tot_zeros = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == '1' ) tot_ones ++ ; else tot_zeros ++ ; } int ones = 0 , zeros = 0 , sum = 0 ; for ( int i = l - 1 ; i < r ; i ++ ) { if ( s . charAt ( i ) == '1' ) { ones ++ ; sum ++ ; } else zeros ++ ; } int rem_ones = tot_ones - ones ; int rem_zeros = tot_zeros - zeros ; if ( k >= sum ) { int rem = k - sum ; if ( zeros >= rem && rem_ones >= rem ) return rem ; } else if ( k < sum ) { int rem = sum - k ; if ( ones >= rem && rem_zeros >= rem ) return rem ; } return - 1 ; } public static void main ( String [ ] args ) { String S = "110011111000101" ; int L = 5 , R = 8 , K = 2 ; System . out . println ( minimumSwaps ( S , L , R , K ) ) ; } }

Accumulator variables: i, ones, sum, tot_ones, tot_zeros, zeros
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int N = 200000 ; static long Ans [ ] = new long [ 200000 ] ; static int index = 0 ; static void populateNumber ( ) { Ans [ index ++ ] = ( 2 ) ; Ans [ index ++ ] = ( 5 ) ; long x = 5 ; long inf = 1000000000001L ; while ( x < inf ) { x *= 2 ; Ans [ index ++ ] = ( x ) ; x = x * 2 + 1 ; Ans [ index ++ ] = ( x ) ; } } static void checkString ( int N ) { populateNumber ( ) ; for ( int i = 0 ; i < index ; i ++ ) { if ( Ans [ i ] == N ) { System . out . println ( " YES " ) ; return ; } } System . out . println ( " NO " ) ; } public static void main ( String [ ] args ) { N = 5 ; checkString ( N ) ; } }

Index/key variables: i
Accumulator variables: i, index, x
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . Stack ; class GFG { public static void deleteSubseq ( String s ) { int N = s . length ( ) ; Stack < Character > roundStk = new Stack < > ( ) ; Stack < Character > squareStk = new Stack < > ( ) ; int roundCount = 0 ; int squareCount = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == ' [ ' ) { squareStk . push ( s . charAt ( i ) ) ; } else if ( s . charAt ( i ) == ' ] ' ) { if ( squareStk . size ( ) != 0 && squareStk . peek ( ) == ' [ ' ) { squareStk . pop ( ) ; squareCount += 1 ; } } else if ( s . charAt ( i ) == ' ( ' ) { roundStk . push ( s . charAt ( i ) ) ; } else { if ( roundStk . size ( ) != 0 && squareStk . peek ( ) == ' ( ' ) { squareStk . pop ( ) ; roundCount += 1 ; } } } System . out . println ( N - ( 2 * squareCount + 2 * roundCount ) ) ; } public static void main ( String [ ] args ) { String s = " [ ] ] ) ( [ " ; deleteSubseq ( s ) ; } }

Accumulator variables: i, roundCount, squareCount
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void minimumOperations ( String s , int n ) { HashMap < Character , List < Integer > > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . containsKey ( s . charAt ( i ) ) ) { mp . get ( s . charAt ( i ) ) . add ( i ) ; } else { mp . put ( s . charAt ( i ) , new ArrayList < Integer > ( Arrays . asList ( i ) ) ) ; } } int ans = Integer . MAX_VALUE ; for ( Map . Entry < Character , List < Integer > > x : mp . entrySet ( ) ) { int curr = 0 ; int prev = 0 ; boolean first = true ; for ( Integer index : ( x . getValue ( ) ) ) { if ( first ) { if ( index > 0 ) { curr ++ ; } prev = index ; first = false ; } else { if ( index != prev + 1 ) { curr ++ ; } prev = index ; } } if ( prev != n - 1 ) { curr ++ ; } ans = Math . min ( ans , curr ) ; } System . out . print ( ans ) ; } public static void main ( String [ ] args ) { String s = " YYXYZYXYZXY " ; int N = s . length ( ) ; minimumOperations ( s , N ) ; } }

Accumulator variables: curr, i
Iterator variables: i, index
Boolean variables: first
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void checkValidDFA ( String s ) { int initial_state = 0 ; int final_state = 0 ; int previous_state = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( ( s . charAt ( i ) == '0' && previous_state == 0 ) || ( s . charAt ( i ) == '1' && previous_state == 3 ) ) { final_state = 1 ; } else if ( ( s . charAt ( i ) == '0' && previous_state == 3 ) || ( s . charAt ( i ) == '1' && previous_state == 0 ) ) { final_state = 2 ; } else if ( ( s . charAt ( i ) == '0' && previous_state == 1 ) || ( s . charAt ( i ) == '1' && previous_state == 2 ) ) { final_state = 0 ; } else if ( ( s . charAt ( i ) == '0' && previous_state == 2 ) || ( s . charAt ( i ) == '1' && previous_state == 1 ) ) { final_state = 3 ; } previous_state = final_state ; } if ( final_state == 3 ) { System . out . println ( " Accepted " ) ; } else { System . out . println ( " Not ▁ Accepted " ) ; } } public static void main ( String args [ ] ) { String s = "010011" ; checkValidDFA ( s ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class Node { int data ; Node left , right ; Node ( int key ) { data = key ; left = right = null ; } } class GFG { static int evenOddLevelDifference ( Node root ) { if ( root == null ) return 0 ; Queue < Node > q = new LinkedList < > ( ) ; q . add ( root ) ; int level = 0 ; int evenSum = 0 , oddSum = 0 ; while ( q . size ( ) != 0 ) { int size = q . size ( ) ; level ++ ; while ( size > 0 ) { Node temp = q . remove ( ) ; if ( level % 2 == 0 ) evenSum += temp . data ; else oddSum += temp . data ; if ( temp . left != null ) q . add ( temp . left ) ; if ( temp . right != null ) q . add ( temp . right ) ; size -- ; } } return ( oddSum - evenSum ) ; } public static void main ( String args [ ] ) { Node root = new Node ( 5 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 6 ) ; root . left . left = new Node ( 1 ) ; root . left . right = new Node ( 4 ) ; root . left . right . left = new Node ( 3 ) ; root . right . right = new Node ( 8 ) ; root . right . right . right = new Node ( 9 ) ; root . right . right . left = new Node ( 7 ) ; System . out . println ( " diffence ▁ between ▁ sums ▁ is ▁ " + evenOddLevelDifference ( root ) ) ; } }

Accumulator variables: evenSum, level, oddSum, size
Class/struct names: GFG, Node
Java program:
class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right ; } } class BinaryTree { Node root ; int getLevelDiff ( Node node ) { if ( node == null ) return 0 ; return node . data - getLevelDiff ( node . left ) - getLevelDiff ( node . right ) ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 5 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 6 ) ; tree . root . left . left = new Node ( 1 ) ; tree . root . left . right = new Node ( 4 ) ; tree . root . left . right . left = new Node ( 3 ) ; tree . root . right . right = new Node ( 8 ) ; tree . root . right . right . right = new Node ( 9 ) ; tree . root . right . right . left = new Node ( 7 ) ; System . out . println ( tree . getLevelDiff ( tree . root ) + " ▁ is ▁ the ▁ required ▁ difference " ) ; } }

Class/struct names: BinaryTree, Node
Java program:
import java . util . ArrayList ; import java . util . Stack ; public class MaxSpiralSum { class Node { int data ; Node left , right ; Node ( int data ) { this . data = data ; left = right = null ; } } ; static int maxSum ( ArrayList < Integer > arr ) { int max_ending_here = Integer . MIN_VALUE ; int max_so_far = Integer . MIN_VALUE ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { if ( max_ending_here < 0 ) max_ending_here = arr . get ( i ) ; else max_ending_here += arr . get ( i ) ; max_so_far = Math . max ( max_so_far , max_ending_here ) ; } return max_so_far ; } public static int maxSpiralSum ( Node root ) { if ( root == null ) return 0 ; Stack < Node > s1 = new Stack < > ( ) ; Stack < Node > s2 = new Stack < > ( ) ; ArrayList < Integer > arr = new ArrayList < > ( ) ; s1 . push ( root ) ; while ( ! s1 . isEmpty ( ) || ! s2 . isEmpty ( ) ) { while ( ! s1 . isEmpty ( ) ) { Node temp = s1 . pop ( ) ; arr . add ( temp . data ) ; if ( temp . right != null ) s2 . push ( temp . right ) ; if ( temp . left != null ) s2 . push ( temp . left ) ; } while ( ! s2 . isEmpty ( ) ) { Node temp = s2 . pop ( ) ; arr . add ( temp . data ) ; if ( temp . left != null ) s1 . push ( temp . left ) ; if ( temp . right != null ) s1 . push ( temp . right ) ; } } return maxSum ( arr ) ; } public static void main ( String args [ ] ) { Node root = new Node ( - 2 ) ; root . left = new Node ( - 3 ) ; root . right = new Node ( 4 ) ; root . left . left = new Node ( 5 ) ; root . left . right = new Node ( 1 ) ; root . right . left = new Node ( - 2 ) ; root . right . right = new Node ( - 1 ) ; root . left . left . left = new Node ( - 3 ) ; root . right . right . right = new Node ( 2 ) ; System . out . print ( " Maximum ▁ Spiral ▁ Sum ▁ = ▁ " + maxSpiralSum ( root ) ) ; } }

Accumulator variables: i, max_ending_here
Iterator variables: i
Class/struct names: MaxSpiralSum, Node
Java program:
public class GFG { static class Node { int data ; Node left , right ; Node ( int data ) { this . data = data ; left = null ; right = null ; } } static int sum ; static void leafSum ( Node root ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) sum += root . data ; leafSum ( root . left ) ; leafSum ( root . right ) ; } public static void main ( String args [ ] ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right = new Node ( 3 ) ; root . right . right = new Node ( 7 ) ; root . right . left = new Node ( 6 ) ; root . right . left . right = new Node ( 8 ) ; sum = 0 ; leafSum ( root ) ; System . out . println ( sum ) ; } }

Accumulator variables: sum
Class/struct names: GFG, Node
Java program:
class tNode { int data ; tNode left , right ; tNode ( int item ) { data = item ; left = right = null ; } } class BinaryTree { tNode root ; void MorrisTraversal ( tNode root ) { tNode current , pre ; if ( root == null ) return ; current = root ; while ( current != null ) { if ( current . left == null ) { System . out . print ( current . data + " ▁ " ) ; current = current . right ; } else { pre = current . left ; while ( pre . right != null && pre . right != current ) pre = pre . right ; if ( pre . right == null ) { pre . right = current ; current = current . left ; } else { pre . right = null ; System . out . print ( current . data + " ▁ " ) ; current = current . right ; } } } } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new tNode ( 1 ) ; tree . root . left = new tNode ( 2 ) ; tree . root . right = new tNode ( 3 ) ; tree . root . left . left = new tNode ( 4 ) ; tree . root . left . right = new tNode ( 5 ) ; tree . MorrisTraversal ( tree . root ) ; } }

Class/struct names: BinaryTree, tNode
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left , right ; } ; static Node getNode ( int data ) { Node newNode = new Node ( ) ; newNode . data = data ; newNode . left = newNode . right = null ; return newNode ; } static int sumOfLeafNodesAtMinLevel ( Node root ) { if ( root == null ) return 0 ; if ( root . left == null && root . right == null ) return root . data ; Queue < Node > q = new LinkedList < > ( ) ; int sum = 0 ; boolean f = false ; q . add ( root ) ; while ( f == false ) { int nc = q . size ( ) ; while ( nc -- > 0 ) { Node top = q . peek ( ) ; q . remove ( ) ; if ( top . left == null && top . right == null ) { sum += top . data ; f = true ; } else { if ( top . left != null ) q . add ( top . left ) ; if ( top . right != null ) q . add ( top . right ) ; } } } return sum ; } public static void main ( String [ ] args ) { Node root = getNode ( 1 ) ; root . left = getNode ( 2 ) ; root . right = getNode ( 3 ) ; root . left . left = getNode ( 4 ) ; root . left . right = getNode ( 5 ) ; root . right . left = getNode ( 6 ) ; root . right . right = getNode ( 7 ) ; root . left . right . left = getNode ( 8 ) ; root . right . left . right = getNode ( 9 ) ; System . out . println ( " Sum ▁ = ▁ " + sumOfLeafNodesAtMinLevel ( root ) ) ; } }

Accumulator variables: nc, sum
Boolean variables: f
Class/struct names: GFG, Node
Java program:
class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; boolean hasPathSum ( Node node , int sum ) { if ( node == null ) return sum == 0 ; return hasPathSum ( node . left , sum - node . data ) || hasPathSum ( node . right , sum - node . data ) ; } public static void main ( String args [ ] ) { int sum = 21 ; BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 10 ) ; tree . root . left = new Node ( 8 ) ; tree . root . right = new Node ( 2 ) ; tree . root . left . left = new Node ( 3 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . right . left = new Node ( 2 ) ; if ( tree . haspathSum ( tree . root , sum ) ) System . out . println ( " There ▁ is ▁ a ▁ root ▁ to ▁ leaf ▁ path ▁ with ▁ sum ▁ " + sum ) ; else System . out . println ( " There ▁ is ▁ no ▁ root ▁ to ▁ leaf ▁ path ▁ with ▁ sum ▁ " + sum ) ; } }

Class/struct names: BinaryTree, Node
Java program:
class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; int treePathsSumUtil ( Node node , int val ) { if ( node == null ) return 0 ; val = ( val * 10 + node . data ) ; if ( node . left == null && node . right == null ) return val ; return treePathsSumUtil ( node . left , val ) + treePathsSumUtil ( node . right , val ) ; } int treePathsSum ( Node node ) { return treePathsSumUtil ( node , 0 ) ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 6 ) ; tree . root . left = new Node ( 3 ) ; tree . root . right = new Node ( 5 ) ; tree . root . right . right = new Node ( 4 ) ; tree . root . left . left = new Node ( 2 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . left . right . right = new Node ( 4 ) ; tree . root . left . right . left = new Node ( 7 ) ; System . out . print ( " Sum ▁ of ▁ all ▁ paths ▁ is ▁ " + tree . treePathsSum ( tree . root ) ) ; } }

Class/struct names: BinaryTree, Node
Java program:
class Node { int data ; Node left , right ; public Node ( int data , Node left , Node right ) { this . data = data ; this . left = left ; this . right = right ; } static Node newNode ( int data ) { return new Node ( data , null , null ) ; } static void inorder ( Node node ) { if ( node == null ) return ; inorder ( node . left ) ; System . out . printf ( " % d ▁ " , node . data ) ; inorder ( node . right ) ; } static Node MergeTrees ( Node t1 , Node t2 ) { if ( t1 == null ) return t2 ; if ( t2 == null ) return t1 ; t1 . data += t2 . data ; t1 . left = MergeTrees ( t1 . left , t2 . left ) ; t1 . right = MergeTrees ( t1 . right , t2 . right ) ; return t1 ; } public static void main ( String [ ] args ) { Node root1 = newNode ( 1 ) ; root1 . left = newNode ( 2 ) ; root1 . right = newNode ( 3 ) ; root1 . left . left = newNode ( 4 ) ; root1 . left . right = newNode ( 5 ) ; root1 . right . right = newNode ( 6 ) ; Node root2 = newNode ( 4 ) ; root2 . left = newNode ( 1 ) ; root2 . right = newNode ( 7 ) ; root2 . left . left = newNode ( 3 ) ; root2 . right . left = newNode ( 2 ) ; root2 . right . right = newNode ( 6 ) ; Node root3 = MergeTrees ( root1 , root2 ) ; System . out . printf ( "The Merged Binary Tree is:NEW_LINE"); inorder ( root3 ) ; } }

Accumulator variables: data
Class/struct names: Node
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left , right ; } ; static class snode { Node l , r ; } ; static Node newNode ( int data ) { Node new_node = new Node ( ) ; new_node . data = data ; new_node . left = new_node . right = null ; return new_node ; } static void inorder ( Node node ) { if ( node == null ) return ; inorder ( node . left ) ; System . out . printf ( " % d ▁ " , node . data ) ; inorder ( node . right ) ; } static Node MergeTrees ( Node t1 , Node t2 ) { if ( t1 == null ) return t2 ; if ( t2 == null ) return t1 ; Stack < snode > s = new Stack < > ( ) ; snode temp = new snode ( ) ; temp . l = t1 ; temp . r = t2 ; s . add ( temp ) ; snode n ; while ( ! s . isEmpty ( ) ) { n = s . peek ( ) ; s . pop ( ) ; if ( n . l == null n . r == null ) continue ; n . l . data += n . r . data ; if ( n . l . left == null ) n . l . left = n . r . left ; else { snode t = new snode ( ) ; t . l = n . l . left ; t . r = n . r . left ; s . add ( t ) ; } if ( n . l . right == null ) n . l . right = n . r . right ; else { snode t = new snode ( ) ; t . l = n . l . right ; t . r = n . r . right ; s . add ( t ) ; } } return t1 ; } public static void main ( String [ ] args ) { Node root1 = newNode ( 1 ) ; root1 . left = newNode ( 2 ) ; root1 . right = newNode ( 3 ) ; root1 . left . left = newNode ( 4 ) ; root1 . left . right = newNode ( 5 ) ; root1 . right . right = newNode ( 6 ) ; Node root2 = newNode ( 4 ) ; root2 . left = newNode ( 1 ) ; root2 . right = newNode ( 7 ) ; root2 . left . left = newNode ( 3 ) ; root2 . right . left = newNode ( 2 ) ; root2 . right . right = newNode ( 6 ) ; Node root3 = MergeTrees ( root1 , root2 ) ; System . out . printf ( "The Merged Binary Tree is:NEW_LINE"); inorder ( root3 ) ; } }

Accumulator variables: data
Class/struct names: GFG, Node, snode
Java program:
class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int findRoot ( pair arr [ ] , int n ) { int root = 0 ; for ( int i = 0 ; i < n ; i ++ ) { root += ( arr [ i ] . first - arr [ i ] . second ) ; } return root ; } public static void main ( String [ ] args ) { pair arr [ ] = { new pair ( 1 , 5 ) , new pair ( 2 , 0 ) , new pair ( 3 , 0 ) , new pair ( 4 , 0 ) , new pair ( 5 , 5 ) , new pair ( 6 , 5 ) } ; int n = arr . length ; System . out . printf ( "%dNEW_LINE", findRoot(arr, n)); } }

Index/key variables: i
Accumulator variables: i, root
Iterator variables: i
Class/struct names: GFG, pair
Java program:
import java . util . Arrays ; class GFG { static int search ( int arr [ ] , int x , int n ) { for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] == x ) return i ; return - 1 ; } static void printPostOrder ( int in1 [ ] , int pre [ ] , int n ) { int root = search ( in1 , pre [ 0 ] , n ) ; if ( root != 0 ) printPostOrder ( in1 , Arrays . copyOfRange ( pre , 1 , n ) , root ) ; if ( root != n - 1 ) printPostOrder ( Arrays . copyOfRange ( in1 , root + 1 , n ) , Arrays . copyOfRange ( pre , 1 + root , n ) , n - root - 1 ) ; System . out . print ( pre [ 0 ] + " ▁ " ) ; } public static void main ( String args [ ] ) { int in1 [ ] = { 4 , 2 , 5 , 1 , 3 , 6 } ; int pre [ ] = { 1 , 2 , 4 , 5 , 3 , 6 } ; int n = in1 . length ; System . out . println ( " Postorder ▁ traversal ▁ " ) ; printPostOrder ( in1 , pre , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG