Questions tagged [set-intersection]

The intersection of two or more sets consists of the elements that those sets all have in common.

Set intersection is a mathematical operation defined upon sets.
The intersection of two or more sets is defined as the set of those elements that are present in all sets.

For example, let A = { 2, 3, 4 } and B = { 2, 4, 5 }.
The intersection of A and B is what the set of elements that A and B have in common: { 2, 4 }.
The symbol for intersection is ∩, so in our example we would write A ∩ B = { 2, 4 }

276 questions
4
votes
3 answers

Python: Symmetrical Difference Between List of Sets of Strings

I have a list that contains multiple sets of strings, and I would like to find the symmetric difference between each string and the other strings in the set. For example, I have the following list: targets = [{'B', 'C', 'A'}, {'E', 'C', 'D'},…
SummerEla
  • 1,902
  • 3
  • 26
  • 43
4
votes
3 answers

MySQL: Efficient way computing set powers of Venn-Diagram

Given the 4 tables, each containing items and representing one set, how to get the count of the items in each compartment required to draw a Venn diagram as shown below. The calculation should take place in the MySQL server avoiding transmission of…
Rainer Rillke
  • 1,281
  • 12
  • 24
4
votes
3 answers

Find equal rows between two Matlab matrices

I have a matrix index in Matlab with size GxN and a matrix A with size MxN. Let me provide an example before presenting my question. clear N=3; G=2; M=5; index=[1 2 3; 13 14 15]; %GxN A=[1 2 3; 5 6 7; 21 22 23; 1 2 3; …
TEX
  • 2,249
  • 20
  • 43
4
votes
2 answers

Finding common links in a matrix and classification by common intersection

Suppose I have a matrix of distance cost, in which the cost of destiny and the cost of origin both need to be below a certain threshold amount - say, US 100 -- to share a link. My difficulty lies in achieving a common set after classifying these…
John Doe
  • 212
  • 1
  • 9
  • 28
4
votes
2 answers

How to find common elements in string cells?

I want to find the common elements in multiple (>=2) cell arrays of strings. A related question is here, and the answer proposes to use the function intersect(), however it works for only 2 inputs. In my case, I have more than two cells, and I want…
jeff
  • 13,055
  • 29
  • 78
  • 136
4
votes
2 answers

Intersections and Unions in Ruby for sets with repeated elements

How do we get intersections and unions in Ruby for sets that repeat elements. # given the sets a = ["A", "B", "B", "C", "D", "D"] b = ["B", "C", "D", "D", "D", "E"] # A union function that adds repetitions union(a, b) => ["A", "B", "B", "C", "D",…
Amin Shah Gilani
  • 8,675
  • 5
  • 37
  • 79
4
votes
1 answer

Maximum Cardinality Intersection of Every Pair of Equal-Size Sets

We have N sets, each having N integers. We take every pair of sets, and find their intersection set, S. Now, we are interested to find the cardinality of the intersection set S that has maximum cardinality. Example For example, let N be 4 and…
Sushil Verma
  • 659
  • 9
  • 23
4
votes
3 answers

Compare an unspecified number of arrays for common values in javascript

I would like to know how to compare two or more -- potentially unlimited -- arrays for common values and push these values into a new array efficiently. Below I have a function that will accept unlimited arguments, but I am uncertain if this is a…
Laurence
  • 43
  • 3
4
votes
2 answers

finding the smallest array that intersects with a set of arrays

Say I have three arrays - ['a', 'b'], ['b', 'c'] and ['d']. If I were to create a fourth array that intersects with these three arrays with a minimal number of elements the array I'd get would be ['b', 'd']. My question is... how would I go about…
neubert
  • 15,947
  • 24
  • 120
  • 212
4
votes
2 answers

Using a map with set_intersection

Not used set_intersection before, but I believe it will work with maps. I wrote the following example code but it doesn't give me what I'd expect: #include #include #include #include using namespace…
Component 10
  • 10,247
  • 7
  • 47
  • 64
4
votes
2 answers

SetIntersection size without allocation

Given 2 sets (C++) is there a convenient way to get the size of the intersection without any alocations (as std::set_intersection does) Sure, I could copy the implementation minus the assignment but I always rather not re-invent the wheel int count…
aivision2020
  • 619
  • 6
  • 14
4
votes
2 answers

std::set_intersection on two completely different containers

I had a simple requirement where I need to find the occurance of strings in one vector from a master list of strings in another vector. I was able to do it easily at first with: vector custom_list; set master_list; vector
ForeverLearning
  • 6,352
  • 3
  • 27
  • 33
4
votes
1 answer

Parallel algorithm for set intersections

I have n-sets (distributed on n-ranks) of data which represents the nodes of a mesh and I wanted to know an efficient parallel algorithm to find the intersection of these sets, i.e., the common nodes. An intersection is defined as soon as any 2 sets…
3
votes
5 answers

Union of All Intersecting Sets

Given a list of objects with multiple attributes I need to find the list of sets created by a union of all intersecting subsets. Specifically these are Person objects, each with many attributes. I need to create a list of 'master' sets based on a…
3
votes
2 answers

How do I do a linq query to find fields in a dataset that are present in every record of a set?

I have an XML data set with 10K records, each containing a set of fields. I'd like to know which fields need to be null and which can be non-null in the database schema that matches the dataset. Does linq offer way to produce a big…
Aaron Anodide
  • 16,906
  • 15
  • 62
  • 121