Assalam.O.Alaikum
DESIGN AND ANALYSIS
OF ALGORITHMS
Dynamic Programing
 Thought first by Richard Bellman in the
1950s,
 Dynamic Programming (DP) is a problem-
solving technique used in computer
science and mathematics to solve
complex larger problems by breaking
them down into simpler, smaller
overlapping subproblems.

Dynamic Programing
The key idea is solving each
subproblem once and storing
the results to avoid redundant
calculations. DP is particularly
useful problem where the solution
can be expressed recursively and
the same subproblem appears multiple times.
When to Use Dynamic Programing?
There are two keys:
 Overlapping Subproblems:
 Dynamic Programming thrives on identifying
 and solving overlapping subproblems.
 These are smaller subproblems within a larger
 problem that are solved independently but
 repeatedly. By solving and storing the results of
 these subproblems, we avoid redundant work
 and speed up the overall solution.

 Optimal Substructure:
 Another crucial concept is the optimal substructure property. It means
that the optimal solution to a larger problem can be generated from the
optimal solutions of its smaller subproblems. This property allows us to
break down complex problems into simpler ones and build the solution
iteratively. Let's say we've figured out the shortest route from City A to City
B, and the shortest route from City B to City C. The shortest route from City
A to City C via City B would be the combination of these two shortest
routes. So, by knowing the optimal solutions (shortest routes) to the
subproblems, we can determine the optimal solution to the original
problem. That's an optimal substructure.
Practical Application:
The Fibonacci Sequence
 To really get a grip on dynamic programming, let's explore a classic
example: The Fibonacci sequence.
 It is a series of numbers in which each number is the sum of the two
preceding ones, usually starting with 0 and 1.
 Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34…and so on.
 Mathematically, we could write each term using the formula:
 F(n) = F(n-1) + F(n-2),
 Let’s look at the diagram for better understanding.
Types of Dynamic Programming
 Dynamic programming is divided into two main approaches:
 top-down (memoization) and bottom-up (tabulation).
 Both of these methods help in solving complex problems
more efficiently by storing and reusing solutions of
overlapping subproblems, but they differ in the way they go
about it.
Types of Dynamic Programming
 Top-Down DP (Memoization)
 In the top-down approach, also known as
memoization, we start with the original problem and
break it down into subproblems. Think of it like
starting at the top of a tree and working your way
down to the leaves.
Types of Dynamic Programming
 Bottom-Up DP (Tabulation):
 The bottom-up approach, also known as tabulation (a
bottom-up approach where complex problems are divided
into simpler sub-problems.)
 That takes the opposite direction. This approach solves
problems by breaking them up into smaller ones, solving the
problem with the smallest mathematical value, and then
working up to the problem with the biggest value.
Types of Dynamic Programming
 Bottom-Up DP (Tabulation):
 . Solutions to its subproblems are compiled in a way
that falls and loops back on itself. Users can opt to
rewrite the problem by initially solving the smaller
subproblems and then carrying those solutions for
solving the larger subproblems
Thank You!
BSCS-E1

Dynamic Programing.pptx good for understanding

  • 1.
  • 2.
    Dynamic Programing  Thoughtfirst by Richard Bellman in the 1950s,  Dynamic Programming (DP) is a problem- solving technique used in computer science and mathematics to solve complex larger problems by breaking them down into simpler, smaller overlapping subproblems. 
  • 3.
    Dynamic Programing The keyidea is solving each subproblem once and storing the results to avoid redundant calculations. DP is particularly useful problem where the solution can be expressed recursively and the same subproblem appears multiple times.
  • 4.
    When to UseDynamic Programing? There are two keys:  Overlapping Subproblems:  Dynamic Programming thrives on identifying  and solving overlapping subproblems.  These are smaller subproblems within a larger  problem that are solved independently but  repeatedly. By solving and storing the results of  these subproblems, we avoid redundant work  and speed up the overall solution. 
  • 5.
     Optimal Substructure: Another crucial concept is the optimal substructure property. It means that the optimal solution to a larger problem can be generated from the optimal solutions of its smaller subproblems. This property allows us to break down complex problems into simpler ones and build the solution iteratively. Let's say we've figured out the shortest route from City A to City B, and the shortest route from City B to City C. The shortest route from City A to City C via City B would be the combination of these two shortest routes. So, by knowing the optimal solutions (shortest routes) to the subproblems, we can determine the optimal solution to the original problem. That's an optimal substructure.
  • 6.
    Practical Application: The FibonacciSequence  To really get a grip on dynamic programming, let's explore a classic example: The Fibonacci sequence.  It is a series of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1.  Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34…and so on.  Mathematically, we could write each term using the formula:  F(n) = F(n-1) + F(n-2),
  • 7.
     Let’s lookat the diagram for better understanding.
  • 8.
    Types of DynamicProgramming  Dynamic programming is divided into two main approaches:  top-down (memoization) and bottom-up (tabulation).  Both of these methods help in solving complex problems more efficiently by storing and reusing solutions of overlapping subproblems, but they differ in the way they go about it.
  • 9.
    Types of DynamicProgramming  Top-Down DP (Memoization)  In the top-down approach, also known as memoization, we start with the original problem and break it down into subproblems. Think of it like starting at the top of a tree and working your way down to the leaves.
  • 10.
    Types of DynamicProgramming  Bottom-Up DP (Tabulation):  The bottom-up approach, also known as tabulation (a bottom-up approach where complex problems are divided into simpler sub-problems.)  That takes the opposite direction. This approach solves problems by breaking them up into smaller ones, solving the problem with the smallest mathematical value, and then working up to the problem with the biggest value.
  • 11.
    Types of DynamicProgramming  Bottom-Up DP (Tabulation):  . Solutions to its subproblems are compiled in a way that falls and loops back on itself. Users can opt to rewrite the problem by initially solving the smaller subproblems and then carrying those solutions for solving the larger subproblems
  • 12.