Given a positive integer n. The task is to find the maximum coefficient term in all binomial coefficient.
The binomial coefficient series is
nC0, nC1, nC2, …., nCr, …., nCn-2, nCn-1, nCn
the task is to find maximum value of nCr.
Examples:
Input : n = 4 Output : 6 4C0 = 1 4C1 = 4 4C2 = 6 4C3 = 1 4C4 = 1 So, maximum coefficient value is 6. Input : n = 3 Output : 3
Method 1: (Brute Force)
The idea is to find all the value of binomial coefficient series and find the maximum value in the series.
Below is the implementation of this approach:
C++
// CPP Program to find maximum binomial coefficient // term #include<bits/stdc++.h> using namespace std; // Return maximum binomial coefficient term value. int maxcoefficientvalue(int n) { int C[n+1][n+1]; // Calculate value of Binomial Coefficient in // bottom up manner for (int i = 0; i <= n; i++) { for (int j = 0; j <= min(i, n); j++) { // Base Cases if (j == 0 || j == i) C[i][j] = 1; // Calculate value using previously // stored values else C[i][j] = C[i-1][j-1] + C[i-1][j]; } } // finding the maximum value. int maxvalue = 0; for (int i = 0; i <= n; i++) maxvalue = max(maxvalue, C[n][i]); return maxvalue; } // Driven Program int main() { int n = 4; cout << maxcoefficientvalue(n) << endl; return 0; } |
Java
// Java Program to find // maximum binomial // coefficient term import java.io.*; class GFG { // Return maximum binomial // coefficient term value. static int maxcoefficientvalue(int n) { int [][]C = new int[n + 1][n + 1]; // Calculate value of // Binomial Coefficient // in bottom up manner for (int i = 0; i <= n; i++) { for (int j = 0; j <= Math.min(i, n); j++) { // Base Cases if (j == 0 || j == i) C[i][j] = 1; // Calculate value // using previously // stored values else C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; } } // finding the // maximum value. int maxvalue = 0; for (int i = 0; i <= n; i++) maxvalue = Math.max(maxvalue, C[n][i]); return maxvalue; } // Driver Code public static void main (String[] args) { int n = 4; System.out.println(maxcoefficientvalue(n)); } } // This code is contributed by ajit |
Python3
# Python3 Program to find # maximum binomial # coefficient term # Return maximum binomial # coefficient term value. def maxcoefficientvalue(n): C = [[0 for x in range(n + 1)] for y in range(n + 1)]; # Calculate value of # Binomial Coefficient in # bottom up manner for i in range(n + 1): for j in range(min(i, n) + 1): # Base Cases if (j == 0 or j == i): C[i][j] = 1; # Calculate value # using previously # stored values else: C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]); # finding the maximum value. maxvalue = 0; for i in range(n + 1): maxvalue = max(maxvalue, C[n][i]); return maxvalue; # Driver Code n = 4; print(maxcoefficientvalue(n)); # This code is contributed by mits |
C#
// C# Program to find maximum binomial coefficient // term using System; public class GFG { // Return maximum binomial coefficient term value. static int maxcoefficientvalue(int n) { int [,]C = new int[n+1,n+1]; // Calculate value of Binomial Coefficient in // bottom up manner for (int i = 0; i <= n; i++) { for (int j = 0; j <= Math.Min(i, n); j++) { // Base Cases if (j == 0 || j == i) C[i,j] = 1; // Calculate value using previously // stored values else C[i,j] = C[i-1,j-1] + C[i-1,j]; } } // finding the maximum value. int maxvalue = 0; for (int i = 0; i <= n; i++) maxvalue = Math.Max(maxvalue, C[n,i]); return maxvalue; } // Driven Program static public void Main () { int n = 4; Console.WriteLine(maxcoefficientvalue(n)); } } // This code is contributed by vt_m. |
PHP
<?php // PHP Program to find // maximum binomial // coefficient term // Return maximum binomial // coefficient term value. function maxcoefficientvalue($n) { // Calculate value of // Binomial Coefficient in // bottom up manner for ($i = 0; $i <= $n; $i++) { for ($j = 0; $j <= min($i, $n); $j++) { // Base Cases if ($j == 0 || $j == $i) $C[$i][$j] = 1; // Calculate value // using previously // stored values else $C[$i][$j] = $C[$i - 1][$j - 1] + $C[$i - 1][$j]; } } // finding the maximum value. $maxvalue = 0; for ($i = 0; $i <= $n; $i++) $maxvalue = max($maxvalue, $C[$n][$i]); return $maxvalue; } // Driver Code $n = 4; echo maxcoefficientvalue($n), "\n"; // This code is contributed by aj_36 ?> |
Output:
6
Method 2: (Using formula)

