This repository provides an educational comparison of two fundamental approaches to solving the Subset Sum Problem: Brute Force (Exhaustive Search) and Dynamic Programming (DP).
Given a set of non-negative integers (e.g.,
The subset sum problem is a classic example of an NP-complete problem. This means it is both in the complexity class NP (a potential solution can be verified in polynomial time) and NP-hard (every other problem in NP can be reduced to it in polynomial time).
The brute force approach is an exact approach to solve the problem, but inefficient for a large number of list items, n.
| Approach | Description | Time Complexity | Notes |
|---|---|---|---|
| Brute Force | Tries every possible subset ( |
|
Highly inefficient for large input sets. |
| Dynamic Programming | Builds a table of solutions to smaller subproblems ( |
|
Faster than Brute Force, but performance depends on the magnitude of the target sum ( |