Search:     Advanced search
Browse by category:
C/C++   |   Java   |   Oracle/Database   |   SAP   |   ASP .NET   |   Mainframe-DB2   |   Freshers

A full N-ary tree has M non-leaf nodes, how many leaf nodes does it have?

Add comment
Views: 265
Votes: 0
Comments: 0

Use Geometric progression.


M + (N ^ (n-1)) = (1 - (N ^ n)) / (1 - N)

Here (N ^ (n-1)) is the number of leaf-nodes.

Solving for this leads to the answer

Leaf nodes = M * (N - 1) + 1

 

Suppose you have a 3-ary tree


A
B C D
E F G H I J K L M

 

So, here M=4 and N=3. So using the formula above,


Leaf nodes = M * (N - 1) + 1 = 4 * (3 - 1) + 1 = 9

Others in this Category
document Q: When do you use a LIKE statement?
document Check if the 20th bit of a 32 bit integer is on or off?
document Q: What is the meaning of underscore ( ‘_’ ) in the LIKE statement?
document Write a C program to count bits set in an integer?
document Q: Is BETWEEN inclusive of the range values specified?
document How many different trees can be constructed using n nodes?
document Construct a tree given its inorder and preorder traversal strings. Similarly construct a tree given its inorder and post For Inorder And Preorder traversals
document Q: What is DCLGEN ?
document Q: What is the COBOL picture clause for a DB2 column defined as DECIMAL(11,2)?
document Implement Breadth First Search (BFS) and Depth First Search (DFS)
» More articles



RSS