Mean of minimum of all possible K | Function to find the value of nCr ; Base Case ; Find nCr recursively ; Function to find the expected minimum values of all the subsets of size K ; Find the factorials that will be used later ; Find the factorials ; Total number of subsets ; Stores the sum of minimum over all possible subsets ; Iterate over all possible minimum ; Find the mean over all subsets ; Driver Code
def nCr ( n , r , f ) : NEW_LINE INDENT if ( n < r ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT return f [ n ] / ( f [ r ] * f [ n - r ] ) NEW_LINE DEDENT def findMean ( N , X ) : NEW_LINE INDENT f = [ 0 for i in range ( N + 1 ) ] NEW_LINE f [ 0 ] = 1 NEW_LINE for i in range ( 1 , N + 1 , 1 ) : NEW_LINE INDENT f [ i ] = f [ i - 1 ] * i NEW_LINE DEDENT total = nCr ( N , X , f ) NEW_LINE count = 0 NEW_LINE for i in range ( 1 , N + 1 , 1 ) : NEW_LINE INDENT count += nCr ( N - i , X - 1 , f ) * i NEW_LINE DEDENT E_X = ( count ) / ( total ) NEW_LINE print ( " { 0 : . 9f } " . format ( E_X ) ) NEW_LINE return 0 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 3 NEW_LINE X = 2 NEW_LINE findMean ( N , X ) NEW_LINE DEDENT