Questions tagged [symmetric-difference]

The symmetric difference of two sets consists of those elements that are present in either set, but not in both.

"Symmetric difference" is a mathematical operation defined upon sets.
The symmetric difference between two sets is defined as the set of those elements that belong to either one of those sets, but not both.

For example, let A = { 1, 2, 3, 4 } and B = { 2, 4, 6, 8 }.

  • Elements in A that are not in B are 1 and 3.
  • Elements that are in B but not in A are 6 and 8.
  • Hence, the symmetric difference is { 1, 3, 6, 8 }.

Symmetric difference can also be defined on more than two sets. In this case, the symmetric difference is defined as the set of elements which are in an odd number of sets.

Wikipedia link: https://en.wikipedia.org/wiki/Symmetric_difference

25 questions
0
votes
2 answers

How to find symmetrical difference using JavaScript?

I've been working on an algorithm that will find the symmetric difference of two arrays (i.e. only items that are in 1 of the 2 arrays, but not both). I've come up with the following so far: function diffArray(arr1, arr2) { let newArr1 =…
alexion
  • 13
  • 3
0
votes
0 answers

Symmetric Difference Recursion Function is returning "UNDEFINED"

Alright, I'm trying to do one of the freeCodeCamp lessons online and I'm getting undefined when I think that I shouldn't be. I'm new to this so there is probably a really easy solution to this but I would like to know where I am going wrong. The…
0
votes
0 answers

Efficiently compute xor / symmetric difference of many sets (list of sets)

I have an arbitrary number of Python sets, e.g. >>> a = {1, 2, 3} >>> b = {3, 4, 5} >>> c = {5, 6, 7} >>> d = {7, 8, 1} I want to compute their "combined" symmetric difference, i.e. I want to xor all of them: >>> a ^ b ^ c ^ d {2, 4, 6, 8} In my…
s-m-e
  • 3,433
  • 2
  • 34
  • 71
0
votes
1 answer

Finding symmetric difference of two lists of objects

Consider two lists (or other appropriate data structures) of the objects of type: class Object { public string clause; public string preamble; public string description; } I need to build a list of these objects that are NOT perfect…
Al2110
  • 566
  • 9
  • 25
0
votes
1 answer

how to reduce the key number used in symmetric encryption

We know the number of key used in symmetric encryption is n(n-1)/2. Is there a way to reduce the number of keys used in the communication? Let’s say that if there are 1000 students wants to communicate with each other using symmetric encryption,…
0
votes
1 answer

symmetric_difference Output as Two Separate Lists

Let's say we have two lists of values, whereby each list only contains unique values unto itself. There will never be duplicate values in a single list. L1 | L2 ------- a | a b | d c | e d | g e | h f | i | j We can get the…
oldboy
  • 5,729
  • 6
  • 38
  • 86
0
votes
2 answers

convert a set of tuples into a numpy array of lists in python

So, I've been using the set method "symmetric_difference" between 2 ndarray matrices in the following way: x_set = list(set(tuple(i) for i in x_spam_matrix.tolist()).symmetric_difference( set(tuple(j) for j in…
0
votes
2 answers

How to efficiently find identical indices in multiple dataframes

I have a process that collects reports generated throughout the week and consolidates the collection to eliminate identical reports. I've written a function that identifies identical reports by finding those that have identical indices, then it…
Jed
  • 638
  • 1
  • 8
  • 17
0
votes
2 answers

Locally symmetric difference in sql

I have a problem similar to this StackOverflow question, except that I need to exclude certain fields from the comparison but still include it in the result set. I'm penning the problem as locally symmetric difference. For example Table A and B…
BlackHowling
  • 3
  • 1
  • 3
0
votes
2 answers

Python: best way to find out from which set the results of `symmetric_difference` are from?

What is the best practice for finding out from which set the results of symmetric_difference are from? intersect = s1.symmetric_difference(s2) The result should look like {'34':'s1', '66':'s2'} Where '34','66' are the unique items.
LarsVegas
  • 6,522
  • 10
  • 43
  • 67
1
2