140 likes | 360 Views
This presentation aims to solve the subset sum problems using dynamic programming. This "subset sum problem" tutorial helps learners to learn data structures and algorithms through a standard problem.<br> <br>This presentation will cover the following concepts:<br>1. Introduction<br>2. Problem Statment<br>3. Algorithmic solution<br>4. Implementation
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]]