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
3
votes
2 answers

Intersection of two maximum heaps

I have two maximum-heaps (represented in arrays), H1 of size m and H2 of size n, with n>m. I have to create a third max-heap with elements coming from the intersection of H1 and H2. The elementary solution (scan the two arrays) takes O(n*m) time,…
Davide R.
  • 207
  • 2
  • 8
3
votes
1 answer

R: How to efficiently find out whether data.frame A is contained in data.frame B?

In order to find out whether data frame df.a is a subset of data frame df.b I did the following: df.a <- data.frame( x=1:5, y=6:10 ) df.b <- data.frame( x=1:7, y=6:12 ) inds.x <- as.integer( lapply( df.a$x, function(x) which(df.b$x == x) )) inds.y…
user3139868
  • 393
  • 2
  • 12
3
votes
1 answer

Computing efficiently intersection of n sets

I have n sets identified by setId and each one could contain an arbitrary number of elements that is a pair (elementId, priority). My algorithm should take in input two setId, and give in output a set containing the first m elements which are in the…
marka.thore
  • 2,795
  • 2
  • 20
  • 35
3
votes
1 answer

Using set_intersection on set container.

Hi everybody :) i d like to create a personnal set Class and to overload the operator /=, in the case of my class, this operator should be used to take the interstion of two Sets. I got the following error: error: assignment of read-only location…
Vrael
  • 77
  • 6
3
votes
0 answers

What is optimal performance for set merge algorithms?

Assume ordered sets that support O(n) iteration and O(log n) access to single items, what is theoretically optimal complexity for set-union, set-intersection and set-difference? Assume that a dedicated structure could be used for the sets, as long…
3
votes
3 answers

C++ to compare 2 lists of strings

In Python, set is pretty handy for comparing 2 lists of strings (see this link). I was wondering if there's a good solution for C++ in terms of performance. As each list has over 1 million strings in it. It's case-sensitive matching.
Stan
  • 37,207
  • 50
  • 124
  • 185
2
votes
1 answer

Finding intersections between a large number of sets with unique elements each

The following is an interesting algorithmic problem. Inputs: The set of elements S (say, non-negative integers). A mapping N that maps some elements from S to a subset S_k \subset S. (not all elements of S are represented, neither in keys nor in…
2
votes
3 answers

PowerShell: Intersection of more than two arrays

Using PowerShell, I have 14 arrays of strings. Some of the arrays are empty. How would I get the intersection (all elements that exist in all of the arrays) of these arrays (excluding the arrays that are empty)? I am trying to avoid comparing two…
MaxRax
  • 23
  • 4
2
votes
1 answer

Select if array contains an element of another array

I have a table which has a JSON type field where I save a number array like [1, 2, 3, 4]. I want to select records in which its array set contains at least one element of another array I have in a php script. I know that the JSON_CONTAINS function…
AlexSp3
  • 2,201
  • 2
  • 7
  • 24
2
votes
0 answers

SIMD vector intersection of two sets using AVX-512: need a speed up

I currently need to intersect two sorted vectors. Here are my implementations: #include #include #include #include #include #include #include #include #include…
Kroma
  • 1,109
  • 9
  • 18
2
votes
1 answer

EF Core Intersect between List and Property of child element returns "ArgumentNullException"

I am currently trying to intersect a list of IDs with a child property of my Database Entity. The intent of doing so is to find all "Form" records that that have all of the list Ids matching at least one entity in the child entity "Location". I…
Bitz
  • 1,128
  • 11
  • 33
2
votes
3 answers

how to intersect elements of one column along with group_by in R

Lets assume, my data is like group_id col1 1 1 A,B 2 1 B,C 3 2 A,C 4 2 B,D 5 3 A,D 6 3 A,B,C,D I would like to summarise/mutate col1 where its elements are intersected within same…
AnilGoyal
  • 25,297
  • 4
  • 27
  • 45
2
votes
1 answer

Detect points upstream and downstream of an intersection between two curves

I have two curves, defined by X1=[9, 10.5, 11, 12, 12, 11, 10, 8, 7, 7] Y1=[-5, -3.5, -2.5, -0.7, 1, 3, 4, 5, 5, 5] X2=[5, 7, 9, 9.5, 10, 11, 12] Y2=[-2, 4, 1, 0, -0.5, -0.7, -3] They intersect each other and by a function which is written in the…
2
votes
1 answer

Finding every point of intersection of multiple lines using pygame in python for creation of game board

I need to find every point of intersection of lines in my code. At these points, I want to put my game pieces. The logic of the game is like that of tic tac toe in which if a player places 3 same color marbles in a row he/she can grab a piece of the…
shyckh
  • 57
  • 8
2
votes
1 answer

Why does TypeScript only sometimes treat an impossible intersection as 'never'?

TypeScript will sometimes decide that two types, if intersected, don't have any compatible values. This empty intersection is called never and means that you can't provide a value that fulfills both types: type Bread = { shape: "loafy" }; type Car…
Ryan Cavanaugh
  • 209,514
  • 56
  • 272
  • 235