Skip to main content

Subsets

Learn Subsets (Recursion & Backtracking, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Generating All Subsets (the Power Set) A set of n elements has 2ⁿ subsets - each element is either INCLUDED or EXCLUDED, independently. Backtracking generates them all by trying both choices at every element and recursing, with a base case that records the current partial subset once all elements have been decided.

More lessons in Recursion & Backtracking