It is an ebook about trees

源代码在线查看: full n-ary tree has m non-leaf nodes.txt

软件大小: 11 K
上传用户: sbukhpak
关键词: about ebook trees It
下载地址: 免注册下载 普通下载 VIP

相关代码

				 full N-ary tree has M non-leaf nodes, how many leaf nodes does it have? 
				
				Discuss it!          
				
				
				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 
				 
							

相关资源