The Wayback Machine - https://web.archive.org/web/20240804090141/https://www.geeksforgeeks.org/meanings-and-objectives-of-tabulation/
Open In App

Meanings and objectives of Tabulation

Last Updated : 26 Dec, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

Tabulation is a fundamental concept in Dynamic programming (DP), which entails dividing a problem into smaller subproblems and an array to hold the outcomes of these subproblems.

What is Tabulation?

One of the two primary methodologies in dynamic programming is tabulation, and memoization serves as the other. Tabulation creates a table (often an array) and fills it up one row at a time. It begins with resolving the smallest subproblems first and builds up towards larger subproblems using those answers until the main problem is resolved.

  • A bottom-up strategy in dynamic programming is tabulation.
  • The outcomes of the subproblems are kept in a table, which is often an array.
  • Comparing tabulation to memoization in terms of time complexity, tabulation is often more effective.

Steps to Implement Tabulation:

Tabulation follows these steps:

  • Determine the factors that need to be optimized and clearly identify the issue you’re trying to solve.
  • Make a table to hold the outcomes of the subproblems (often an array). The problem determines the table’s size.
  • Create base cases or initial values for the Table. These numbers stand in for the answers to the smallest subproblems.
  • Fill in the table from the smallest subproblems to the largest using iteration (usually loops). Based on previously calculated subproblems, determine the solutions to each subproblem.
  • Once the table is fully filled, the final result is usually found in the last entry of the table.

Let’s take an example: Fibonacci Sequence

Follow the steps to solve the problem using Dynamic Programming(tabulation):

  • Find the nth Fibonacci number.
  • Create an array fib to store intermediate Fibonacci numbers.
  • Initialize the Table: fib[0] = 0 fib[1] = 1
  • Use a loop to calculate fib[i] = fib[i-1] + fib[i-2] for i from 2 to n.
  • The nth Fibonacci number is fib[n].

Below is the implementation of the above idea:

C++




#include <iostream>
#include <vector>
 
int fibonacci_tabulation(int n) {
    // Create a vector to store Fibonacci numbers
    std::vector<int> fib(n + 1, 0);
 
    // Base cases
    // Smallest subproblems
    fib[0] = 0;
    fib[1] = 1;
 
    // Fill in the vector using tabulation
    // Filling the rest of the vector from
    // smaller subproblems
    for (int i = 2; i <= n; i++) {
        fib[i] = fib[i - 1] + fib[i - 2];
    }
 
    // Return the nth Fibonacci number
    return fib[n];
}
 
int main() {
    int n = 10;
    int result = fibonacci_tabulation(n);
    std::cout << result << std::endl;
    return 0;
}


Java




public class Main {
    // Function to calculate the nth Fibonacci number using tabulation
    public static int fibonacciTabulation(int n) {
        // Create an array to store Fibonacci numbers
        int[] fib = new int[n + 1];
 
        // Base cases (smallest subproblems)
        fib[0] = 0;
        fib[1] = 1;
 
        // Fill in the array using tabulation
        // Filling the rest of the array from smaller subproblems
        for (int i = 2; i <= n; i++) {
            fib[i] = fib[i - 1] + fib[i - 2];
        }
 
        // Return the nth Fibonacci number
        return fib[n];
    }
 
    public static void main(String[] args) {
        int n = 10;
        int result = fibonacciTabulation(n);
 
        System.out.println(result);
    }
}


Python




def fibonacci_tabulation(n):
    # Create an array to store Fibonacci numbers
    fib = [0] * (n + 1)
 
    # Base cases
    # Smallest subproblems
    fib[0] = 0
    fib[1] = 1
 
    # Fill in the table using tabulation
    # Filling the rest of the table from
    # smaller subproblems
     
    for i in range(2, n + 1):
        fib[i] = fib[i - 1] + fib[i - 2]
 
    # Return the nth Fibonacci number
    return fib[n]
 
# Driver Code
n = 10
result = fibonacci_tabulation(n)
print(result)


C#




using System;
 
class Program
{
    static int FibonacciTabulation(int n)
    {
        // Create an array to store Fibonacci numbers
        int[] fib = new int[n + 1];
 
        // Base cases
        // Smallest subproblems
        fib[0] = 0;
        fib[1] = 1;
 
        // Fill in the array using tabulation
        // Filling the rest of the array from
        // smaller subproblems
        for (int i = 2; i <= n; i++)
        {
            fib[i] = fib[i - 1] + fib[i - 2];
        }
 
        // Return the nth Fibonacci number
        return fib[n];
    }
 
