Algorithm Design and Applications
CS:3330 (22C:031) Algorithms, Spring 2018
Tree
Depth
Let v be a node of a tree T. The depth of v is the number of ancestors of v,
excluding v itself. Note that this definition implies that the depth of the root of T
is 0. The depth of a node v can also be recursively defined as follows:
• If v is the root, then the depth of v is 0.
• Otherwise, the depth of v is one plus the depth of the parent of v.
1 | Algorithm depth(T, v): |
using the following recursive definition of the height of a node v in a tree T:
• If v is an external node, then the height of v is 0.
• Otherwise, the height of v is one plus the maximum height of a child of v.
The height of a tree T is the height of the root of T.
1 | Algorithm height(T, v): |
Preorder Traversal
Postorder Traversal
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 志云宝宝的生活记录!



