I am working on to solve the Subset - Sum problem. Problem statement is-
Given a set of non-negative integers, and a value sum, determine if there is a subset of the given set with sum equal to given sum.
Example:
Input: set[] = {3, 34, 4, 12, 5, 2}, sum = 9
Output: True //There is a subset (4, 5) with sum 9.
I have seen different approaches to solve this problem. One of them is using recursion and other one is using Dynamic Programming.
My Question is, Why cant we solve the problem using nested loops. Each one of them considering an element and checking it one by one whether it makes a complete sum or not?
Sorry, I am new to algorithms and stuff.