Calculating depth and descendants of tree

Posted by yuudachi on Stack Overflow See other posts from Stack Overflow or by yuudachi
Published on 2010-05-05T03:34:35Z Indexed on 2010/05/05 3:38 UTC
Read the original article Hit count: 301

Filed under:
|
|
|

Can you guys help me with the algorithm to do these things? I have preorder, inorder, and postorder implemented, and I am given the hint to traverse the tree with one of these orders. I am using dotty to label (or "visit") the nodes.

Depth is the number of edges from the root to the bottom leaf, so everytime I move, I add +1 to the depth? Something like that?

No idea about the algorithm for descendants. They are asking about the number of nodes a specific node has under itself.

These are normal trees btw.

© Stack Overflow or respective owner

Related posts about trees

Related posts about depth