Fibonomial coefficient and Fibonomial triangle


In this article, we will discuss about a special type of number called fibonomial coefficient and how does a fibonomial triangle looks like. We will also discuss the C++ code approach to print a fibonomial triangle with a given height.

Let us first discuss that what is a fibonomial coefficient.

Fibonomial Coefficient

We can call a fibonomial coefficient a generalisation of well known terms namely , Fibonacci numbers and binomial coefficients.

The Fibonacci numbers are a series of numbers in which, each number is the sum of the two preceding numbers (for example − 0, 1, 1, 2, 3, 5, 8, 13, 21)

Binomial coefficients, on the other hand, arise from the binomial theorem and represent the coefficients in the expansion of binomial expressions (e.g., (a + b)^n).

Combining these two concepts, a fibonomial coefficient could refer to a coefficient in an expansion related to both Fibonacci numbers and binomial coefficients.

In simpler terms, the Fibonomial coefficient is a way to count the number of ways \on which we can select k different elements from a set of n distinct elements, where each element has a weight based on its position in the Fibonacci sequence.

Here's an example to illustrate it better −

Let's say we have a sequence of 5 different numbers namely {A, B, C, D, E}. We want to choose 3 elements from this set, considering their order, and assign weights to each element based on the Fibonacci sequence. The Fibonomial coefficient will tell us the number of possible ways to do this.

First, we find the Fibonacci numbers at the corresponding positions −

F(5) = 5
F(3) = 2
F(2) = 1

Next, we use the formula for the Fibonomial coefficient: F(n, k) = F(n) / (F(k) * F(n−k)) Plugging in the values −

F(5, 3) = F(5) / (F(3) * F(5-3))
= 5 / (2 * 1)
= 5 / 2
= 2.5

So, there are 2.5 possible ways to choose 3 elements from the set {A, B, C, D, E}, considering their order, and assigning Fibonacci−based weights to each element.

Fibonomial Triangle

Now let us discuss about fibonomial triangle and how it is formed.

In the context of the Fibonomial triangle, the Fibonomial coefficients combine Fibonacci numbers and binomial coefficients. Each entry in the triangle represents a coefficient that arises from the expansion of a Fibonomial expression, which combines Fibonacci numbers and binomial coefficients.

The Fibonomial triangle is a triangular arrangement of numbers that represents the Fibonomial coefficients. Similar to how Pascal's triangle represents binomial coefficients, the Fibonomial triangle displays the Fibonomial coefficients for different values of n and k.

To construct the Fibonomial triangle, we calculated each numbers in the triangle using the Fibonomial coefficient formula: F(n, k) = F(n) / (F(k) * F(n−k)). The Fibonomial coefficient for a specific position (n, k) in the triangle is obtained by dividing the n−th Fibonacci number by the product of the k−th and (n−k)−th Fibonacci numbers.

The Fibonomial triangle shares similarities with Pascal's triangle in terms of its arrangement and how the coefficients are calculated, but instead of binomial coefficients, it showcases Fibonomial coefficients.

Here's an example of the Fibonomial triangle −

                    1
                 1     1
              1     2     1
           1     3     3     1
        1     5     6     5     1
     1     8    11    11    8      1

In this triangle, each number represents a Fibonomial coefficient, combining the properties of both Fibonacci numbers and binomial coefficients.

Problem Statement

We are given a task to generate the fibonomial triangle using C++.

Example

Following is the implementation of the above approach in different programming languages: C, C++, Java, and Python −

