dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; public class TreeNode { int val ; TreeNode left ; TreeNode right ; TreeNode ( int x ) { val = x ; } } class BinaryTree { static Set < TreeNode > set = new HashSet < > ( ) ; static Stack < TreeNode > stack = new Stack < > ( ) ; public TreeNode buildTree ( int [ ] preorder , int [ ] inorder ) { TreeNode root = null ; for ( int pre = 0 , in = 0 ; pre < preorder . length ; ) { TreeNode node = null ; do { node = new TreeNode ( preorder [ pre ] ) ; if ( root == null ) { root = node ; } if ( ! stack . isEmpty ( ) ) { if ( set . contains ( stack . peek ( ) ) ) { set . remove ( stack . peek ( ) ) ; stack . pop ( ) . right = node ; } else { stack . peek ( ) . left = node ; } } stack . push ( node ) ; } while ( preorder [ pre ++ ] != inorder [ in ] && pre < preorder . length ) ; node = null ; while ( ! stack . isEmpty ( ) && in < inorder . length && stack . peek ( ) . val == inorder [ in ] ) { node = stack . pop ( ) ; in ++ ; } if ( node != null ) { set . add ( node ) ; stack . push ( node ) ; } } return root ; } void printInorder ( TreeNode node ) { if ( node == null ) return ; printInorder ( node . left ) ; System . out . print ( node . val + " ▁ " ) ; printInorder ( node . right ) ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; int in [ ] = new int [ ] { 9 , 8 , 4 , 2 , 10 , 5 , 10 , 1 , 6 , 3 , 13 , 12 , 7 } ; int pre [ ] = new int [ ] { 1 , 2 , 4 , 8 , 9 , 5 , 10 , 10 , 3 , 6 , 7 , 12 , 13 } ; int len = in . length ; TreeNode root = tree . buildTree ( pre , in ) ; tree . printInorder ( root ) ; } }

Index/key variables: in, pre
Accumulator variables: in, pre
Iterator variables: pre
Class/struct names: BinaryTree, TreeNode
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left ; Node right ; } ; static Node newNode ( int val ) { Node temp = new Node ( ) ; temp . data = val ; temp . left = temp . right = null ; return temp ; } static void insertToHash ( Node root , HashSet < Integer > s ) { if ( root == null ) return ; insertToHash ( root . left , s ) ; s . add ( root . data ) ; insertToHash ( root . right , s ) ; } static boolean checkBSTs ( Node root1 , Node root2 ) { if ( root1 != null && root2 != null ) return true ; if ( ( root1 == null && root2 != null ) || ( root1 != null && root2 == null ) ) return false ; HashSet < Integer > s1 = new HashSet < Integer > ( ) ; HashSet < Integer > s2 = new HashSet < Integer > ( ) ; insertToHash ( root1 , s1 ) ; insertToHash ( root2 , s2 ) ; return ( s1 . equals ( s2 ) ) ; } public static void main ( String [ ] args ) { Node root1 = newNode ( 15 ) ; root1 . left = newNode ( 10 ) ; root1 . right = newNode ( 20 ) ; root1 . left . left = newNode ( 5 ) ; root1 . left . right = newNode ( 12 ) ; root1 . right . right = newNode ( 25 ) ; Node root2 = newNode ( 15 ) ; root2 . left = newNode ( 12 ) ; root2 . right = newNode ( 20 ) ; root2 . left . left = newNode ( 5 ) ; root2 . left . left . right = newNode ( 10 ) ; root2 . right . right = newNode ( 25 ) ; if ( checkBSTs ( root1 , root2 ) ) System . out . print ( " YES " ) ; else System . out . print ( " NO " ) ; } }

Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left ; Node right ; } ; static Node newNode ( int val ) { Node temp = new Node ( ) ; temp . data = val ; temp . left = temp . right = null ; return temp ; } static void storeInorder ( Node root , Vector < Integer > v ) { if ( root == null ) return ; storeInorder ( root . left , v ) ; v . add ( root . data ) ; storeInorder ( root . right , v ) ; } static boolean checkBSTs ( Node root1 , Node root2 ) { if ( root1 != null && root2 != null ) return true ; if ( ( root1 == null && root2 != null ) || ( root1 != null && root2 == null ) ) return false ; Vector < Integer > v1 = new Vector < Integer > ( ) ; Vector < Integer > v2 = new Vector < Integer > ( ) ; storeInorder ( root1 , v1 ) ; storeInorder ( root2 , v2 ) ; return ( v1 == v2 ) ; } public static void main ( String [ ] args ) { Node root1 = newNode ( 15 ) ; root1 . left = newNode ( 10 ) ; root1 . right = newNode ( 20 ) ; root1 . left . left = newNode ( 5 ) ; root1 . left . right = newNode ( 12 ) ; root1 . right . right = newNode ( 25 ) ; Node root2 = newNode ( 15 ) ; root2 . left = newNode ( 12 ) ; root2 . right = newNode ( 20 ) ; root2 . left . left = newNode ( 5 ) ; root2 . left . left . right = newNode ( 10 ) ; root2 . right . right = newNode ( 25 ) ; if ( checkBSTs ( root1 , root2 ) ) System . out . print ( " YES " ) ; else System . out . print ( " NO " ) ; } }

