Monday, 2 March 2015

proof(?) for tree height approx log (n)

In Diane's morning lecture, we talked bout height of a "perfect" tree being approximately log (n). Here, I want to show a "proof" for it. It probably will not be a formal proof, but I will show something that hopefully can be written in that form.

let's think of a tree with arity k. Then at "level" n, there will be k^(n-1) nodes.

At level 1, there is 1 node, at level 2 there is k nodes, at level 3 there is k^2... everytime you go one more level there will be k times more.
#Nodes(n) = #Nodes(n-1) * k, #Nodes(1) = 1
explicitly, #Nodes(n) = k^(n-1)

Then the total number of nodes leading to n is sum (k^(i)) for i = 0...n-1

S = (1-k^n)/(1-k)

This can be shown by subtracting S from rS and rearranging. I believe this kind of technique is called telescoping.
Conceptually, you have x + y + z - (y + z + A) = x + y - y + z - z - A

Anyhow, rearranging
S = (1-k^n)/(1-k),
we get log(S) = log(1-k^n) - log(1-k).
if r is const and as n-> inf,
log(S) = n*log(k), rearranging, the height n is ...
n = log(S)/log(k) = log base k of S
remembering that S was the total number of nodes,  we are where we want to be. :)

This post I diverted a little... Next post for sure, I will discuss my realization about what kinds of problems might be suitable for recursion. It's kind of obvious when you think about it, and I think I understood kind of intuitively but couldn't really exactly describe it...

No comments:

Post a Comment