Re: Height of weighted tree
Well, normally, to find the depth of a tree, we do something like this:
Code:
int GetDepth(Node * node)
{
//this example doesn't take into account trees with just one child
//but that's something you'll need to worry about
if(!(node->right || node->left))
{
//a tree with one node has height zero
return 0;
}
else
{
return std::max(GetDepth(node->right), GetDepth(node->left)) + 1;
}
}
It shouldn't be too hard to extend that to your problem. Instead of adding 1, you'd add the edge's weight. And you'd have to have some way of tracking the current deepest leaf (either with an out-paramo or returning a struct with both the depth and the node, or something else).
Regardless, the number of lines of code should be quite small.