Class/struct names: GFG, Node
Java program:
class GfG { static class Node { Node left , right ; int key ; } static Node newNode ( int key ) { Node ptr = new Node ( ) ; ptr . key = key ; ptr . left = null ; ptr . right = null ; return ptr ; } static Node insert ( Node root , int key ) { if ( root == null ) root = newNode ( key ) ; else if ( root . key > key ) root . left = insert ( root . left , key ) ; else if ( root . key < key ) root . right = insert ( root . right , key ) ; return root ; } static int distanceFromRoot ( Node root , int x ) { if ( root . key == x ) return 0 ; else if ( root . key > x ) return 1 + distanceFromRoot ( root . left , x ) ; return 1 + distanceFromRoot ( root . right , x ) ; } static int distanceBetween2 ( Node root , int a , int b ) { if ( root == null ) return 0 ; if ( root . key > a && root . key > b ) return distanceBetween2 ( root . left , a , b ) ; if ( root . key < a && root . key < b ) return distanceBetween2 ( root . right , a , b ) ; if ( root . key >= a && root . key <= b ) return distanceFromRoot ( root , a ) + distanceFromRoot ( root , b ) ; return 0 ; } static int findDistWrapper ( Node root , int a , int b ) { int temp = 0 ; if ( a > b ) { temp = a ; a = b ; b = temp ; } return distanceBetween2 ( root , a , b ) ; } public static void main ( String [ ] args ) { Node root = null ; root = insert ( root , 20 ) ; insert ( root , 10 ) ; insert ( root , 5 ) ; insert ( root , 15 ) ; insert ( root , 30 ) ; insert ( root , 25 ) ; insert ( root , 35 ) ; System . out . println ( findDistWrapper ( root , 5 , 35 ) ) ; } }

Class/struct names: GfG, Node
Java program:
class GfG { static class node { int data ; node left , right ; } static void RangeTraversal ( node root , int n1 , int n2 ) { if ( root == null ) return ; node curr = root ; while ( curr != null ) { if ( curr . left == null ) { if ( curr . data <= n2 && curr . data >= n1 ) { System . out . print ( curr . data + " ▁ " ) ; } curr = curr . right ; } else { node pre = curr . left ; while ( pre . right != null && pre . right != curr ) pre = pre . right ; if ( pre . right == null ) { pre . right = curr ; curr = curr . left ; } else { pre . right = null ; if ( curr . data <= n2 && curr . data >= n1 ) { System . out . print ( curr . data + " ▁ " ) ; } curr = curr . right ; } } } } static node newNode ( int data ) { node temp = new node ( ) ; temp . data = data ; temp . right = null ; temp . left = null ; return temp ; } public static void main ( String [ ] args ) { node root = newNode ( 4 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 7 ) ; root . left . left = newNode ( 1 ) ; root . left . right = newNode ( 3 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 10 ) ; RangeTraversal ( root , 4 , 12 ) ; } }

