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 happens if we put duplicate key in hashmap?

657


How null key is handled in hashmap?

643


What do you mean by breadth first search (bfs)?

795


What is arrays copyof?

663


What is quick sort?

835


A lot of data structures related programs related to only trees and graphs, like the diameter of a tree, removing the loops in a graph etc.

793


What are the Differences between map and hashmap?

696


What is breadth first tree?

777


How do you sort an arraylist?

658


What is the difference between Strings and Arrays?

701


What are the types of collision resolution strategies in open addressing?

772


How to sort an Array?

719


write a program to show the insertion and deletion of an element in an array using the position

671


What is difference between hashmap and hashtable?

664


What is a priority queue?

730