Proof,
Expansion of (x + y)n are:
nC0 xn y0, nC1 xn-1 y1, nC2 xn-2 y2, …., nCr xn-r yr, …., nCn-2 x2 yn-2, nCn-1 x1 yn-1, nCn x0 ynSo, putting x = 1 and y = 1, we get binomial coefficient,
nC0, nC1, nC2, …., nCr, …., nCn-2, nCn-1, nCnLet term ti+1 contains the greatest value in (x + y)n. Therefore,
tr+1 >= tr
nCr xn-r yr >= nCr-1 xn-r+1 yr-1Putting x = 1 and y = 1,
nCr >= nCr-1
nCr/nCr-1 >= 1
(using nCr/nCr-1 = (n-r+1)/r)
(n-r+1)/r >= 1
(n+1)/r – 1 >= 1
(n+1)/r >= 2
(n+1)/2 >= rTherefore, r should be less than equal to (n+1)/2.
And r should be integer. So, we get maximum coefficient for r equals to:
(1) n/2, when n is even.
(2) (n+1)/2 or (n-1)/2, when n is odd.
C++
// CPP Program to find maximum binomial coefficient term #include<bits/stdc++.h> using namespace std; // Returns value of Binomial Coefficient C(n, k) int binomialCoeff(int n, int k) { int C[n+1][k+1]; // Calculate value of Binomial Coefficient // in bottom up manner for (int i = 0; i <= n; i++) { for (int j = 0; j <= min(i, k); j++) { // Base Cases if (j == 0 || j == i) C[i][j] = 1; // Calculate value using previously // stored values else C[i][j] = C[i-1][j-1] + C[i-1][j]; } } return C[n][k]; } // Return maximum binomial coefficient term value. int maxcoefficientvalue(int n) { // if n is even if (n%2 == 0) return binomialCoeff(n, n/2); // if n is odd else return binomialCoeff(n, (n+1)/2); } // Driven Program int main() { int n = 4; cout << maxcoefficientvalue(n) << endl; return 0; } |
Java
// Java Program to find // maximum binomial // coefficient term import java.io.*; class GFG { // Returns value of // Binomial Coefficient // C(n, k) static int binomialCoeff(int n, int k) { int [][]C = new int[n + 1][k + 1]; // Calculate value of // Binomial Coefficient // in bottom up manner for (int i = 0; i <= n; i++) { for (int j = 0; j <= Math.min(i, k); j++) { // Base Cases if (j == 0 || j == i) C[i][j] = 1; // Calculate value using // previously stored values else C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; } } return C[n][k]; } // Return maximum // binomial coefficient // term value. static int maxcoefficientvalue(int n) { // if n is even if (n % 2 == 0) return binomialCoeff(n, n / 2); // if n is odd else return binomialCoeff(n, (n + 1) / 2); } // Driver Code public static void main(String[] args) { int n = 4; System.out.println(maxcoefficientvalue(n)); } } // This code is contributed // by akt_mit |
Python3
# Python3 Program to find # maximum binomial # coefficient term # Returns value of # Binomial Coefficient C(n, k) def binomialCoeff(n, k): C=[[0 for x in range(k+1)] for y in range(n+1)] # Calculate value of # Binomial Coefficient # in bottom up manner for i in range(n+1): for j in range(min(i,k)+1): # Base Cases if (j == 0 or j == i): C[i][j] = 1; # Calculate value # using previously # stored values else: C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; return C[n][k]; # Return maximum binomial # coefficient term value. def maxcoefficientvalue(n): # if n is even if (n % 2 == 0): return binomialCoeff(n, int(n / 2)); # if n is odd else: return binomialCoeff(n, int((n + 1) / 2)); # Driver Code if __name__=='__main__': n = 4; print(maxcoefficientvalue(n)); # This code is contributed by mits |
C#
// C# Program to find maximum binomial // coefficient term using System; public class GFG { // Returns value of Binomial Coefficient // C(n, k) static int binomialCoeff(int n, int k) { int [,]C = new int[n+1,k+1]; // Calculate value of Binomial // Coefficient in bottom up manner for (int i = 0; i <= n; i++) { for (int j = 0; j <= Math.Min(i, k); j++) { // Base Cases if (j == 0 || j == i) C[i,j] = 1; // Calculate value using // previously stored values else C[i,j] = C[i-1,j-1] + C[i-1,j]; } } return C[n,k]; } // Return maximum binomial coefficient // term value. static int maxcoefficientvalue(int n) { // if n is even if (n % 2 == 0) return binomialCoeff(n, n/2); // if n is odd else return binomialCoeff(n, (n + 1) / 2); } // Driven Program static public void Main () { int n = 4; Console.WriteLine(maxcoefficientvalue(n)); } } // This code is contributed by vt_m. |
PHP
<?php // PHP Program to find // maximum binomial // coefficient term // Returns value of // Binomial Coefficient C(n, k) function binomialCoeff($n, $k) { $C[$n + 1][$k + 1] = array(0); // Calculate value of // Binomial Coefficient // in bottom up manner for ($i = 0; $i <= $n; $i++) { for ($j = 0; $j <= min($i, $k); $j++) { // Base Cases if ($j == 0 || $j == $i) $C[$i][$j] = 1; // Calculate value // using previously // stored values else $C[$i][$j] = $C[$i - 1][$j - 1] + $C[$i - 1][$j]; } } return $C[$n][$k]; } // Return maximum binomial // coefficient term value. function maxcoefficientvalue($n) { // if n is even if ($n % 2 == 0) return binomialCoeff($n, $n / 2); // if n is odd else return binomialCoeff($n, ($n + 1) / 2); } // Driver Code $n = 4; echo maxcoefficientvalue($n), "\n"; // This code is contributed by m_kit ?> |
Output:
6
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Nth term where K+1th term is product of Kth term with difference of max and min digit of Kth term
- Binomial Coefficient | DP-9
- Space and time efficient Binomial Coefficient
- Sum of product of r and rth Binomial Coefficient (r * nCr)
- Eggs dropping puzzle (Binomial Coefficient and Binary Search Solution)
- Central binomial coefficient
- Middle term in the binomial expansion series
- Replace the maximum element in the array by coefficient of range
- Sum of series till N-th term whose i-th term is i^k - (i-1)^k
- Find the Nth term of the series where each term f[i] = f[i - 1] - f[i - 2]
- Find Nth term of the series where each term differs by 6 and 2 alternately
- Nth term of a sequence formed by sum of current term with product of its largest and smallest digit
- Count sequences of length K having each term divisible by its preceding term
- Clustering Coefficient in Graph Theory
- Program to find correlation coefficient
- Fibonomial coefficient and Fibonomial triangle
- Binomial Random Variables
- Corollaries of Binomial Theorem
- Mathematics | PnC and Binomial Coefficients
- Sum of Binomial coefficients
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

