Given a set of positive integers, find all its subsets.
Input : 1 2 3 Output : // this space denotes null element. 1 1 2 1 2 3 1 3 2 2 3 3 Input : 1 2 Output : 1 2 1 2
Idea is that if we have n number of elements inside an array, we have exactly two choices for each of the elements. Either we include that element in our subset or we do not include it.
1 1 2 1 2 3 1 3 2 2 3 3
Time Complexity : O(2 ^ n)
- Partition an array of non-negative integers into two subsets such that average of both the subsets is equal
- Find all distinct subsets of a given set
- Sum of subsets of all the subsets of an array | O(2^N)
- Sum of subsets of all the subsets of an array | O(3^N)
- Sum of subsets of all the subsets of an array | O(N)
- Rat in a Maze | Backtracking-2
- Sudoku | Backtracking-7
- Subset Sum | Backtracking-4
- Backtracking | Introduction
- Magnet Puzzle | Backtracking-9
- Rat in a Maze | Backtracking using Stack
- N Queen Problem | Backtracking-3
- m Coloring Problem | Backtracking-5
- Hamiltonian Cycle | Backtracking-6
- The Knight's tour problem | Backtracking-1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.