Question: PowerSet.java This class represents the Power Set from a given set. This class must also work with the generic type T. The class must have

 PowerSet.java This class represents the Power Set from a given set.

PowerSet.java This class represents the Power Set from a given set. This class must also work with the generic type T. The class must have the following private variable: - Set[] set The class must have the following public methods: - public PowerSet(T] elements): constructor - Generate the Power Set from the given T array of elements - See the hints below (Power Set Generation) for help on how to approach this - Store the series of sets for this Power Set in the instance variable, set. - public int getLength() - Return the number of items in the array (the number of sets in the Power Set) - public Set getSet(int i) - Return the Set stored at index i of the array Power Set Generation Creating a Power Set might sound difficult but there is a recommended approach that simplifies the process. - A Power Set for a set of n elements will contain 2n sets. - To generate each of the 2n sets with the proper combination of elements, take the binary representation of each number from 0 to 2n1. Hint: you can use Integer.toBinaryString (x) to convert an int, x, to its binary representation as a String. - Ensure that all the binary numbers have the same number of digits (they will need to have n digits) using padded zeroes at the front, i.e. 0001. - Loop through each binary number and through each digit (bit) of the binary number. Whenever the digit (bit) is a 1, add the item from the original set at the corresponding index into the proper set for the Power Set (see the Example table below and the resulting sets (below the table) that would be produced from each binary number)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!