二叉树的路径和内部路径长度有什么区别

来源:百度知道 编辑:UC知道 时间:2024/06/22 06:34:20

1. 二叉树的路径是指从根节点到一个节点的路线。 比如下面这树:
1
/ \
2 3
/ \ / \
4 5 6 7
/ \ /
8 9 10

到节点10的路径就是 1->2 ->5 -> 10

2. 二叉树的内部路径长度就是指所有节点的深度之和。比如下面这树:
1
/ \
2 3
/ \ / \
4 5 6 7
/ \ /
8 9 10

节点号 深度
1 0
2 1
3 1
4 2
5 2
6 2
7 2
8 3
9 3
10 3
总计: 2 * 1 + 4 * 2 + 3 * 3 = 2 + 8 + 9 = 19

(length-1)%2

The path length is the sum of the levels all the trees nodes
Internal path length: sum of the levels of all internal nodes
External path length: sum of the levels of all external nodes