Central binomial coefficient - GeeksforGeeks

28 Jun, 2021
Given an integer N, the task is to find the Central binomial coefficient. The first few Central binomial coefficients for N = 0, 1, 2, 3... are  
1, 2, 6, 20, 70, 252, 924, 3432.....
Examples:  
Input: N = 3 Output: 20 Explanation: Central Binomial Coefficient = = = = 20Input: N = 2 Output: 6  
 
Approach: The central binomial coefficient is a binomial coefficient of the form . The Binomial Coefficient can be computed using this approach for a given value N using Dynamic Programming.For Example:  
Central binomial coefficient of N = 3 is given by: = = = 20  
Below is the implementation of the above approach: 
C++
Java
Python3
C#
Javascript
// C++ implementation to find the// Nth Central Binomial Coefficient #include<bits/stdc++.h>using namespace std; // Function to find the value of// Nth Central Binomial Coefficientint binomialCoeff(int n, int k){    int C[n + 1][k + 1];    int i, j;     // 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];} // Driver Codeint main(){    int n = 3;    int k = n;    n = 2*n;    cout << binomialCoeff(n, k);}
// Java implementation to find the// Nth Central Binomial Coefficientclass GFG{     // Function to find the value of// Nth Central Binomial Coefficientstatic int binomialCoeff(int n, int k){    int[][] C = new int[n + 1][k + 1];    int i, j;     // Calculate value of Binomial    // Coefficient in bottom up manner    for(i = 0; i <= n; i++)    {       for(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];} // Driver Codepublic static void main(String[] args){    int n = 3;    int k = n;    n = 2 * n;         System.out.println(binomialCoeff(n, k));}} // This code is contributed by Ritik Bansal
# C# implementation to find the# Nth Central Binomial Coefficient # Function to find the value of# Nth Central Binomial Coefficientdef binomialCoeff(n, k):         C = [[0 for j in range(k + 1)]            for i in range(n + 1)]         i = 0    j = 0         # 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]     # Driver codeif __name__=='__main__':         n = 3    k = n    n = 2 * n         print(binomialCoeff(n, k))         # This code is contributed by rutvik_56
// C# implementation to find the// Nth Central Binomial Coefficientusing System;class GFG{     // Function to find the value of// Nth Central Binomial Coefficientstatic int binomialCoeff(int n, int k){    int [,]C = new int[n + 1, k + 1];    int i, j;     // Calculate value of Binomial    // Coefficient in bottom up manner    for(i = 0; i <= n; i++)    {       for(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];} // Driver Codepublic static void Main(){    int n = 3;    int k = n;    n = 2 * n;         Console.Write(binomialCoeff(n, k));}} // This code is contributed by Code_Mech
<script> // Javascript implementation to find the// Nth Central Binomial Coefficient // Function to find the value of// Nth Central Binomial Coefficientfunction binomialCoeff(n, k){    var C = Array.from(Array(n+1),()=> Array(k+1));    var i, j;     // Calculate value of Binomial    // Coefficient in bottom up manner    for (i = 0; i <= n; i++)    {        for (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];} // Driver Codevar n = 3;var k = n;n = 2*n;document.write( binomialCoeff(n, k));  </script>
20
 
Time Complexity: O(N * K)Auxiliary Space: O(N * K)
bansal_rtk_
Code_Mech
nidhi_biet
rutvik_56
itsok
subhammahato348
binomial coefficient
series
Mathematical
Mathematical
series
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Program to print prime numbers from 1 to N.
Modular multiplicative inverse
Fizz Buzz Implementation
Check if a number is Palindrome
Segment Tree | Set 1 (Sum of given range)
Generate all permutation of a set in Python
How to check if a given point lies inside or outside a polygon?
Merge two sorted arrays with O(1) extra space
Singular Value Decomposition (SVD)
Program to multiply two matrices