Total nodes traversed in Euler Tour Tree | Javascript program to check the number of nodes in Euler Tour tree . ; Adjacency list representation of tree ; Function to add edges to tree ; Program to check if calculated Value is equal to 2 * size - 1 ; push out - degree of each node ; Driver Code ; Constructing 1 st tree from example ; Out_deg [ node [ i ] ] is equal to adj [ i ] . Count ; clear previous stored tree ; Constructing 2 nd tree from example ; Out_deg [ node [ i ] ] is equal to adj [ i ] . Count
var MAX = 1001 ; var adj = Array . from ( Array ( MAX ) , ( ) => Array ( ) ) ; function add_edge ( u , v ) { adj [ u ] . push ( v ) ; } function checkTotalNumberofNodes ( actualAnswer , size ) { var calculatedAnswer = size ; for ( var i = 1 ; i <= size ; i ++ ) calculatedAnswer += adj [ i ] . length ; if ( actualAnswer == calculatedAnswer ) document . write ( " " + calculatedAnswer + " " ) ; else document . write ( " " + " " ) ; } for ( var i = 0 ; i < MAX ; i ++ ) adj [ i ] = [ ] ; var N = 8 ; add_edge ( 1 , 2 ) ; add_edge ( 1 , 3 ) ; add_edge ( 2 , 4 ) ; add_edge ( 2 , 5 ) ; add_edge ( 3 , 6 ) ; add_edge ( 3 , 7 ) ; add_edge ( 6 , 8 ) ; checkTotalNumberofNodes ( 2 * N - 1 , N ) ; for ( var i = 1 ; i <= N ; i ++ ) adj [ i ] = [ ] N = 9 ; add_edge ( 1 , 2 ) ; add_edge ( 1 , 3 ) ; add_edge ( 2 , 4 ) ; add_edge ( 2 , 5 ) ; add_edge ( 2 , 6 ) ; add_edge ( 3 , 9 ) ; add_edge ( 5 , 7 ) ; add_edge ( 5 , 8 ) ; checkTotalNumberofNodes ( 2 * N - 1 , N ) ;