sets

Obtaining powerset of a set in java

The powerset of {1, 2, 3} is: {{}, {2}, {3}, {2, 3}, {1, 2}, {1, 3}, {1, 2, 3}, {1}} Lets say I have a Set in Java... Set<Integer> mySet = new HashSet<Integer>(); mySet.add(1); mySet.add(2); mySet.add(3); Set<Set<Integer>> powerSet = getPowerset(mySet); What I want is the function getPowerset, with the best possible order of complex...

LINQ : Determine if two sequences contains exactly the same elements

I need to determine whether or not two sets contains exactly the same elements. The ordering does not matter. For instance, these two arrays should be considered equal: IEnumerable<int> data = new []{ 3,5,6,9 }; IEnumerable<int> otherData = new []{ 6,5,9,3} One set cannot contain any elements, that are not in the other. Can this be...

Removing items from a collection in java while iterating over it

I want to be able to remove multiple elements from a set while I am iterating over it. Initially I hoped that iterators were smart enough for the naive solution below to work. Set<SomeClass> set = new HashSet<SomeClass>(); fillSet(set); Iterator<SomeClass> it = set.iterator(); while (it.hasNext()) { set.removeAll(setOfElementsToRemo...

Functional Data Structures in Java

Does the Java standard library have any functional data structures, like immutable Sets, Lists, etc., with functional update? ...

Is there code out there to subclass set in Python for big xranges?

I'm trying to write some Python code that includes union/intersection of sets that potentially can be very large. Much of the time, these sets will be essentially set(xrange(1<<32)) or something of the kind, but often there will be ranges of values that do not belong in the set (say, 'bit 5 cannot be clear'), or extra values thrown in. F...

Does Microsoft Access 2003 contain sets or multisets?

I'm trying to confirm or deny whether you can define a table column in MS Access 2003 as a set. It seems this is implemented in Office 2007 - you can define a column to have a 'multi-select list' in the query/lookup, but this feature appears to be unique to the new access 2007 file format as far as I can determine. Worded another way, ...

Ruby: Make hash from Hash => Set

I have a join table that I'm using to find available services for an order form; in that table is the utility_id and a company_id. What I want is a group (hash) where the keys are the utility names and the values are hashes of the corresponding companies. I got the following... Service.find(:all).to_set.classify { |service| Utility.fi...

Collection of sets containing no sets which are a subset of another in the collection

I am looking for an abstract data structure which represents a collection of sets such that no set in the collection is a subset of another set in the collection. This means that on insert the following conditions will be met: A. Inserting an element that is already a subset of another element will return the original collection. B. I...

Python: Fast extraction of intersections among all possible 2-combinations in a large number of lists

I have a dataset of ca. 9K lists of variable length (1 to 100K elements). I need to calculate the length of the intersection of all possible 2-list combinations in this dataset. Note that elements in each list are unique so they can be stored as sets in python. What is the most efficient way to perform this in python? Edit I forgot to ...

In-place C++ set intersection

The standard way of intersecting two sets in C++ is to do the following: std::set<int> set_1; // With some elements std::set<int> set_2; // With some other elements std::set<int> the_intersection; // Destination of intersect std::set_intersection(set_1.begin(), set_1.end(), set_2.begin(), set_2.end(), std::inserter(the_intersection, ...

Fuzzy logic membership function in C

Hi, I'm trying to implement a fuzzy logic membership function in C for a hobby robotics project but I'm not quite sure how to start. I have inputs about objects near a point, such as distance or which directions are clear/obstructed, and I want to map how strongly these inputs belong to sets like very near, near, far, very far. Does ...

Generate all possible dna sequences from a few given sets

Hi, I have been trying to wrap my head around this for a while now but have not been able to come up with a good solution. Here goes: Given a number of sets: set1: A, T set2: C set3: A, C, G set4: T set5: G I want to generate all possible sequences from a list of sets. In this example the length of the sequence is 5, but it can be a...

Finding elements that are present in one set not the other

I have two sets A and B. A -- 1 2 6 B -- 1 2 3 4 When I compare set A with B, I need to get value 6 as output and value 4 as output when set B is compared against A. I am wondering what would be the best algorithm to do this? I have wrote one but it has got a quadratic complexity. It basically iterate one set and inside the loop it...

Some thought about a PHP Enum setup

Hi all, For a project I'm working I need to have some sort of enumaration class since the data won't be changed It's useless to store it in a database and exhaust the db-server with unnecessary request. So after reading some related posts on SO I tried the following: class Model_MaintenanceTerminology { const SetDefault = array("id" ...

Project Euler: please help me understand #106

I have solved #103 and #105, but I have a hard time understanding #106, specifically where does the number 25 come from? If we are talking about two disjoint subsets with equal number of elements, then 1-elem vs. 1-elem: there are 4 x 3 = 12 comparisons 2 vs. 2: C(4, 2) = 6 comparisons If we include disjoint subsets with non-equal nu...

Is there a Queue (PriorityQueue) implementation which is also a Set?

I'm looking for a PriorityQueue implementation which is also a Set. The compareTo implementation if its elements must not have the requirement to be consistent with the implementation of equals. Is there somewhere such a implementation for java? Update: I implemented it now using a SortedSet as the internal collection. So I only had t...

Returning Multiple Counts of Rows

Hard to capture the problem in a single sentence, but the problem is a simple one. Table looks like this: col_a col_b v1 c v2 c v3 c v5 d v2 d v1 a v5 a v7 a v4 a Each row is distinct, and I need a count of the rows for each unique value of col_b. So, my resu...

Finding the closest number in a random set

Say I got a set of 10 random numbers between 0 and 100. An operator gives me also a random number between 0 and 100. Then I got to find the number in the set that is the closest from the number the operator gave me. example set = {1,10,34,39,69,89,94,96,98,100} operator number = 45 return = 39 And how do translate this into code? (...

Ruby Array Intersection, Hash.has_value? for intersection with array[i+1] based on hash values

I am trying to populate an array with an intersection of an array and hash based on hash values: array2 = ["hi","world","One"] Vals = {:one => "One", :two => "Two"} array2 = VALS.values & array2 print array2 Works fine for intersection of hash values and array2[ i ], but if I want to instead populate with array2[ i+1 ] element from ar...

what does O(N) mean

Possible Duplicate: What is Big O notation? Do you use it? Hi all, fairly basic scalability notation question. I recently recieved a comment on a post that my python ordered-list implimentation "but beware that your 'ordered set' implementation is O(N) for insertions" Which is great to know, but I'm not sure what this means. ...