human
Can you provide a code to combinatorics on ordered trees and the other steps required given the following:
Combinatorics on ordered trees | Function returns value of Binomial Coefficient C ( n , k ).
Calculate value of Binomial Coefficient in bottom up manner.
Base Cases.
Calculate value using previously stored values.
Function to calculate the number of trees with exactly k leaves ..
Function to calculate total number of Nodes of degree d in these trees ..
Function to calculate the number of trees in which the root has degree r ..
Driver code.
Number of trees having 3 edges and exactly 2 leaves.
Number of Nodes of degree 3 in a tree having 4 edges.
Number of trees having 3 edges where root has degree 2"
Solution in Python:
assistant
#Here is code to combinatorics on ordered trees and the other steps required.
 def binomialCoeff ( n , k ) :
	C = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]
	for i in range ( n + 1 ) :
		for j in range ( min ( i , k ) + 1 ) :
			if ( j == 0 or j == i ) :
				C [ i ] [ j ] = 1
			else :
				C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )
	return C [ n ] [ k ]
def k_Leaves ( n , k ) :
	ans = ( ( binomialCoeff ( n , k ) * binomialCoeff ( n , k - 1 ) ) // n )
	print ( " Number ▁ of ▁ trees ▁ " , " having ▁ 4 ▁ edges ▁ and ▁ exactly ▁ 2 ▁ " , " leaves ▁ : ▁ " , ans )
def numberOfNodes ( n , d ) :
	ans = binomialCoeff ( 2 * n - 1 - d , n - 1 )
	print ( " Number ▁ of ▁ Nodes ▁ " , " of ▁ degree ▁ 1 ▁ in ▁ a ▁ tree ▁ having ▁ 4 ▁ " , " edges ▁ : ▁ " , ans )
def rootDegreeR ( n , r ) :
	ans = r * binomialCoeff ( 2 * n - 1 - r , n - 1 )
	ans = ans // n
	print ( " Number ▁ of ▁ trees ▁ " , " having ▁ 4 ▁ edges ▁ where ▁ root ▁ has ▁ " , " degree ▁ 2 ▁ : ▁ " , ans )
if __name__ == ' _ _ main _ _ ' :
	k_Leaves ( 3 , 2 )
	numberOfNodes ( 3 , 1 )
	rootDegreeR ( 3 , 2 )