private static void generate_power_set_helper(ArrayList<Integer> S, int idx,
                                   LinkedList<Integer> res) {
        if (!res.isEmpty()) {
            // Print the subset.
            Iterator<Integer> iterator = res.iterator();
            while(iterator.hasNext()) {
                System.out.print(iterator.next());
                if(iterator.hasNext())
                    System.out.print(",");
            }
        }
        System.out.println();

        for (int i = idx; i < S.size(); ++i) {
            res.offerLast(S.get(i));
            generate_power_set_helper(S, i + 1, res);
            res.pollLast();
        }
    }