CSCI 3342 Submission 07
Generating and Displaying Power Sets
Supplied file(s) | $sup07/demo_power_sets |
---|---|
Files to submit |
power_sets.cpp (your source code) power_sets (your executable) my_tests.sh (your testing script) |
Where to put them | Copy them to your u##/submissions/s07 directory. |
When they're due | Sun, Mar 16, 2025 @11:59pm |
This week you will have a chance to showcase your "recursion chops" by
writing a recursive function to compute the power set of a
set of integers or characters, which will also require you to make critical
use of the STL set
container. You can solve the problem for
this submission however you like, but I strongly suggest that you write two
functions, a recursive one to compute the power set of a set of integers or
characters provided as input, and a non-recursive function that takes as
input that power set and displays each set of the power set in the required
output format.
The power set of any set is the set of all subsets of that set. One can prove (using mathematical induction, and perhaps other techniques as well) that the number of sets in the power set of a finite set containing n elements is 2^n (2 to the power n). So, for example, the power set of any set containing 3 elements will contain 8 elements. If this is a new concept for you, construct a set of three elements and then write down all of its subsets to confirm the previous statement.
if (the set is empty) return the empty set else Take an element out of the set and then: (1) Find the power set of the "reduced" set (2) Add the removed element to each set in the power set of that reduced set return the "union" of the two sets in (1) and (2) above