140 likes | 157 Views
This presentation on 'What Is Dynamic Programming?' will acquaint you with a clear understanding of how this programming paradigm works with the help of a real-life example. In this Dynamic Programming Tutorial, you will understand why recursion is not compatible and how you can solve the problems involved in recursion using DP. Finally, we will cover the dynamic programming implementation of the Fibonacci series program. So, let's get started!
E N D
Agenda Problem Statement
Agenda Algorithmic solution
Agenda Implementation
Problem Statement 1 4 2 3 6 8 7 10 2 9 2 2 2 2 2 We will be given a set of non-negative integers, and a value sum, we must determine if there is a subset of the given set with sum equal to given sum.
Algorithmic Solution We will create a 2D array of size (arr.size() + 1) * (target + 1) of type boolean.
Algorithmic Solution We will create a 2D array of size (arr.size() + 1) * (target + 1) of type boolean. The state DP[i][j] will be true if there exists a subset of elements from A[0….i] with sum value = ‘j’.
Algorithmic Solution We will create a 2D array of size (arr.size() + 1) * (target + 1) of type boolean. The state DP[i][j] will be true if there exists a subset of elements from A[0….i] with sum value = ‘j’. Pseudocode: if (A[i-1] > j) DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]