Skip to main content
Filter by
Sorted by
Tagged with
8 votes
3 answers
1k views

I am trying to solve the problem posed in this question. Here the OP asks that given a 15 element set, its 2^15 element power set be generated in a manner such that the elements of the power set are ...
uran42's user avatar
  • 469
0 votes
0 answers
60 views

First of all: how is the operator "{}" really called? The documentation ist not very good at answering this. I call it powerset operator because it creates a powerset of all elements. { z(1)...
Frank Schwidom's user avatar
1 vote
2 answers
85 views

I'm looking for a simple way to generate the powerset of an iterable where each element can be "positive" or "negative", but not both in the same combination. There are no ...
upe's user avatar
  • 2,182
0 votes
1 answer
90 views

What is the most efficient way (and/or most idiomatic) to make a modified powerset of vector of 2-tuples in Rust? By modified, what I mean is the following rule (a,b),(c,b) not in any set, for any a,b,...
Karl's user avatar
  • 97
-4 votes
2 answers
92 views

Chat-GPT generated me the following code in Java, but it still doesn't work with equal elements. The supposed output is incorrect, since the equal elements get simply ignored and I can't figure out ...
Eugen's user avatar
  • 250
1 vote
1 answer
149 views

I get an error: working.hs:186:25: error: * Couldn't match expected type: Set (Set a) with actual type: [[a]] * In the expression: union (map (insert x) (powerSet s)) (powerSet s) ...
fistic iasi's user avatar
0 votes
1 answer
56 views

I am trying to solve the problem Subsets using Javascript. The task is to print the powerset i.e., all subsets from an array. In the function below, I am passing an array as a parameter to collect all ...
argcv's user avatar
  • 51
0 votes
2 answers
126 views

I'm having this combination problem where I'm trying to find subsets of matching combinations of 2 items which results in the highest amount of total matches. Every item can only be in a match once. ...
Oehoe's user avatar
  • 61
1 vote
1 answer
121 views

I Have a powerset function which creates a list [[a]] but the largest [a] is worked out first, meaning the whole algorithm has to run before I can get the smaller values. I need a function which ...
ineedhelp's user avatar
-1 votes
2 answers
70 views

The powerset of {1, 2, 3} is: {{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}} I have a String array in java, String elements={"apple","mango","banana"}; ...
Prashant Singh's user avatar
0 votes
1 answer
54 views

I am trying to make a powerset of a list for the first item of that list in ascending order. However, I couldn't find on StackOverflow how to tackle this specific problem. When making a powerset of ...
Mathijsvdk's user avatar
2 votes
1 answer
223 views

The time complexity of this code to create a powerset from distinct integers is listed as O(n * 2^n) at all places including the Leetcode solution. I listed the complexity of each step as a code ...
bucksbros's user avatar
0 votes
2 answers
481 views

I was solving the classic powerset generation using backtracking. Now, let's say, I add another constraint, the output should appear in a specific order. For input = [1, 2, 3], the output should be [[]...
Zabir Al Nazi Nabil's user avatar
0 votes
1 answer
98 views

I am trying to generate all powersets from a given list within a limit of given maximum size. I've found some great answers for how to generate powersets in general and admire the solution using ...
Elphie's user avatar
  • 3
0 votes
0 answers
71 views

I am using a binomial tree as a list with 2^T - 1 'nodes' and want to create a set of subsets that work within some given criteria (outlined below) on the elements of the list. Right now, I use the ...
jodawg's user avatar
  • 1
1 vote
2 answers
473 views

I have implemented a Set datatype in Haskell using Binary search tree. I have not used any of the in-built functions nor imported any module. My set datatype is as follows: data Set a = Empty | Node a ...
user avatar
1 vote
1 answer
749 views

I am having trouble with simplifying the time complexity for this recursive algorithm for finding the Power-Set of a given Input Set. I not entirely sure if what I have got is correct so far either. ...
tintins7a6164's user avatar
0 votes
1 answer
274 views

For my class I have to create an iterator that will generate a power set of a LinkedSet. Per my professor, I have to iterate through a bitString of the int current. Where current is the subset to ...
thatOnePerson's user avatar
0 votes
2 answers
143 views

Given a tuple items, I get the powerset with itertools: items = tuple(('a', 'b', 'c')) combos = powerset(items) def powerset(iterable): "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3)...
Craig Nathan's user avatar
0 votes
1 answer
203 views

I'm trying to figure out how to implement an algorithm to find a power set given a set, but I'm having some trouble. The sets are actually vectors so for example I am given Set<char> set1{ 'a','...
Jasmine's user avatar
  • 59
1 vote
1 answer
202 views

I am trying to figure out an optimized Python code that, given a set of letters for example [A,B,C] it will arrange them in n_boxes boxes. each box can have no letters, one letter, or a combination ...
Miguel Bordalo's user avatar
2 votes
2 answers
394 views

While I was trying to solve a problem "Subset II" from LC, I came across a strange problem. The code generates a power set from a given set. However, when I run the code it failed because ...
Krunal's user avatar
  • 7,828
0 votes
3 answers
154 views

I have been looking for a language and code to help me calculate all possible subsets of a set of 3600 elements. At first my search started with python, then I went through JavaScript and then came to ...
7beggars_nnnnm's user avatar
0 votes
1 answer
112 views

Given a set {1, 2, 3, 4, 5 ... n} of n elements, we need to find all subsets of length up to k. For example, Input: n = 4 and k = 2 Output: {{1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, ...
mux032's user avatar
  • 65
4 votes
3 answers
919 views

I am a bit new to Python and am working through programming exercises. I have written the following recursive method to generate the power set based on an input list in Python. It should return a ...
ben348943's user avatar
2 votes
0 answers
65 views

I'm using Elasticsearch with default implementation for searching products of my eCommerce site. This default implementation is producing considerably relevant search results. However, I want my ...
autopilot's user avatar
  • 362
3 votes
1 answer
259 views

Algebraic data types make it easy to allow one item from a set to be selected: just use an appropriate sum type. I'm curious how one would implement the option of selecting strictly n items or fewer ...
Theo H's user avatar
  • 243
1 vote
1 answer
73 views

I would like to define a family of types PowersetTower : Type -> nat -> Type such that: PowersetTower A 0 = A PowersetTower A (n+1) = Ensemble (PowersetTower A n) (that is, PowersetTower A n -&...
Jan Tušil's user avatar
0 votes
0 answers
171 views

Hi I am fairly new to python. I am trying to generate a powerset of all combinations for a list of integers, using the recommended code: def powerset(iterable): s = list(iterable) return chain....
TvelA's user avatar
  • 1
0 votes
1 answer
252 views

I have written the following method to generate power set using Java 8 map function public static List<List<Integer>> powerSet(List<Integer> arr){ List<List<Integer>&...
code-geek's user avatar
  • 463
0 votes
1 answer
44 views

So i am doing a comb. auction algorithm and i like to give him N number of items for example (A,B,C) and i want the algorithm to give me back the following result (A,B,C) (ABC) (AB,C) (AC,B) (BC,A) ...
Artur Kostas Minasian's user avatar
0 votes
2 answers
243 views

I am using the following function to find the subsets of a list L. However, when converting the output of the function powerset into a list it takes way too long. Any suggestion? For clarification, ...
gapansi's user avatar
  • 125
2 votes
1 answer
364 views

I need to find the subsets of a set L = [0, 3, 4, 6, 9, 11, 12, 13]. I saw online the following solution: def powerset(s): x = len(s) masks = [1 << i for i in range(x)] for i in ...
gapansi's user avatar
  • 125
0 votes
0 answers
520 views

I have tried to solve a problem of generating all subsets of an array which contains no duplicates from leetcode : https://leetcode.com/problems/subsets/ . e.g if input is [1,2,3], output should be [[]...
user avatar
2 votes
1 answer
165 views

Is it possible to make a racket function to return powerset of a given list? Constraints- without explicit recursion use abstract list functions code contained in 2 lines (actual requirement) For eg:...
Saksham's user avatar
  • 21
0 votes
1 answer
101 views

I'm trying to learn how to code and stumbled upon a problem generating a powerset of a source set in java. I try to write a method that returns a list of lists of doubles for a input of list of ...
Jannik Wolsky's user avatar
3 votes
1 answer
89 views

I am trying to recursively generate the powerset in the range [0, n - 1] without passing extra parameters to the inner search function. def powerSet(n): all_subsets = [] curr_subset = [] def ...
Svinthe's user avatar
  • 63
0 votes
1 answer
58 views

I have been reading the Effective Java book and I have stuck with this code I am unable to understand how this code is generating power set. Code: public class PowerSet { public static final <...
deadshot's user avatar
  • 9,077
1 vote
1 answer
916 views

I'm trying to write a function that takes in a set as an argument and returns its power set, also as a set of sets. Example use: (power-set (set 1 2)) ; is supposed to output => (set (set) (set ...
jimmyb's user avatar
  • 21
0 votes
1 answer
110 views

I'm trying to save the contents of a PowerSet, obtained from a 1d Array into a 2d Array. I tried assigning the values in the array inside the "if" Statement but I'm getting the indices completely ...
DoktoriPartise19's user avatar
0 votes
1 answer
1k views

Given the powerset of 1, 2, 3 I get 8 subsets: [], [1], [2], [2,1], [3], [3,1], [3,2], [3,2,1]. I would like to then generate the subsets of this new set which have exactly 1 of the original set. The ...
Toeler's user avatar
  • 11
1 vote
1 answer
171 views

I had been given a question to utilize java generics and create a Set class. I have been able to perform other functions such as union, intersection, complement etc using this Set class. But the ...
ft1's user avatar
  • 21
1 vote
3 answers
76 views

I've just started working with Python, and I just came across some behavior that I don't understand. I've searched the site for an explanation, but I haven't been able to find it. Perhaps I don't know ...
user avatar
0 votes
2 answers
114 views

What is a good implementation of Power Set algorithm? Recently I needed this algorithm for building a solver for my puzzle game. Generally, the solver should try strategies (sets of turns, the ...
Vladimir Ignatev's user avatar
0 votes
1 answer
117 views

#include <stdio.h> void powerSet(int* a, int index, int *curr, int N) { if (index == N) return; printf("("); for(int i = 0; i <= index; i++) printf("%d, ", curr[...
Giridhar's user avatar
  • 155
0 votes
2 answers
6k views

As per the implementation of finding all possible sub-array from a given array as follows: public class AllPossibleSubArray { public static void main(String[] args) { int[] arr = { 1, 2, ...
javaq's user avatar
  • 131
-1 votes
1 answer
62 views

I'm trying to write code to output all subsets of a set (represented by a list of integers). Why doesn't the following code work? public static List<List<Integer>> powerSet(List<...
medihde's user avatar
  • 19
0 votes
1 answer
45 views

import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; public class PowerSet { public static final <E> Collection&...
Ladislav Rolnik's user avatar
3 votes
3 answers
546 views

I am coding with java so if you can share code with java it would be nice :) Lets say I have a group of (1,2,3,4,5) and I want to create all subgroups of this group with maximum size of a given ...
Daniel Bartov's user avatar
1 vote
1 answer
1k views

I've just started to learn Haskell and had difficult times of solving this problem: powerSet :: Set a -> Set (Set a) Here's my attempt: powerSet :: Tree a -> Tree (Tree a) powerSet Empty = ...
likeliterally's user avatar

1
2 3 4 5