Class/struct names: GfG, node
Java program:
class GfG { static class node { int data ; node left , right ; } ; static class INT { int a ; } static boolean inRange ( node root , int low , int high ) { return root . data >= low && root . data <= high ; } static boolean getCountUtil ( node root , int low , int high , INT count ) { if ( root == null ) return true ; boolean l = getCountUtil ( root . left , low , high , count ) ; boolean r = getCountUtil ( root . right , low , high , count ) ; if ( l && r && inRange ( root , low , high ) ) { ++ count . a ; return true ; } return false ; } static INT getCount ( node root , int low , int high ) { INT count = new INT ( ) ; count . a = 0 ; getCountUtil ( root , low , high , count ) ; return count ; } 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 ( 10 ) ; root . left = newNode ( 5 ) ; root . right = newNode ( 50 ) ; root . left . left = newNode ( 1 ) ; root . right . left = newNode ( 40 ) ; root . right . right = newNode ( 100 ) ; int l = 5 ; int h = 45 ; System . out . println ( " Count ▁ of ▁ subtrees ▁ in ▁ [ " + l + " , ▁ " + h + " ] ▁ is ▁ " + getCount ( root , l , h ) . a ) ; } }

Class/struct names: GfG, INT, node
Java program:
class GfG { static class Node { int data ; Node left ; Node right ; } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = null ; temp . right = null ; return temp ; } static Node insert ( Node root , int data ) { if ( root == null ) return newNode ( data ) ; if ( data < root . data ) root . left = insert ( root . left , data ) ; else if ( data > root . data ) root . right = insert ( root . right , data ) ; return root ; } static void inorder ( Node root ) { if ( root != null ) { inorder ( root . left ) ; System . out . print ( root . data + " ▁ " ) ; inorder ( root . right ) ; } } static Node leafDelete ( Node root ) { if ( root == null ) { return null ; } if ( root . left == null && root . right == null ) { return null ; } root . left = leafDelete ( root . left ) ; root . right = leafDelete ( root . right ) ; return root ; } public static void main ( String [ ] args ) { Node root = null ; root = insert ( root , 20 ) ; insert ( root , 10 ) ; insert ( root , 5 ) ; insert ( root , 15 ) ; insert ( root , 30 ) ; insert ( root , 25 ) ; insert ( root , 35 ) ; System . out . println ( " Inorder ▁ before ▁ Deleting ▁ the ▁ leaf ▁ Node . ▁ " ) ; inorder ( root ) ; System . out . println ( ) ; leafDelete ( root ) ; System . out . println ( " INorder ▁ after ▁ Deleting ▁ the ▁ leaf ▁ Node . ▁ " ) ; inorder ( root ) ; } }

Class/struct names: GfG, Node
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left , right ; } ; static Node createNode ( int data ) { Node new_Node = new Node ( ) ; new_Node . left = null ; new_Node . right = null ; new_Node . data = data ; return new_Node ; } static Node insert ( Node root , int key ) { if ( root == null ) return createNode ( key ) ; if ( root . data > key ) root . left = insert ( root . left , key ) ; else if ( root . data < key ) root . right = insert ( root . right , key ) ; return root ; } static int count = 0 ; static int ksmallestElementSumRec ( Node root , int k ) { if ( root == null ) return 0 ; if ( count > k ) return 0 ; int res = ksmallestElementSumRec ( root . left , k ) ; if ( count >= k ) return res ; res += root . data ; count ++ ; if ( count >= k ) return res ; return res + ksmallestElementSumRec ( root . right , k ) ; } static int ksmallestElementSum ( Node root , int k ) { int res = ksmallestElementSumRec ( root , k ) ; return res ; } public static void main ( String [ ] args ) { Node root = null ; root = insert ( root , 20 ) ; root = insert ( root , 8 ) ; root = insert ( root , 4 ) ; root = insert ( root , 12 ) ; root = insert ( root , 10 ) ; root = insert ( root , 14 ) ; root = insert ( root , 22 ) ; int k = 3 ; int count = ksmallestElementSum ( root , k ) ; System . out . println ( count ) ; } }

