All possible Subsequences of an array using java
I intend to find all possible subsequences of an array
I tried to do it in 2 different ways
1) Method 1
I create a string with the values in array
// all possible subsequences - all possible elements found by eleiminating zero or more characters
Public class StrManipulation{
public static void combinations(String suffix,String prefix){
if(prefix.length()<0)return;
System.out.println(suffix);
for(int i=0;i
Problem --- works only for single digit characters
2) Method 2
int a[] = new int[3];
a[0]=2;a[1]=3;a[2]=8;
List al= new ArrayList();
for(int i=0;i<3;i++)
al.add(a[i]);
int i, c;
for( c = 0 ; c < 3 ; c++ )
{
for( i = c+1 ; i <= 3 ; i++ )
{
List X = al.subList(c,i);
for(int z=0;z
Problem -- It generates subarrays only for example for an array 2 5 9 I get ---- [2] [2,5] [2,5,9] [5] [5,9] [9] But it misses [2,9]
So can anyone help me with this code?