I am having trouble creating algorithms for this assignment. I would be grateful if I could get some hints on who to start on the first algorithm.
The goal of this assignment is to implement and compare various algorithms for calculating the number of subsets of every possible size for a given set. Remember that a set with n elements has 2^n subsets. Two of the algorithms will be used to actually generate the subsets.
Your program will have the capability of asking the user for choices until he/she wishes to exit. A GUI for your program is permitted, but not required. The choices should allow the following:
- Run an algorithm that works based on counting all 2^n whole numbers starting at 0 (you may not be able to use the C/C++/Java int data type) and determining the size of the subset corresponding to each number. This algorithm must use whole number division and modulus in some way. It needs to return an array holding the numbers of subsets of each possible size. Display the numbers of subsets of each possible size. The value of n will be determined by user input. Error checking should be performed on n.
-
Run an algorithm that works based on counting all 2^n whole numbers starting at 0 (you may not be able to use the C/C++/Java int data type) and determining the size of the subset corresponding to each number. This algorithm must use bit-level operations (logical and and shift) in some way. It needs to return an array holding the numbers of subsets of each possible size. Display the numbers of subsets of each possible size. The value of n will be determined by user input. Error checking should be performed on n.
-
Run an algorithm that generates C(n,k) for all values of k between 0 and n (inclusive), where n is determined by user input. This algorithm needs to utilize a recursive factorial function. It needs to return an array holding the numbers of subsets of each possible size. Display the numbers of subsets of each possible size. Error checking should be performed on n.
-
Run an algorithm that generates C(n,k) for all values of k between 0 and n (inclusive), where n is determined by user input. This algorithm needs to utilize an iterative factorial algorithm. It needs to return an array holding the numbers of subsets of each possible size. Display the numbers of subsets of each possible size. Error checking should be performed on n.
I see that all your questions are about one subject: Recursive Backtracking.
To generate the power set of a set S:
The problem of
C(n, k)is similar, once you understand the concept of recursion. I am not going to give you the solutions for your assignment 🙂