Accumulator variables: count, res
Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { static class Node { int data ; int lCount ; int Sum ; Node left ; Node right ; } ; static Node createNode ( int data ) { Node new_Node = new Node ( ) ; new_Node . left = null ; new_Node . right = null ; new_Node . data = data ; new_Node . lCount = 0 ; new_Node . Sum = 0 ; return new_Node ; } static Node insert ( Node root , int key ) { if ( root == null ) return createNode ( key ) ; if ( root . data > key ) { root . lCount ++ ; root . Sum += key ; root . left = insert ( root . left , key ) ; } else if ( root . data < key ) root . right = insert ( root . right , key ) ; return root ; } static int temp_sum ; static void ksmallestElementSumRec ( Node root , int k ) { if ( root == null ) return ; if ( ( root . lCount + 1 ) == k ) { temp_sum += root . data + root . Sum ; return ; } else if ( k > root . lCount ) { temp_sum += root . data + root . Sum ; k = k - ( root . lCount + 1 ) ; ksmallestElementSumRec ( root . right , k ) ; } else ksmallestElementSumRec ( root . left , k ) ; } static void ksmallestElementSum ( Node root , int k ) { temp_sum = 0 ; ksmallestElementSumRec ( root , k ) ; } public static void main ( String [ ] args ) { Node root = null ; root = insert ( root , 20 ) ; root = insert ( root , 8 ) ; root = insert ( root , 4 ) ; root = insert ( root , 12 ) ; root = insert ( root , 10 ) ; root = insert ( root , 14 ) ; root = insert ( root , 22 ) ; int k = 3 ; ksmallestElementSum ( root , k ) ; System . out . println ( temp_sum ) ; } }

Accumulator variables: Sum, lCount, temp_sum
Class/struct names: GFG, Node
Java program:
class Node { int data ; Node left , right , parent ; Node ( int d ) { data = d ; left = right = parent = null ; } } class BinaryTree { static Node head ; Node insert ( Node node , int data ) { if ( node == null ) { return ( new Node ( data ) ) ; } else { Node temp = null ; if ( data <= node . data ) { temp = insert ( node . left , data ) ; node . left = temp ; temp . parent = node ; } else { temp = insert ( node . right , data ) ; node . right = temp ; temp . parent = node ; } return node ; } } Node inOrderSuccessor ( Node root , Node n ) { if ( n . right != null ) { return minValue ( n . right ) ; } Node p = n . parent ; while ( p != null && n == p . right ) { n = p ; p = p . parent ; } return p ; } Node minValue ( Node node ) { Node current = node ; while ( current . left != null ) { current = current . left ; } return current ; } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; Node root = null , temp = null , suc = null , min = null ; root = tree . insert ( root , 20 ) ; root = tree . insert ( root , 8 ) ; root = tree . insert ( root , 22 ) ; root = tree . insert ( root , 4 ) ; root = tree . insert ( root , 12 ) ; root = tree . insert ( root , 10 ) ; root = tree . insert ( root , 14 ) ; temp = root . left . right . right ; suc = tree . inOrderSuccessor ( root , temp ) ; if ( suc != null ) { System . out . println ( " Inorder ▁ successor ▁ of ▁ " + temp . data + " ▁ is ▁ " + suc . data ) ; } else { System . out . println ( " Inorder ▁ successor ▁ does ▁ not ▁ exist " ) ; } } }