#include<stdlib.h>
#include<stdio.h>
#define number 6
void fib(int number_fib[], int n)
{
   number_fib[0] = 0;
   number_fib[1] = 1;
   for (int iterator = 2; iterator <= n; iterator++)
      number_fib[iterator] = number_fib[iterator - 1] + number_fib[iterator - 2];
}
void fibonomialCoeff(int fib_coeff[][number + 1], int number_fib[], int n){
   for (int iterator = 0; iterator <= n; iterator++)
      fib_coeff[iterator][0] = 1;
   for (int iterator = 1; iterator <= n; iterator++) {
      for (int j = 1; j <= iterator; j++) {
         int k = j;
         while (k--)
            fib_coeff[iterator][j] *= number_fib[k];
         k = 1;
         while ((j + 1) != k)
            fib_coeff[iterator][j] /= number_fib[k++];
      }
   }
}
void printFibonomialTriangle(int n){
   int j = 0;
   int iterator = 0;
   int number_fib[number + 1] = { 0 };
   fib(number_fib, n);
   int fib_coeff[number + 1][number + 1] = { 0 };
   for (iterator = 0; iterator <= n; iterator++)
      fib_coeff[iterator][0] = fib_coeff[iterator][iterator] = 1;
   for (iterator = 1; iterator <= n; iterator++) {
      for (j = 1; j < iterator; j++)
         fib_coeff[iterator][j] = number_fib[iterator - j + 1] * fib_coeff[iterator - 1][j - 1] + number_fib[j - 1] * fib_coeff[iterator - 1][j];
   }
   for (iterator = 0; iterator <= n; iterator++) {
      for (j = 0; j <= iterator; j++)
         printf("%d ", fib_coeff[iterator][j]);
      printf("\n");
   }
}
int main(){
   printf("The Fibonomial triangle of height = 6 is given here \n");
   printFibonomialTriangle(number);
   return 0;
}

Output

The Fibonomial triangle of height = 6 is given here 
1 
1 1 
1 1 1 
1 2 2 1 
1 3 6 3 1 
1 5 15 15 5 1 
1 8 40 60 40 8 1 
#include<bits/stdc++.h>
using namespace std;
#define number 6

void fib(int number_fib[], int n){
   number_fib[0] = 0;
   number_fib[1] = 1;
   for (int iterator = 2; iterator <= n; iterator++)
   number_fib[iterator] = number_fib[iterator - 1] + number_fib[iterator - 2];
}
void fibonomialCoeff(int fib_coeff[][number + 1], int number_fib[], int n){
   for (int iterator = 0; iterator <= n; iterator++)
   fib_coeff[iterator][0] = 1;
   for (int iterator = 1; iterator <= n; iterator++) {
      for (int j = 1; j <= iterator; j++) {
         int k = j;
         while (k--)
         fib_coeff[iterator][j] *= number_fib[k];
         k = 1;
         while ((j + 1) != k)
         fib_coeff[iterator][j] /= number_fib[k++];
      }
   }
}
void printFibonomialTriangle(int n){
   int j = 0;
   int iterator = 0;
   int number_fib[number + 1] = { 0 };
   fib(number_fib, n);
   int fib_coeff[number + 1][number + 1] = { 0 };
   for (iterator = 0; iterator <= n; iterator++)
   fib_coeff[iterator][0] = fib_coeff[iterator][iterator] = 1;
   for (iterator = 1; iterator <= n; iterator++) {
      for (j = 1; j < iterator; j++)
         fib_coeff[iterator][j] = number_fib[iterator - j + 1] * fib_coeff[iterator - 1][j - 1] + number_fib[j - 1] * fib_coeff[iterator - 1][j];
   }
   for (iterator = 0; iterator <= n; iterator++) {
      for (j = 0; j <= iterator; j++)
         cout << fib_coeff[iterator][j] << " ";
      cout << endl;
   }
}
int main(){
   cout << "The Fibonomial triangle of height = 6 is given here" << endl;
   printFibonomialTriangle(number);
   return 0;
}

Output

The Fibonomial triangle of height = 6 is given here
1 
1 1 
1 1 1 
1 2 2  1 
1 3 6  3  1 
1 5 15 15 5  1 
1 8 40 60 40 8 1
public class Main {
   static final int number = 6;

   static void fib(int[] number_fib, int n) {
      number_fib[0] = 0;
      number_fib[1] = 1;
      for (int iterator = 2; iterator <= n; iterator++)
         number_fib[iterator] = number_fib[iterator - 1] + number_fib[iterator - 2];
   }

