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

What sort does arrays sort use?

472


What are the scenarios in which an element can be inserted into the circular queue?

893


What is binary tree in discrete mathematics?

478


What is array and string?

474


Who invented merge sort?

476






How can you insert a node in a random location of the linked list?

498


What does simulation of queues mean?

566


What is the complexity of arraylist?

480


What is the Role of push() and pop() method?

524


Is bubble sort slow?

516


If you are using c language to implement the heterogeneous linked list, explain what pointer type will you use?

610


How is the front of the queue calculated in data structure?

431


How do you find the time complexity of a bubble sort?

480


How do hash tables work?

501


What is difference between data type and variable?

464