Class/struct names: BinaryTree, Node
Java program:
import java . util . * ; class GFG { static class Node { int key ; Node left , right ; } ; static Node pre ; static Node suc ; static void findPreSuc ( Node root , int key ) { if ( root == null ) return ; while ( root != null ) { if ( root . key == key ) { if ( root . right != null ) { suc = root . right ; while ( suc . left != null ) suc = suc . left ; } if ( root . left != null ) { pre = root . left ; while ( pre . right != null ) pre = pre . right ; } return ; } else if ( root . key < key ) { pre = root ; root = root . right ; } else { suc = root ; root = root . left ; } } } static Node newNode ( int item ) { Node temp = new Node ( ) ; temp . key = item ; temp . left = temp . right = null ; return temp ; } static Node insert ( Node node , int key ) { if ( node == null ) return newNode ( key ) ; if ( key < node . key ) node . left = insert ( node . left , key ) ; else node . right = insert ( node . right , key ) ; return node ; } public static void main ( String [ ] args ) { int key = 65 ; Node root = null ; root = insert ( root , 50 ) ; insert ( root , 30 ) ; insert ( root , 20 ) ; insert ( root , 40 ) ; insert ( root , 70 ) ; insert ( root , 60 ) ; insert ( root , 80 ) ; findPreSuc ( root , key ) ; if ( pre != null ) System . out . println ( " Predecessor ▁ is ▁ " + pre . key ) ; else System . out . print ( " - 1" ) ; if ( suc != null ) System . out . print ( " Successor ▁ is ▁ " + suc . key ) ; else System . out . print ( " - 1" ) ; } }

Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { static class node { int key ; node left ; node right ; } ; static node head ; static node tail ; static void convertBSTtoDLL ( node root ) { if ( root == null ) return ; if ( root . left != null ) convertBSTtoDLL ( root . left ) ; root . left = tail ; if ( tail != null ) ( tail ) . right = root ; else head = root ; tail = root ; if ( root . right != null ) convertBSTtoDLL ( root . right ) ; } static boolean isPresentInDLL ( node head , node tail , int sum ) { while ( head != tail ) { int curr = head . key + tail . key ; if ( curr == sum ) return true ; else if ( curr > sum ) tail = tail . left ; else head = head . right ; } return false ; } static boolean isTripletPresent ( node root ) { if ( root == null ) return false ; head = null ; tail = null ; convertBSTtoDLL ( root ) ; while ( ( head . right != tail ) && ( head . key < 0 ) ) { if ( isPresentInDLL ( head . right , tail , - 1 * head . key ) ) return true ; else head = head . right ; } return false ; } static node newNode ( int num ) { node temp = new node ( ) ; temp . key = num ; temp . left = temp . right = null ; return temp ; } static node insert ( node root , int key ) { if ( root == null ) return newNode ( key ) ; if ( root . key > key ) root . left = insert ( root . left , key ) ; else root . right = insert ( root . right , key ) ; return root ; } public static void main ( String [ ] args ) { node root = null ; root = insert ( root , 6 ) ; root = insert ( root , - 13 ) ; root = insert ( root , 14 ) ; root = insert ( root , - 8 ) ; root = insert ( root , 15 ) ; root = insert ( root , 13 ) ; root = insert ( root , 7 ) ; if ( isTripletPresent ( root ) ) System . out . print ( " Present " ) ; else System . out . print ( " Not ▁ Present " ) ; } }

Class/struct names: GFG, node
Java program:
import java . util . ArrayList ; class Node { int data ; Node left , right ; Node ( int d ) { data = d ; left = right = null ; } } class BinarySearchTree { Node root ; BinarySearchTree ( ) { root = null ; } void inorder ( ) { inorderUtil ( this . root ) ; } void inorderUtil ( Node node ) { if ( node == null ) return ; inorderUtil ( node . left ) ; System . out . print ( node . data + " ▁ " ) ; inorderUtil ( node . right ) ; } void insert ( int key ) { root = insertRec ( root , key ) ; } Node insertRec ( Node root , int data ) { if ( root == null ) { root = new Node ( data ) ; return root ; } if ( data < root . data ) root . left = insertRec ( root . left , data ) ; else if ( data > root . data ) root . right = insertRec ( root . right , data ) ; return root ; } ArrayList < Integer > treeToList ( Node node , ArrayList < Integer > list ) { if ( node == null ) return list ; treeToList ( node . left , list ) ; list . add ( node . data ) ; treeToList ( node . right , list ) ; return list ; } boolean isPairPresent ( Node node , int target ) { ArrayList < Integer > a1 = new ArrayList < > ( ) ; ArrayList < Integer > a2 = treeToList ( node , a1 ) ; int start = 0 ; int end = a2 . size ( ) - 1 ; while ( start < end ) { if ( a2 . get ( start ) + a2 . get ( end ) == target ) { System . out . println ( " Pair ▁ Found : ▁ " + a2 . get ( start ) + " ▁ + ▁ " + a2 . get ( end ) + " ▁ " + " = ▁ " + target ) ; return true ; } if ( a2 . get ( start ) + a2 . get ( end ) > target ) { end -- ; } if ( a2 . get ( start ) + a2 . get ( end ) < target ) { start ++ ; } } System . out . println ( " No ▁ such ▁ values ▁ are ▁ found ! " ) ; return false ; } public static void main ( String [ ] args ) { BinarySearchTree tree = new BinarySearchTree ( ) ; tree . insert ( 15 ) ; tree . insert ( 10 ) ; tree . insert ( 20 ) ; tree . insert ( 8 ) ; tree . insert ( 12 ) ; tree . insert ( 16 ) ; tree . insert ( 25 ) ; tree . isPairPresent ( tree . root , 33 ) ; } }