   static void fibonomialCoeff(int[][] fib_coeff, int[] number_fib, int n) {
      for (int iterator = 0; iterator <= n; iterator++)
         fib_coeff[iterator][0] = 1;
      for (int iterator = 1; iterator <= n; iterator++) {
         for (int j = 1; j <= iterator; j++) {
            int k = j;
            while (k-- > 0)
               fib_coeff[iterator][j] *= number_fib[k];
            k = 1;
            while ((j + 1) != k)
               fib_coeff[iterator][j] /= number_fib[k++];
         }
      }
   }

   static void printFibonomialTriangle(int n) {
      int j = 0;
      int iterator = 0;
      int[] number_fib = new int[number + 1];
      fib(number_fib, n);
      int[][] fib_coeff = new int[number + 1][number + 1];
      for (iterator = 0; iterator <= n; iterator++)
         fib_coeff[iterator][0] = fib_coeff[iterator][iterator] = 1;
      for (iterator = 1; iterator <= n; iterator++) {
         for (j = 1; j < iterator; j++)
            fib_coeff[iterator][j] = number_fib[iterator - j + 1] * fib_coeff[iterator - 1][j - 1] + number_fib[j - 1] * fib_coeff[iterator - 1][j];
      }
      for (iterator = 0; iterator <= n; iterator++) {
         for (j = 0; j <= iterator; j++)
            System.out.print(fib_coeff[iterator][j] + " ");
         System.out.println();
      }
   }
   public static void main(String[] args) {
      System.out.println("The Fibonomial triangle of height = 6 is given here ");
      printFibonomialTriangle(number);
   }
}

Output

The Fibonomial triangle of height = 6 is given here 
1 
1 1 
1 1 1 
1 2 2 1 
1 3 6 3 1 
1 5 15 15 5 1 
1 8 40 60 40 8 1 
def fib(number_fib, n):
   number_fib[0] = 0
   number_fib[1] = 1
   for iterator in range(2, n + 1):
      number_fib[iterator] = number_fib[iterator - 1] + number_fib[iterator - 2]

def fibonomialCoeff(fib_coeff, number_fib, n):
   for iterator in range(n + 1):
      fib_coeff[iterator][0] = 1
   for iterator in range(1, n + 1):
      for j in range(1, iterator + 1):
         k = j
         while k > 0:
            fib_coeff[iterator][j] *= number_fib[k - 1]
            k -= 1
         k = 1
         while j + 1 != k:
            fib_coeff[iterator][j] /= number_fib[k - 1]
            k += 1

def printFibonomialTriangle(n):
   j = 0
   iterator = 0
   number_fib = [0] * (n + 1)  # Fix: Use 'n' instead of 'number'
   fib(number_fib, n)
   fib_coeff = [[0] * (n + 1) for _ in range(n + 1)]  # Fix: Use 'n' instead of 'number'
   for iterator in range(n + 1):
      fib_coeff[iterator][0] = fib_coeff[iterator][iterator] = 1
   for iterator in range(1, n + 1):
      for j in range(1, iterator):
         fib_coeff[iterator][j] = number_fib[iterator - j] * fib_coeff[iterator - 1][j - 1] + number_fib[j - 1] * fib_coeff[iterator - 1][j]
   for iterator in range(n + 1):
      for j in range(iterator + 1):
         print(fib_coeff[iterator][j], end=" ")
      print()

if __name__ == "__main__":
   number = 6  # Define 'number' here
   print("The Fibonomial triangle of height = 6 is given here ")
   printFibonomialTriangle(number)

Output

The Fibonomial triangle of height = 6 is given here 
1 
1 1 
1 1 1 
1 1 2 1 
1 2 3 3 1 
1 3 7 6 5 1 
1 5 16 20 16 8 1  

Complexities − The time ad space complexity both of the code written above is O (n^2).

Conclusion

In this article we learnt about fibonomial coefficients and fibonomial triangle and at last we generated the code to generate the fibonomial triangle in C++.

Updated on: 09-Feb-2024

49 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements