Base case : Leaf node
if ( adj . get ( u ) . size ( ) == 0 ) return ; minItr [ u ] = adj . get ( u ) . size ( ) ; Integer [ ] minItrTemp = new Integer [ minItr [ u ] ] ; int k = 0 ; Iterator itr = adj . get ( u ) . iterator ( ) ; while ( itr . hasNext ( ) ) { int currentChild = ( int ) itr . next ( ) ; getMinIterUtil ( currentChild , minItr ) ; minItrTemp [ k ++ ] = minItr [ currentChild ] ; } Arrays . sort ( minItrTemp , Collections . reverseOrder ( ) ) ; for ( k = 0 ; k < adj . get ( u ) . size ( ) ; k ++ ) { int temp = minItrTemp [ k ] + k + 1 ; minItr [ u ] = Math . max ( minItr [ u ] , temp ) ; } }