Accumulator variables: end, start
Class/struct names: BinarySearchTree, Node
Java program:
import java . util . * ; class GFG { static final int MAX_SIZE = 100 ; static class node { int val ; node left , right ; } ; static class Stack { int size ; int top ; node [ ] array ; } ; static Stack createStack ( int size ) { Stack stack = new Stack ( ) ; stack . size = size ; stack . top = - 1 ; stack . array = new node [ stack . size ] ; return stack ; } static int isFull ( Stack stack ) { return ( stack . top - 1 == stack . size ) ? 1 : 0 ; } static int isEmpty ( Stack stack ) { return stack . top == - 1 ? 1 : 0 ; } static void push ( Stack stack , node node ) { if ( isFull ( stack ) == 1 ) return ; stack . array [ ++ stack . top ] = node ; } static node pop ( Stack stack ) { if ( isEmpty ( stack ) == 1 ) return null ; return stack . array [ stack . top -- ] ; } static boolean isPairPresent ( node root , int target ) { Stack s1 = createStack ( MAX_SIZE ) ; Stack s2 = createStack ( MAX_SIZE ) ; boolean done1 = false , done2 = false ; int val1 = 0 , val2 = 0 ; node curr1 = root , curr2 = root ; while ( true ) { while ( done1 == false ) { if ( curr1 != null ) { push ( s1 , curr1 ) ; curr1 = curr1 . left ; } else { if ( isEmpty ( s1 ) == 1 ) done1 = true ; else { curr1 = pop ( s1 ) ; val1 = curr1 . val ; curr1 = curr1 . right ; done1 = true ; } } } while ( done2 == false ) { if ( curr2 != null ) { push ( s2 , curr2 ) ; curr2 = curr2 . right ; } else { if ( isEmpty ( s2 ) == 1 ) done2 = true ; else { curr2 = pop ( s2 ) ; val2 = curr2 . val ; curr2 = curr2 . left ; done2 = true ; } } } if ( ( val1 != val2 ) && ( val1 + val2 ) == target ) { System . out . print ( " Pair ▁ Found : ▁ " + val1 + " + ▁ " + val2 + " ▁ = ▁ " + target + "NEW_LINE"); return true ; } else if ( ( val1 + val2 ) < target ) done1 = false ; else if ( ( val1 + val2 ) > target ) done2 = false ; if ( val1 >= val2 ) return false ; } } static node NewNode ( int val ) { node tmp = new node ( ) ; tmp . val = val ; tmp . right = tmp . left = null ; return tmp ; } public static void main ( String [ ] args ) { node root = NewNode ( 15 ) ; root . left = NewNode ( 10 ) ; root . right = NewNode ( 20 ) ; root . left . left = NewNode ( 8 ) ; root . left . right = NewNode ( 12 ) ; root . right . left = NewNode ( 16 ) ; root . right . right = NewNode ( 25 ) ; int target = 33 ; if ( isPairPresent ( root , target ) == false ) System . out . print ( " No such values are found "); } }

Accumulator variables: top
Boolean variables: done1, done2
Class/struct names: GFG, Stack, node
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left , right ; } ; static Node NewNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = null ; temp . right = null ; return temp ; } static Node insert ( Node root , int key ) { if ( root == null ) return NewNode ( key ) ; if ( key < root . data ) root . left = insert ( root . left , key ) ; else root . right = insert ( root . right , key ) ; return root ; } static boolean findpairUtil ( Node root , int sum , HashSet < Integer > set ) { if ( root == null ) return false ; if ( findpairUtil ( root . left , sum , set ) ) return true ; if ( set . contains ( sum - root . data ) ) { System . out . println ( " Pair ▁ is ▁ found ▁ ( " + ( sum - root . data ) + " , ▁ " + root . data + " ) " ) ; return true ; } else set . add ( root . data ) ; return findpairUtil ( root . right , sum , set ) ; } static void findPair ( Node root , int sum ) { HashSet < Integer > set = new HashSet < Integer > ( ) ; if ( ! findpairUtil ( root , sum , set ) ) System . out . print ( " Pairs ▁ do ▁ not ▁ exit " + "NEW_LINE"); } public static void main ( String [ ] args ) { Node root = null ; root = insert ( root , 15 ) ; root = insert ( root , 10 ) ; root = insert ( root , 20 ) ; root = insert ( root , 8 ) ; root = insert ( root , 12 ) ; root = insert ( root , 16 ) ; root = insert ( root , 25 ) ; root = insert ( root , 10 ) ; int sum = 33 ; findPair ( root , sum ) ; } }

Class/struct names: GFG, Node