?? full n-ary tree has m non-leaf nodes.txt
字號:
full N-ary tree has M non-leaf nodes, how many leaf nodes does it have?
Discuss it!
Use Geometric progression.
M + (N ^ (n-1)) = (1 - (N ^ n)) / (1 - N)
Here (N ^ (n-1)) is the number of leaf-nodes.
Solving for this leads to the answer
Leaf nodes = M * (N - 1) + 1
Suppose you have a 3-ary tree
A
B C D
E F G H I J K L M
So, here M=4 and N=3. So using the formula above,
Leaf nodes = M * (N - 1) + 1 = 4 * (3 - 1) + 1 = 9
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -