A Quick Introduction to the Subset Sum Problem

A Quick Overview

Do you want to learn about a problem that involves finding subsets of an array with a specific sum? Introducing the Subset Sum Problem!

Given an array of non-negative integers and an integer sum, find whether any subset exists in an array whose sum equals the given integer sum.

Problem Statement

Input: arr[] = {3, 34, 4, 12, 3, 2}, sum = 7  Output: True  Explanation: There is a subset (4, 3) with sum 7.


First Case-   1. Take the last element.  2. Now, sum = target sum – value of ‘last’ element.  3. Elements remaining = size of array – 1.

Recursive Approach

Looking for a more efficient solution to Subset Sum Problem? Check out this Approach. Here, we will make a 2D array of size equal to (size of array + 1) * (target sum + 1) of boolean type.

Dynamic Programming Approach

Time Complexity: O(N * sum), where N is array size   Space Complexity: O(N * sum), where N is array size

Explore different approaches and learn how to implement them in various programming languages.