Problem

Recursive Generation of Subsets Solve the problem of Programming Challenge 11 by...

Recursive Generation of Subsets

Solve the problem of Programming Challenge 11 by using recursion. Do this by writing a recursive function that takes an integer parameter n and returns a list of all subsets of the set 1, 2 . . . , n.

11.Generation of Subsets

Adopt the following strategy to construct the list of all subsets of the set of the integers 1, 2, . . . n. Use an STL vector to represent a single subset of integers, and use an STL list of vectors to represent a list of subsets. Start with a list L0 of one empty vector; then L0 represents the list of all subsets of the empty set. Now suppose that you have created the list Lk-1 of all subsets of 1, 2, . . ., k-1. To form the list Lk of all subsets of 1, 2, . . . k create an empty list L, and then for each vector v in Lk-1, add both v and v [k] to L. Finally, set Lk to L. (Here by v [k] we mean the result of adding the integer k to the vector v.) Test your program for all values of n ≤4.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT