codeparrot/xlcost-text-to-code huggingface dataset:
Sum of the nodes of a Circular Linked List | Java program to find the sum of all nodes of a Circular linked list ; structure for a node ; Function to insert a node at the beginning of a Circular linked list ; If linked list is not null then set the next of last node ; For the first node ; Function to find sum of the given Circular linked list ; Driver code ; Initialize lists as empty ; Created linked list will be 11.2 .56 .12
import java . util . * ; class GFG { static class Node { int data ; Node next ; } ; static Node push ( Node head_ref , int data ) { Node ptr1 = new Node ( ) ; Node temp = head_ref ; ptr1 . data = data ; ptr1 . next = head_ref ; if ( head_ref != null ) { while ( temp . next != head_ref ) temp = temp . next ; temp . next = ptr1 ; } else ptr1 . next = ptr1 ; head_ref = ptr1 ; return head_ref ; } static int sumOfList ( Node head ) { Node temp = head ; int sum = 0 ; if ( head != null ) { do { temp = temp . next ; sum += temp . data ; } while ( temp != head ) ; } return sum ; } public static void main ( String args [ ] ) { Node head = null ; head = push ( head , 12 ) ; head = push ( head , 56 ) ; head = push ( head , 2 ) ; head = push ( head , 11 ) ; System . out . println ( " Sum ▁ of ▁ Circular ▁ linked " + " ▁ list ▁ is ▁ = ▁ " + sumOfList ( head ) ) ; } }
Delete every Kth node from circular linked list | Java program to delete every kth Node from circular linked list . ; structure for a Node ; Utility function to print the circular linked list ; Function to delete every kth Node ; If list is empty , simply return . ; take two pointers - current and previous ; Check if Node is the only Node \ If yes , we reached the goal , therefore return . ; Print intermediate list . ; If more than one Node present in the list , Make previous pointer point to current Iterate current pointer k times , i . e . current Node is to be deleted . ; If Node to be deleted is head ; If Node to be deleted is last Node . ; Function to insert a Node at the end of a Circular linked list ; Create a new Node ; if the list is empty , make the new Node head Also , it will point to itself . ; traverse the list to reach the last Node and insert the Node ; Driver code ; insert Nodes in the circular linked list ; Delete every kth Node from the circular linked list .
class GFG { static class Node { int data ; Node next ; Node ( int x ) { data = x ; next = null ; } } ; static void printList ( Node head ) { if ( head == null ) return ; Node temp = head ; do { System . out . print ( temp . data + " - > " ) ; temp = temp . next ; } while ( temp != head ) ; System . out . println ( head . data ) ; } static Node deleteK ( Node head_ref , int k ) { Node head = head_ref ; if ( head == null ) return null ; Node curr = head , prev = null ; while ( true ) { if ( curr . next == head && curr == head ) break ; printList ( head ) ; for ( int i = 0 ; i < k ; i ++ ) { prev = curr ; curr = curr . next ; } if ( curr == head ) { prev = head ; while ( prev . next != head ) prev = prev . next ; head = curr . next ; prev . next = head ; head_ref = head ; } else if ( curr . next == head ) { prev . next = head ; } else { prev . next = curr . next ; } } return head ; } static Node insertNode ( Node head_ref , int x ) { Node head = head_ref ; Node temp = new Node ( x ) ; if ( head == null ) { temp . next = temp ; head_ref = temp ; return head_ref ; } else { Node temp1 = head ; while ( temp1 . next != head ) temp1 = temp1 . next ; temp1 . next = temp ; temp . next = head ; } return head ; } public static void main ( String args [ ] ) { Node head = null ; head = insertNode ( head , 1 ) ; head = insertNode ( head , 2 ) ; head = insertNode ( head , 3 ) ; head = insertNode ( head , 4 ) ; head = insertNode ( head , 5 ) ; head = insertNode ( head , 6 ) ; head = insertNode ( head , 7 ) ; head = insertNode ( head , 8 ) ; head = insertNode ( head , 9 ) ; int k = 4 ; head = deleteK ( head , k ) ; } }
Insertion at Specific Position in a Circular Doubly Linked List | Java program to convert insert an element at a specific position in a circular doubly linked listing , end and middle ; Doubly linked list node ; Utility function to create a node in memory ; Function to display the list ; Function to count nunmber of elements in the list ; Declare temp pointer to traverse the list ; Variable to store the count ; Iterate the list and increment the count ; As the list is circular , increment the counter at last ; Function to insert a node at a given position in the circular doubly linked list ; Declare two pointers ; Create a new node in memory ; Point temp to start ; count of total elements in the list ; If list is empty or the position is not valid , return false ; Assign the data ; Iterate till the loc ; See in Image , circle 1 ; See in Image , Circle 2 ; See in Image , Circle 3 ; See in Image , Circle 4 ; Function to create circular doubly linked list from array elements ; Declare newNode and temporary pointer ; Iterate the loop until array length ; Create new node ; Assign the array data ; If it is first element Put that node prev and next as start as it is circular ; Find the last node ; Add the last node to make them in circular fashion ; Driver Code ; Array elements to create circular doubly linked list ; Start Pointer ; Create the List ; Display the list before insertion ; Inserting 8 at 3 rd position ; Display the list after insertion
class GFG { static class node { int data ; node next ; node prev ; } ; static node getNode ( ) { return new node ( ) ; } static int displayList ( node temp ) { node t = temp ; if ( temp == null ) return 0 ; else { System . out . println ( " The ▁ list ▁ is : ▁ " ) ; while ( temp . next != t ) { System . out . print ( temp . data + " ▁ " ) ; temp = temp . next ; } System . out . println ( temp . data ) ; return 1 ; } } static int countList ( node start ) { node temp = start ; int count = 0 ; while ( temp . next != start ) { temp = temp . next ; count ++ ; } count ++ ; return count ; } static node insertAtLocation ( node start , int data , int loc ) { node temp , newNode ; int i , count ; newNode = getNode ( ) ; temp = start ; count = countList ( start ) ; if ( temp == null count < loc ) return start ; else { newNode . data = data ; for ( i = 1 ; i < loc - 1 ; i ++ ) { temp = temp . next ; } newNode . next = temp . next ; ( temp . next ) . prev = newNode ; temp . next = newNode ; newNode . prev = temp ; return start ; } } static node createList ( int arr [ ] , int n , node start ) { node newNode , temp ; int i ; for ( i = 0 ; i < n ; i ++ ) { newNode = getNode ( ) ; newNode . data = arr [ i ] ; if ( i == 0 ) { start = newNode ; newNode . prev = start ; newNode . next = start ; } else { temp = ( start ) . prev ; temp . next = newNode ; newNode . next = start ; newNode . prev = temp ; temp = start ; temp . prev = newNode ; } } return start ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; int n = arr . length ; node start = null ; start = createList ( arr , n , start ) ; displayList ( start ) ; start = insertAtLocation ( start , 8 , 3 ) ; displayList ( start ) ; } }
Convert an Array to a Circular Doubly Linked List | Java program to convert array to circular doubly linked list ; Doubly linked list node ; Utility function to create a node in memory ; Function to display the list ; Function to convert array into list ; Declare newNode and temporary pointer ; Iterate the loop until array length ; Create new node ; Assign the array data ; If it is first element Put that node prev and next as start as it is circular ; Find the last node ; Add the last node to make them in circular fashion ; Driver Code ; Array to be converted ; Start Pointer ; Create the List ; Display the list
class GFG { static class node { int data ; node next ; node prev ; } ; static node getNode ( ) { return new node ( ) ; } static int displayList ( node temp ) { node t = temp ; if ( temp == null ) return 0 ; else { System . out . print ( " The ▁ list ▁ is : ▁ " ) ; while ( temp . next != t ) { System . out . print ( temp . data + " ▁ " ) ; temp = temp . next ; } System . out . print ( temp . data ) ; return 1 ; } } static node createList ( int arr [ ] , int n , node start ) { node newNode , temp ; int i ; for ( i = 0 ; i < n ; i ++ ) { newNode = getNode ( ) ; newNode . data = arr [ i ] ; if ( i == 0 ) { start = newNode ; newNode . prev = start ; newNode . next = start ; } else { temp = ( start ) . prev ; temp . next = newNode ; newNode . next = start ; newNode . prev = temp ; temp = start ; temp . prev = newNode ; } } return start ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; node start = null ; start = createList ( arr , n , start ) ; displayList ( start ) ; } }
Lucky alive person in a circle | Code Solution to sword puzzle | Java code to find the luckiest person ; Node structure ; Function to find the luckiest person ; Create a single node circular linked list . ; Starting from first soldier . ; condition for evaluating the existence of single soldier who is not killed . ; deleting soldier from the circular list who is killed in the fight . ; Returning the Luckiest soldier who remains alive . ; Driver code
class GFG { static class Node { int data ; Node next ; } ; static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . next = null ; return node ; } static int alivesol ( int Num ) { if ( Num == 1 ) return 1 ; Node last = newNode ( 1 ) ; last . next = last ; for ( int i = 2 ; i <= Num ; i ++ ) { Node temp = newNode ( i ) ; temp . next = last . next ; last . next = temp ; last = temp ; } Node curr = last . next ; Node temp = new Node ( ) ; while ( curr . next != curr ) { temp = curr ; curr = curr . next ; temp . next = curr . next ; temp = temp . next ; curr = temp ; } int res = temp . data ; return res ; } public static void main ( String args [ ] ) { int N = 100 ; System . out . println ( alivesol ( N ) ) ; } }
Lowest Common Ancestor of the deepest leaves of a Binary Tree | Node of a Binary Tree ; Function to find the depth of the Binary Tree ; If root is not null ; Left recursive subtree ; Right recursive subtree ; Returns the maximum depth ; Function to perform the depth first search on the binary tree ; If root is null ; If curr is equal to depth ; Left recursive subtree ; Right recursive subtree ; If left and right are not null ; Return left , if left is not null Otherwise return right ; Function to find the LCA of the deepest nodes of the binary tree ; If root is null ; Stores the deepest depth of the binary tree ; Return the LCA of the nodes at level depth ; Driver code ; Given Binary Tree
class Node { Node left = null ; Node right = null ; int data ; Node ( int data ) { this . data = data ; } } class GFG { public static int findDepth ( Node root ) { if ( root == null ) return 0 ; int left = findDepth ( root . left ) ; int right = findDepth ( root . right ) ; return 1 + Math . max ( left , right ) ; } public static Node DFS ( Node root , int curr , int depth ) { if ( root == null ) return null ; if ( curr == depth ) return root ; Node left = DFS ( root . left , curr + 1 , depth ) ; Node right = DFS ( root . right , curr + 1 , depth ) ; if ( left != null && right != null ) return root ; return ( left != null ) ? left : right ; } public static Node lcaOfDeepestLeaves ( Node root ) { if ( root == null ) return null ; int depth = findDepth ( root ) - 1 ; return DFS ( root , 0 , depth ) ; } 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 . right . left . left = new Node ( 8 ) ; root . right . left . right = new Node ( 9 ) ; System . out . println ( lcaOfDeepestLeaves ( root ) . data ) ; } }
Check if two nodes are on same path in a tree | Set 2 | Java program to check if two nodes are on same path in a tree without using any extra space ; Function to filter the return Values ; Utility function to check if nodes are on same path or not ; Condition to check if any vertex is equal to given two vertex or not ; Check if the current position has 1 ; Recursive call ; Return LCA ; Function to check if nodes lies on same path or not ; Driver code
class GFG { static int filter ( int x , int y , int z ) { if ( x != - 1 && y != - 1 ) { return z ; } return x == - 1 ? y : x ; } static int samePathUtil ( int mtrx [ ] [ ] , int vrtx , int v1 , int v2 , int i ) { int ans = - 1 ; if ( i == v1 i == v2 ) return i ; for ( int j = 0 ; j < vrtx ; j ++ ) { if ( mtrx [ i ] [ j ] == 1 ) { ans = filter ( ans , samePathUtil ( mtrx , vrtx , v1 , v2 , j ) , i ) ; } } return ans ; } static boolean isVertexAtSamePath ( int mtrx [ ] [ ] , int vrtx , int v1 , int v2 , int i ) { int lca = samePathUtil ( mtrx , vrtx , v1 - 1 , v2 - 1 , i ) ; if ( lca == v1 - 1 lca == v2 - 1 ) return true ; return false ; } public static void main ( String [ ] args ) { int vrtx = 7 ; int mtrx [ ] [ ] = { { 0 , 1 , 1 , 1 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 1 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 1 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 1 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 } } ; int v1 = 1 , v2 = 5 ; if ( isVertexAtSamePath ( mtrx , vrtx , v1 , v2 , 0 ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }
Count of all prime weight nodes between given nodes in the given Tree | Java program to count prime weight nodes between two nodes in the given tree ; Function to perform Sieve Of Eratosthenes for prime number ; Initialize all entries of prime it as true a value in prime [ i ] will finally be false if i is Not a prime , else true . ; Check if prime [ p ] is not changed , then it is a prime ; Update all multiples of p greater than or equal to the square of it numbers which are multiple of p and are less than p ^ 2 are already been marked . ; Function to perform dfs ; Stores parent of each node ; Stores level of each node from root ; Function to perform prime number between the path ; The node which is present farthest from the root node is taken as v If u is farther from root node then swap the two ; Find the ancestor of v which is at same level as u ; If Weight is prime increment count ; If u is the ancestor of v then u is the LCA of u and v Now check if weigh [ v ] is prime or not ; When v and u are on the same level but are in different subtree . Now move both u and v up by 1 till they are not same ; If weight of first ancestor is prime ; Driver code ; Precompute all the prime numbers till MAX ; Weights of the node ; Edges of the tree
import java . util . * ; class GFG { static final int MAX = 1000 ; static int [ ] weight = new int [ MAX ] ; static int [ ] level = new int [ MAX ] ; static int [ ] par = new int [ MAX ] ; static boolean [ ] prime = new boolean [ MAX + 1 ] ; static Vector < Integer > [ ] graph = new Vector [ MAX ] ; static void SieveOfEratosthenes ( ) { for ( int i = 0 ; i < prime . length ; i ++ ) prime [ i ] = true ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= MAX ; i += p ) prime [ i ] = false ; } } } static void dfs ( int node , int parent , int h ) { par [ node ] = parent ; level [ node ] = h ; for ( int child : graph [ node ] ) { if ( child == parent ) continue ; dfs ( child , node , h + 1 ) ; } } static int findPrimeOnPath ( int u , int v ) { int count = 0 ; if ( level [ u ] > level [ v ] ) { int temp = v ; v = u ; u = temp ; } int d = level [ v ] - level [ u ] ; while ( d -- > 0 ) { if ( prime [ weight [ v ] ] ) count ++ ; v = par [ v ] ; } if ( v == u ) { if ( prime [ weight [ v ] ] ) count ++ ; return count ; } while ( v != u ) { if ( prime [ weight [ v ] ] ) count ++ ; if ( prime [ weight [ u ] ] ) count ++ ; u = par [ u ] ; v = par [ v ] ; } if ( prime [ weight [ v ] ] ) count ++ ; return count ; } public static void main ( String [ ] args ) { for ( int i = 0 ; i < graph . length ; i ++ ) graph [ i ] = new Vector < Integer > ( ) ; SieveOfEratosthenes ( ) ; weight [ 1 ] = 5 ; weight [ 2 ] = 10 ; weight [ 3 ] = 11 ; weight [ 4 ] = 8 ; weight [ 5 ] = 6 ; graph [ 1 ] . add ( 2 ) ; graph [ 2 ] . add ( 3 ) ; graph [ 2 ] . add ( 4 ) ; graph [ 1 ] . add ( 5 ) ; dfs ( 1 , - 1 , 0 ) ; int u = 3 , v = 5 ; System . out . print ( findPrimeOnPath ( u , v ) ) ; } }
Lowest Common Ancestor for a Set of Nodes in a Rooted Tree | Java Program to find the LCA in a rooted tree for a given set of nodes ; Set time 1 initially ; Case for root node ; In - time for node ; Out - time for the node ; level [ i ] - . Level of node i ; t_in [ i ] - . In - time of node i ; t_out [ i ] - . Out - time of node i ; Fill the level , in - time and out - time of all nodes ; To find minimum in - time among all nodes in LCA set ; To find maximum in - time among all nodes in LCA set ; Node with same minimum and maximum out time is LCA for the set ; Take the minimum level as level of LCA ; If i - th node is at a higher level than that of the minimum among the nodes of the given set ; Compare in - time , out - time and level of i - th node to the respective extremes among all nodes of the given set ; Driver code
import java . util . * ; class GFG { static int T = 1 ; static void dfs ( int node , int parent , Vector < Integer > g [ ] , int level [ ] , int t_in [ ] , int t_out [ ] ) { if ( parent == - 1 ) { level [ node ] = 1 ; } else { level [ node ] = level [ parent ] + 1 ; } t_in [ node ] = T ; for ( int i : g [ node ] ) { if ( i != parent ) { T ++ ; dfs ( i , node , g , level , t_in , t_out ) ; } } T ++ ; t_out [ node ] = T ; } static int findLCA ( int n , Vector < Integer > g [ ] , Vector < Integer > v ) { int [ ] level = new int [ n + 1 ] ; int [ ] t_in = new int [ n + 1 ] ; int [ ] t_out = new int [ n + 1 ] ; dfs ( 1 , - 1 , g , level , t_in , t_out ) ; int mint = Integer . MAX_VALUE , maxt = Integer . MIN_VALUE ; int minv = - 1 , maxv = - 1 ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) { if ( t_in [ v . get ( i ) ] < mint ) { mint = t_in [ v . get ( i ) ] ; minv = v . get ( i ) ; } if ( t_out [ v . get ( i ) ] > maxt ) { maxt = t_out [ v . get ( i ) ] ; maxv = v . get ( i ) ; } } if ( minv == maxv ) { return minv ; } int lev = Math . min ( level [ minv ] , level [ maxv ] ) ; int node = 0 , l = Integer . MIN_VALUE ; for ( int i = 1 ; i <= n ; i ++ ) { if ( level [ i ] > lev ) continue ; if ( t_in [ i ] <= mint && t_out [ i ] >= maxt && level [ i ] > l ) { node = i ; l = level [ i ] ; } } return node ; } public static void main ( String [ ] args ) { int n = 10 ; Vector < Integer > [ ] g = new Vector [ n + 1 ] ; for ( int i = 0 ; i < g . length ; i ++ ) g [ i ] = new Vector < Integer > ( ) ; g [ 1 ] . add ( 2 ) ; g [ 2 ] . add ( 1 ) ; g [ 1 ] . add ( 3 ) ; g [ 3 ] . add ( 1 ) ; g [ 1 ] . add ( 4 ) ; g [ 4 ] . add ( 1 ) ; g [ 2 ] . add ( 5 ) ; g [ 5 ] . add ( 2 ) ; g [ 2 ] . add ( 6 ) ; g [ 6 ] . add ( 2 ) ; g [ 3 ] . add ( 7 ) ; g [ 7 ] . add ( 3 ) ; g [ 4 ] . add ( 10 ) ; g [ 10 ] . add ( 4 ) ; g [ 8 ] . add ( 7 ) ; g [ 7 ] . add ( 8 ) ; g [ 9 ] . add ( 7 ) ; g [ 7 ] . add ( 9 ) ; Vector < Integer > v = new Vector < > ( ) ; v . add ( 7 ) ; v . add ( 3 ) ; v . add ( 8 ) ; System . out . print ( findLCA ( n , g , v ) + "NEW_LINE"); } }
Sum of all odd nodes in the path connecting two given nodes | Java program to find sum of all odd nodes in the path connecting two given nodes ; Binary Tree node ; Utitlity function to create a new Binary Tree node ; Function to check if there is a path from root to the given node . It also populates ' arr ' with the given path ; if root is null there is no path ; push the node ' s ▁ value ▁ in ▁ ' arr ' ; if it is the required node return true ; else check whether the required node lies in the left subtree or right subtree of the current node ; required node does not lie either in the left or right subtree of the current node Thus , remove current node ' s ▁ value ▁ from ▁ ▁ ' arr 'and then return false ; Function to get the sum of odd nodes in the path between any two nodes in a binary tree ; vector to store the path of first node n1 from root ; vector to store the path of second node n2 from root ; Get intersection point ; Keep moving forward until no intersection is found ; calculate sum of ODD nodes from the path ; Driver Code
import java . util . * ; class solution { static class Node { int data ; Node left ; Node right ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return node ; } static boolean getPath ( Node root , Vector < Integer > arr , int x ) { if ( root == null ) return false ; arr . add ( root . data ) ; if ( root . data == x ) return true ; if ( getPath ( root . left , arr , x ) || getPath ( root . right , arr , x ) ) return true ; arr . remove ( arr . size ( ) - 1 ) ; return false ; } static int sumOddNodes ( Node root , int n1 , int n2 ) { Vector < Integer > path1 = new Vector < Integer > ( ) ; Vector < Integer > path2 = new Vector < Integer > ( ) ; getPath ( root , path1 , n1 ) ; getPath ( root , path2 , n2 ) ; int intersection = - 1 ; int i = 0 , j = 0 ; while ( i != path1 . size ( ) || j != path2 . size ( ) ) { if ( i == j && path1 . get ( i ) == path2 . get ( j ) ) { i ++ ; j ++ ; } else { intersection = j - 1 ; break ; } } int sum = 0 ; for ( i = path1 . size ( ) - 1 ; i > intersection ; i -- ) if ( path1 . get ( i ) % 2 != 0 ) sum += path1 . get ( i ) ; for ( i = intersection ; i < path2 . size ( ) ; i ++ ) if ( path2 . get ( i ) % 2 != 0 ) sum += path2 . get ( i ) ; return sum ; } 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 ) ; root . right . right = newNode ( 6 ) ; int node1 = 5 ; int node2 = 6 ; System . out . print ( sumOddNodes ( root , node1 , node2 ) ) ; } }
Lowest Common Ancestor in Parent Array Representation | Java program to find LCA in a tree represented as parent array . ; Maximum value in a node ; Function to find the Lowest common ancestor ; Create a visited vector and mark all nodes as not visited . ; Moving from n1 node till root and mark every accessed node as visited ; Move to the parent of node n1 ; For second node finding the first node common ; Insert function for Binary tree ; Driver Function ; Maximum capacity of binary tree ; Root marked
import java . util . * ; class GFG { static int MAX = 1000 ; static int findLCA ( int n1 , int n2 , int parent [ ] ) { boolean [ ] visited = new boolean [ MAX ] ; visited [ n1 ] = true ; while ( parent [ n1 ] != - 1 ) { visited [ n1 ] = true ; n1 = parent [ n1 ] ; } visited [ n1 ] = true ; while ( ! visited [ n2 ] ) n2 = parent [ n2 ] ; return n2 ; } static void insertAdj ( int parent [ ] , int i , int j ) { parent [ i ] = j ; } public static void main ( String [ ] args ) { int [ ] parent = new int [ MAX ] ; parent [ 20 ] = - 1 ; insertAdj ( parent , 8 , 20 ) ; insertAdj ( parent , 22 , 20 ) ; insertAdj ( parent , 4 , 8 ) ; insertAdj ( parent , 12 , 8 ) ; insertAdj ( parent , 10 , 12 ) ; insertAdj ( parent , 14 , 12 ) ; System . out . println ( findLCA ( 10 , 14 , parent ) ) ; } }