What is the maximum total number of nodes in a tree that has
N levels? Note that the root is level (zero)

Answer Posted / hex

to be more generic this kind of problem is best solved
recursivly.

To point out that 2 ^ N AND 3 ^ N are both wrong,
here's a few examples: (the exponet is the amount of levels)
2^0 = 1, correct
2^1 = 2, incorrect, should be 3
2^2 = 4, incorrect, should be 7

And a tree with three children
3^0 = 1, correct
3^1 = 3, incorrect, should be 4
3^2 = 9, incorrect, should be 13

Looking at that I'm sure you can see the pattern.
Let
C = "Number of Possible Children"
N = Levels

N
Σ C^N
j=0

or in C++ code
int NodeCount(int C, int N)
{
if (N < 0) return 0
return NodeCount(C, N-1) + C^N
}

Is This Answer Correct ?    8 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what are the methods available in storing sequential files ?

496


How do you sort an array by value?

476


What is difference between rb tree and avl tree?

471


which is the simplest file structure? (Sequential, indexed, random)

787


What are examples of data structures?

512






Can a class have a constructor?

512


Run time memory allocation is known as in data structure?

534


What are the issues that hamper the efficiency in sorting a file?

593


Explain the terms base case, recursive case, binding time, run-time stack and tail recursion.

465


When is a graph said to be weakly connected?

524


Is python good for freshers?

502


How to compare Two Arrays?

544


What is adt example?

549


What is the best complexity of bubble sort?

472


What is the use of bubble sort?

526