    static void Main()
    {
        int n = 10;
        int result = FibonacciTabulation(n);
        Console.WriteLine(result);
    }
}


Javascript




// Function to calculate the nth Fibonacci number using tabulation
function fibonacciTabulation(n) {
    // Create an array to store Fibonacci numbers
    let fib = new Array(n + 1);
 
    // Base cases (smallest subproblems)
    fib[0] = 0;
    fib[1] = 1;
 
    // Fill in the array using tabulation
    // Filling the rest of the array from smaller subproblems
    for (let i = 2; i <= n; i++) {
        fib[i] = fib[i - 1] + fib[i - 2];
    }
 
    // Return the nth Fibonacci number
    return fib[n];
}
 
// Main function
function main() {
    let n = 10;
    let result = fibonacciTabulation(n);
 
    console.log(result);
}
 
// Calling the main function
main();


Output

55




Conclusion:

Tabulation is a powerful technique in dynamic programming for solving complex problems efficiently by storing subproblems results in array.



Similar Reads

Tabulation vs Memoization
Tabulation and memoization are two techniques used in dynamic programming to optimize the execution of a function that has repeated and expensive computations. Although both techniques have similar goals, there are some differences between them. Memoization is a top-down approach where we cache the results of function calls and return the cached re
10 min read
Bookkeeping | Types, Importance and Objectives
What is Bookkeeping?Bookkeeping is defined as a process of recording and maintaining the financial transactions of the company on a daily basis. The transactions consist of sales, payments, receipts and purchases, revenue, operational expenses, investments, etc. These details are added into chronological order while maintaining the records. The pro
4 min read
Local Area Banks | Full Form of LAB, Features, Objectives and Functions
Local Area Banks are such banks that are set up for a small area and operate in that area. Local Area Banks function just like the other big banks, which means completing the financial requirements, for example, storing money, lending money, withdrawing money, etc., of the area that's provided to each Local Area Bank. Local Area Banks are also refe
5 min read
PRASAD Scheme : Objectives, Selection Criteria and Functioning
PRASAD Scheme is an acronym that stands for Pilgrimage Rejuvenation And Spirituality Augmentation Drive. This scheme was started by the Government of India under the Ministry of Tourism in the year 2014-2015. In October 2017, the name of this scheme was changed to National Mission on Pilgrimage Rejuvenation and Spiritual Heritage Augmentation Drive
5 min read
Gram Panchayat Expenditure - Objectives and Role of State Audit Department
In India, the State Audit Department normally examines the Gram Panchayat's accounts for expenses. The audit procedure is carried out to guarantee accountability, transparency, and proper use of the funds given to the Gram Panchayat. To guarantee that funds are being used for their intended goals and to check for compliance with financial regulatio
5 min read
ECS: Full Form, Objectives, Types, Merits and Demerits
What is ECS? ECS is defined as an electronic means for the transfer of funds introduced by the Reserve Bank of India to reduce the transit time of funds mobilisation so that repetitive and recurring payments can be processed easily and electronically without any manual intervention. This payment mode also ensures that paper transactions are minimis
9 min read
NACH : Full Form, Features, Objectives and Benefits
What is NACH?NACH is defined as a centralised system that enables the automated clearing of high-volume electronic transactions, like pensions, subsidies, or any other kind of reimbursement coming from the side of the government. NACH system was developed to standardise and synergise the interface of all electronic transactions with the compliances
9 min read
NBFC : Full Form, Role, Objectives, Functions and Examples
What are NBFCs?NBFCs are financial institutions that offer various financial services similar to traditional banks, but they operate without a banking license. Unlike banks, NBFCs cannot accept demand deposits, but they can provide loans and advances, asset financing, wealth management, and other financial products. A Non-Banking Financial Company
12 min read
OECD | Full Form, Objectives, Organisational Structure and Functions
What is OECD?OECD serves as a platform for government to collaborate on economic, social, and environmental policies. OECD is an important international organisation founded in 1961. OECD comprises 38 member countries from around the globe. The core mission of the OECD is to promote policies that improve the well-being and living standards of peopl
6 min read
e-National Agriculture Market (eNAM) - Mission, Objectives and Benefits
e-NAM is a government initiative taken up by our prime minister Shri Narendra Modi &amp; was founded on 14 April 2016. It is an online trading platform that induces transparency in the process of buying &amp; selling agricultural goods where the farmers and traders benefit from extra profits as compared to the previous methods. According to the lat
9 min read
three90RightbarBannerImg