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
-2
votes
1 answer

Intersection of all N sets in Java

I have List of TreeSet. I need intersection of all TreeSets in the List. I checked reatainAll it is working on two sets,Correct me if i am wrong. Maximum size of List is 8. How can i get intersection of all these sets? public class Rate…
Siva Kumar
  • 632
  • 3
  • 9
  • 19
-3
votes
3 answers

How do I change the Java Set's retainall method to use the equals method instead of the == operator?

I am trying to test whether two HashSets of Strings contain identical Strings. The retainAll() method of Java Sets (which, as I understand it, implements the Collection interface) is a good way to check the intersection of two Sets. However, this…
Todd R
  • 21
  • 1
  • 7
-3
votes
3 answers

C++: Intersection Of two ranges

I'm trying to find the intersection of two ranges in C++? For example, if I have one range as [1..14] inclusive, and another as [10..20] inclusive, I want to get [10..14], as that is the intersection between them. I found a way on SO as follows…
sammy
  • 75
  • 8
-3
votes
2 answers

Set operations in python

I am looking for a single set operation to accomplish both the cases below. Is there a way to do this python? Case 1: a = set([1,2]) and b = set([1,2,3]) I want a result [1,2], which is a straightforward intersection. Now set(a) could be empty and…
Program Questions
  • 440
  • 2
  • 6
  • 20
-5
votes
1 answer

Intersection of two BTreeSet objects in Rust

I can't figure out how to take two BTreeSet objects and create a new, owned, BTreeSet from the intersection operation. Here is a Minimal Example: use std::collections::BTreeSet; fn test() -> BTreeSet { let mut s1 = BTreeSet::new(); let…
FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
-5
votes
1 answer

Why does "set(a) and set(b)" vs "set(a) & set(b)" give different results in python?

I understand that one is bitwise operation while the other is not, but how does this bitwise property affect the results of given expression. As both should simply compare the elements in both sets and result in common elements. set(a) & set(b)…
Divide
  • 1
  • 2
1 2 3
18
19