codeparrot/xlcost-text-to-code huggingface dataset:
Sum of all leaf nodes of binary tree | Java program to find sum of all leaf nodes of binary tree ; user define class node ; constructor ; utility function which calculates sum of all leaf nodes ; add root data to sum if root is a leaf node ; propagate recursively in left and right subtree ; driver program ; construct binary tree ; variable to store sum of leaf nodes
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 ) ; } }
Inorder Tree Traversal without recursion and without stack ! | A binary tree tNode has data , a pointer to left child and a pointer to right child ; Function to traverse a binary tree without recursion and without stack ; Find the inorder predecessor of current ; Make current as right child of its * inorder predecessor ; Revert the changes made in the ' if ' part to restore the original tree i . e . , fix the right child of predecessor ; Driver Code ; Constructed binary tree is 1 / \ 2 3 / \ 4 5
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 ) ; } }
Sum of leaf nodes at minimum level | Java implementation to find the sum of leaf nodes at minimum level ; structure of a node of binary tree ; function to get a new node ; allocate space ; put in the data ; function to find the sum of leaf nodes at minimum level ; if tree is empty ; if there is only one node ; queue used for level order traversal ; push root node in the queue ' q ' ; count number of nodes in the current level ; traverse the current level nodes ; get front element from ' q ' ; if it is a leaf node ; accumulate data to ' sum ' ; set flag ' f ' to 1 , to signify minimum level for leaf nodes has been encountered ; if top ' s ▁ left ▁ and ▁ right ▁ child ▁ ▁ ▁ exists , ▁ then ▁ push ▁ them ▁ to ▁ ' q ' ; required sum ; Driver Code ; binary tree creation
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 ) ) ; } }
Root to leaf path sum equal to a given number | A binary tree node has data , pointer to left child and a pointer to right child ; Given a tree and a sum , return true if there is a path from the root down to a leaf , such that adding up all the values along the path equals the given sum . Strategy : subtract the node value from the sum when recurring down , and check to see if the sum is 0 when you run out of tree . ; Driver Code ; Constructed binary tree is 10 / \ 8 2 / \ / 3 5 2
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 ) ; } }
Sum of all the numbers that are formed from root to leaf paths | Java program to find sum of all numbers that are formed from root to leaf paths A binary tree node ; Returns sum of all root to leaf paths . The first parameter is root of current subtree , the second parameter is value of the number formed by nodes from root to this node ; Base case ; Update val ; if current node is leaf , return the current value of val ; recur sum of values for left and right subtree ; A wrapper function over treePathsSumUtil ( ) ; Pass the initial value as 0 as there is nothing above root ; Driver program to test above functions
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 ) ) ; } }
Merge Two Binary Trees by doing Node Sum ( Recursive and Iterative ) | A binary tree node has data , pointer to left child and a pointer to right child ; Helper method that allocates a new node with the given data and NULL left and right pointers . ; Given a binary tree , print its nodes in inorder ; first recur on left child ; then print the data of node ; now recur on right child ; Method to merge given two binary trees ; Driver method ; Let us construct the first Binary Tree 1 / \ 2 3 / \ \ 4 5 6 ; Let us construct the second Binary Tree 4 / \ 1 7 / / \ 3 2 6
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 ) ; } }
Merge Two Binary Trees by doing Node Sum ( Recursive and Iterative ) | Java program to Merge Two Binary Trees ; A binary tree node has data , pointer to left child and a pointer to right child ; Structure to store node pair onto stack ; Helper function that allocates a new node with the given data and null left and right pointers . ; Given a binary tree , print its nodes in inorder ; first recur on left child ; then print the data of node ; now recur on right child ; Function to merge given two binary trees ; Driver code ; Let us conthe first Binary Tree 1 / \ 2 3 / \ \ 4 5 6 ; Let us conthe second Binary Tree 4 / \ 1 7 / / \ 3 2 6
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 ) ; } }
Find root of the tree where children id sum for every node is given | Find root of tree where children sum for every node id is given . ; Every node appears once as an id , and every node except for the root appears once in a sum . So if we subtract all the sums from all the ids , we 're left  with the root id. ; Driver code
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)); } }
Print Postorder traversal from given Inorder and Preorder traversals | Java program to print postorder traversal from preorder and inorder traversals ; A utility function to search x in arr [ ] of size n ; Prints postorder traversal from given inorder and preorder traversals ; The first element in pre [ ] is always root , search it in in [ ] to find left and right subtrees ; If left subtree is not empty , print left subtree ; If right subtree is not empty , print right subtree ; Print root ; Driver code
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 ) ; } }
Lowest Common Ancestor in a Binary Tree | Set 1 | Class containing left and right child of current node and key value ; Root of the Binary Tree ; This function returns pointer to LCA of two given values n1 and n2 . This function assumes that n1 and n2 are present in Binary Tree ; Base case ; If either n1 or n2 matches with root 's key, report  the presence by returning root (Note that if a key is  ancestor of other, then the ancestor key becomes LCA ; Look for keys in left and right subtrees ; If both of the above calls return Non - NULL , then one key is present in once subtree and other is present in other , So this node is the LCA ; Otherwise check if left subtree or right subtree is LCA ; Driver program to test above functions
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 ) ; } }
Lowest Common Ancestor in a Binary Tree | Set 1 | Class containing left and right child of current node and key ; Root of the Binary Tree ; This function returns pointer to LCA of two given values n1 and n2 . v1 is set as true by this function if n1 is found v2 is set as true by this function if n2 is found ; Base case ; Store result in temp , in case of key match so that we can search for other key also . ; If either n1 or n2 matches with root 's key, report the presence  by setting v1 or v2 as true and return root (Note that if a key is ancestor of other, then the ancestor key becomes LCA) ; Look for keys in left and right subtrees ; If both of the above calls return Non - NULL , then one key is present in once subtree and other is present in other , So this node is the LCA ; Otherwise check if left subtree or right subtree is LCA ; Finds lca of n1 and n2 under the subtree rooted with ' node ' ; Initialize n1 and n2 as not visited ; Find lca of n1 and n2 using the technique discussed above ; Return LCA only if both n1 and n2 are present in tree ; Else return NULL ; Driver program to test above functions
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 " ) ; } }
Lowest Common Ancestor in a Binary Tree | Set 2 ( Using Parent Pointer ) | Java program to find lowest common ancestor using parent pointer ; A tree node ; A utility function to insert a new node with given key in Binary Search Tree ; If the tree is empty , return a new node ; Otherwise , recur down the tree ; return the ( unchanged ) node pointer ; To find LCA of nodes n1 and n2 in Binary Tree ; Creata a map to store ancestors of n1 ; Insert n1 and all its ancestors in map ; Check if n2 or any of its ancestors is in map . ; Driver method to test above functions
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 ) ; } }
Lowest Common Ancestor in a Binary Tree | Set 2 ( Using Parent Pointer ) |  ; Java program to find lowest common ancestor using parent pointer A tree node ; A utility function to insert a new node with given key in Binary Search Tree ; If the tree is empty , return a new node ; Otherwise , recur down the tree ; return the ( unchanged ) node pointer ; A utility function to find depth of a node ( distance of it from root ) ; To find LCA of nodes n1 and n2 in Binary Tree ; Find depths of two nodes and differences ; If n2 is deeper , swap n1 and n2 ; Move n1 up until it reaches the same level as n2 ; Now n1 and n2 are at same levels ; Driver method to test above functions
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 ) ; } }