A recursive function to used by getMinIter ( ) . This function mainly does postorder traversal and get minimum iteration of all children of parent node , sort them in decreasing order and then get minimum iteration of parent node 1. Get minItr ( B ) of all children ( B ) of a node ( A ) 2. Sort all minItr ( B ) in descending order 3. Get minItr of A based on all minItr ( B ) minItr ( A ) = child ( A ) -- >> child ( A ) is children count of node A For children B from i = 0 to child ( A ) minItr ( A ) = max ( minItr ( A ) , minItr ( B ) + i + 1 ) Base cases would be : If node is leaf , minItr = 0 If node 's height is 1, minItr = children count
private void getMinIterUtil ( int u , int [ ] minItr ) {