@kool_guy :
use recursion.
map<treenode, int> min_map;
// p is a node of the tree;
// get_child_count(p) returns count of p's child;
// p[i] is its (i+1)th child, 0 <= i <= get_child_count(p)-1;
int minStep( p )
{
if( min_map.key_exist(p) ) return min_map[p];
min_map[p] = 0;
int child_count = get_child_count(p);
if( child_count == 0 ) return 0;
int min_step = INT_MAX;
for( int i = 0; i < child_count; i++ )
{
int n = max( child_count, minStep( p[i] ) );
if( n < min_step )
{
min_step = n;
}
}
min_map[p] = min_step;
return min_step;
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---