-1

Assume if the node has N children in a tree and height be H, is total number of nodes equals N pow(H) or the logic applies only for 2 because of log base 2?

user2531608
  • 141
  • 2
  • 7
  • Also, if I have N digits, I can accommodate address space up to 2 power (N) memory slots. Assume if memory is reprented by trinary (0,1, and 2), will it be 3 power N? – user2531608 Jun 01 '16 at 09:35

1 Answers1

0

I am assuming height of a tree with single node is 0.

I am also assuming that number of children of every node except leaves is N.

Now let Num(X) is the number of nodes in a tree of height X. The answer we seek is Num(H).

Now we can derive a recurrence relation :

Num(H) = 1 + N.Num(H-1) 

The term 1 is accounting for the root and each Num(H-1), as mentioned, denotes the height of sub-tree with root as child of the root and there are N children of the main root.

Similarly,

Num(H) = 1+N.(1 + N.Num(H-2)) = 1+N+N2.Num(H-2) = 1+N+N2+N3+....+NH.Num(0)

But Num(0) = 1 since the number of nodes in a tree with height 0 is 1 i.e a single node.

Therefore, Num(H) = (NH+1-1)/(N-1)

2rd_7
  • 462
  • 1
  • 3
  • 15