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
Can we change the size of an array at run time?
Is radix sort stable?
Does arraylist have index?
What do you mean by hash table?
what is Singly Linked list?
What is the most used data structure?
What happens if we put a key object in a hashmap which exists?
What is a binary search tree? Explain with example?
Explain about map and their types?
Why is quicksort faster than merge sort?
Is array immutable?
How do you find the number of comparisons in bubble sort?
Explain about the different lists available in the collection?
What is the difference between 1d and 2d array?
What is two-dimensional array?