cud u help me ... i am struggling with this question... to
find all the subsets of a given set for ex.... a,,b,c shud
give all the subsets.... i gt the program in c bt nt able
to get it in java..... help needed ..
Answer / Devesh Kumar Dubey
To find all the subsets of a given set in Java, you can use bit manipulation techniques. Here's an example code snippet that demonstrates this approach:
```
import java.util.ArrayList;
public class Subset {
static int n = 3; // number of elements in the set
static ArrayList<ArrayList<Integer>> subsets = new ArrayList<>();
public static void main(String[] args) {
ArrayList<Integer> set = new ArrayList<>();
for (int i = 1; i <= n; i++) {
set.add(i);
}
findSubsets(set, (int) Math.pow(2, n) - 1);
for (ArrayList<Integer> subset : subsets) {
System.out.println(subset);
}
}
public static void findSubsets(ArrayList<Integer> set, int k) {
if (k == 0) {
// base case: empty subset
ArrayList<Integer> emptySet = new ArrayList<>();
subsets.add(emptySet);
return;
}
for (int i = set.size() - 1; i >= 0; i--) {
// create a copy of the current subset and add the current element if the corresponding bit in k is set
ArrayList<Integer> newSet = new ArrayList<>(set);
if ((k & (1 << i)) > 0) {
newSet.add(newSet.get(i));
}
// recursively find subsets for the remaining elements and the updated k value
findSubsets(newSet, k - (1 << i));
}
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Explain the purposes of methods wait(), notify(), notifyAll ()?
How are the elements of a borderlayout organized?
Write a singleton program?
1) Scenario: I developed my application on local system and everything is perfect and tested. Now on UAT this application is deployed on clustered server environment. They are logical or physically clustered. But application is not working over there.  What is the issue with application?  What are the first things which come in your mind?
Can we sent objects using Sockets?
What are synchronized methods and synchronized statements?
what is the use of Object Factories?
Explain bind(), rebind(), unbind() and lookup() methods?
Explain the difference between object state and behavior?
what is JTS?
What are the various thread priorities?
What exceptions are thrown by RMI?