开发者

number of leaves in a strict binary tree

开发者 https://www.devze.com 2023-03-26 10:07 出处:网络
I looking for derivation how we came to following result. sum of 2 to power of i, as i goes from 0 to n => answer is giv开发者_开发技巧en as (2 power of (n+1) -1).

I looking for derivation how we came to following result.

sum of 2 to power of i, as i goes from 0 to n => answer is giv开发者_开发技巧en as (2 power of (n+1) -1).

Can any one show me how we achieved above result or to proper link where we have solution.

Thanks!


Proof by induction.

Observe it's true for n=0 - sum0->0 = 1 = 2^1 - 1

Assume true for n = k-1, so sum[0->k-1] = 2^k - 1. Then sum[0->k] = sum[0->k-1] + 2^k = 2^k - 1 + 2^k = 2(2^k) - 1 = 2^(k+1) - 1.

Therefore true for all n.


It comes from the mathematical geometric progression.

If you want a clearer (more intuitive) explanation, you can read this nice explanation

0

精彩评论

暂无评论...
验证码 换一张
取 消