human
Possible edges of a tree for given diameter , height and vertices | Function to construct the tree.
Special case when d == 2 , only one edge.
Tree is not possible.
Satisfy the height condition by add edges up to h.
Add d - h edges from 1 to satisfy diameter condition.
Remaining edges at vertex 1 or 2 ( d == h ).
Driver Code"
Solution in Python:
assistant
#Here is code to possible edges of a tree for given diameter , height and vertices and the other steps required.
 def constructTree ( n , d , h ) :
	if d == 1 :
		if n == 2 and h == 1 :
			print ( "1 ▁ 2" )
			return 0
		print ( " - 1" )
		return 0
	if d > 2 * h :
		print ( " - 1" )
		return 0
	for i in range ( 1 , h + 1 ) :
		print ( i , " ▁ " , i + 1 )
	if d > h :
		print ( 1 , " ▁ " , h + 2 )
		for i in range ( h + 2 , d + 1 ) :
			print ( i , " ▁ " , i + 1 )
	for i in range ( d + 1 , n ) :
		k = 1
		if d == h :
			k = 2
		print ( k , " ▁ " , i + 1 )
n = 5
d = 3
h = 2
constructTree ( n , d , h )