0% found this document useful (0 votes)
18 views6 pages

ADA Presentation

Dynamic programming is an algorithmic technique that solves complex problems by breaking them down into subproblems. It avoids recomputing the same subproblems repeatedly by storing and looking up the results of already solved subproblems. There are three main approaches to dynamic programming: recursion, memoization, and tabulation. Memoization is a top-down approach where results of subproblems are stored in a table to be reused, avoiding redundant recursive calls. Tabulation is a bottom-up approach where the table is populated incrementally without recursion, by solving subproblems from smallest to largest. The Fibonacci sequence is commonly used to illustrate dynamic programming, with recursive, memoized, and tabulated solutions presented.

Uploaded by

Samriddhi Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views6 pages

ADA Presentation

Dynamic programming is an algorithmic technique that solves complex problems by breaking them down into subproblems. It avoids recomputing the same subproblems repeatedly by storing and looking up the results of already solved subproblems. There are three main approaches to dynamic programming: recursion, memoization, and tabulation. Memoization is a top-down approach where results of subproblems are stored in a table to be reused, avoiding redundant recursive calls. Tabulation is a bottom-up approach where the table is populated incrementally without recursion, by solving subproblems from smallest to largest. The Fibonacci sequence is commonly used to illustrate dynamic programming, with recursive, memoized, and tabulated solutions presented.

Uploaded by

Samriddhi Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DYNAMIC PROGRAMMING

DYNAMIC PROGRAMMING IS AN ALGORITHMIC PARADIGM THAT


SOLVES A GIVEN COMPLEX PROBLEM BY BREAKING IT INTO
SUBPROBLEMS AND STORING THE RESULTS OF SUBPROBLEMS
TO AVOID COMPUTING THE SAME RESULTS AGAIN

Solving a problem– 3 ways:


1. Recursion
2. Memoization
3. Bottom-up
Eg: Fibonacci series
 f(n) = f(n-1) + f(n-2) , where n>=2
f(1) = 1 and f(0) = 0
 f(n) = [0, 1, 1, 2, 3, 5, 8, 13, ….]

 Simple recursion:

int fib (int n)


{
if ( n<= 1)
return n;
return fib(n-1) + fib(n-2);
}
Optimal substructure:
If an optimal solution of the given problem can be obtained by
using optimal solution of its subproblems. Eg: Floyd-Warshall
Recurrence relation:
T(n) = T(n-1) + T(n-1) + O(1)

Time complexity = O(2n)

Solution:
Do not solve the same problem again,
just recall it rom memory.
Overlapping subproblems Two methods:
1. Memoization (Top-Down)
2. Tabulation (Bottom-Up)
Memoized solution
Algo fib(n, memo)
{
if memo[n] != null
return memo[n]
if n<=1
result = n
else
result = fib(n-1) + fib(n-2)
memo[n] = result
null null null null null null
return result
}
Tabulation
Algo fib(n)
{
if n<=1
result = n
int bottom_up[n+1];
bottom_up[0] = 0;
bottom_up[1] = 1;
for i from 2 upto n:
bottom_up[i] = bottom_up[i-1] + bottom_up[i-2] null null null null null null
return bottom_up[n];
}
Thank You

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy