How to Efficiently Handle Set Operations Without Inbuilt Functions?

Click For Summary
SUMMARY

This discussion focuses on efficiently handling set operations without relying on inbuilt functions. The primary example involves calculating the set difference A - (B ∪ C) using sets A = [1, 2, x, y], B = [2, x, z, m], and C = [4, 5]. The correct result is derived as {1, y} by removing elements of B and C from A. The conversation emphasizes the importance of verifying answers and understanding foundational concepts like DeMorgan's laws in set theory.

PREREQUISITES
  • Understanding of set theory concepts, including set difference and union
  • Familiarity with DeMorgan's laws in set operations
  • Basic programming skills for implementing pseudocode
  • Ability to manipulate and analyze sets without inbuilt functions
NEXT STEPS
  • Learn how to implement set operations in Python without using built-in functions
  • Explore advanced set theory concepts, including Cartesian products and power sets
  • Study the application of DeMorgan's laws in complex set operations
  • Investigate algorithms for efficient set manipulation in large datasets
USEFUL FOR

This discussion is beneficial for students studying discrete mathematics, software developers implementing custom set operations, and educators teaching set theory concepts.

chwala
Gold Member
Messages
2,827
Reaction score
415
Homework Statement
This is my original question; Given ##A=[1,2,x,y]## ##B=[2,x,z,m]## ##C=[4,5]##, then find
##A-(BUC)##
Relevant Equations
set theory
ok we shall have ##(A-B)∩(A-C)= [1,y]∩[1,2,x,y]=[1,y]## correct?
 
Physics news on Phys.org
Have you heard of DeMorgan's laws?
 
  • Like
Likes chwala
chwala said:
Homework Statement:: This is my original question; Given ##A=[1,2,x,y]## ##B=[2,x,z,m]## ##C=[4,5]##, then find
##A-(BUC)##
Relevant Equations:: set theory

ok we shall have ##(A-B)∩(A-C)= [1,y]∩[1,2,x,y]=[1,y]## correct?
Correct. But it concerns me that you seem unable to check your answers yourself. That is a skill that is just as important to learn as anything else.
 
  • Like
Likes chwala
WWGD said:
Have you heard of DeMorgan's laws?
Yes that's what I used...##M-(B∪Q)=(M-B)∩(M-Q)##
 
Last edited:
  • Like
Likes WWGD
FactChecker said:
Correct. But it concerns me that you seem unable to check your answers yourself. That is a skill that is just as important to learn as anything else.
I am able to check...I ask because I may want a different perspective from what I know...I am always learning...cheers
 
chwala said:
I am able to check...I ask because I may want a different perspective from what I know...I am always learning...cheers
My perspective would be that if you want a simple answer to this, you do the following:

a) Write down the elements of the set ##A##: ##1, 2, x, y##.

b) Write down the elements of ##B \cup C##: ##2, x, z, m, 4, 5##

c) Go through the set ##B \cup C## one element at a time and delete these elements from the list in set ##A##.

1d) That gives the answer ##A - (B \cup C) = \{1, y\}##

If you want to verify De Morgan's law by using this as an example, then fine. But, don't lose sight of the simple fact that ##A - (B \cup C)## means things that are in ##A## with anything that is in either ##B## or ##C## removed.
 
  • Love
  • Like
Likes Mark44 and chwala
Yes, it's a good think not to rely only on big formulas , but what if you have similar with a large collection of sets? It becomes a nightmare to do a specific example.
 
  • Like
Likes chwala
WWGD said:
Yes, it's a good think not to rely only on big formulas , but what if you have similar with a large collection of sets? It becomes a nightmare to do a specific example.
If I were coding this, without using inbuilt set operations, then I would do it either the way described; or, not bother with the union at all, but just go through ##B## and ##C## separately and delete elements from ##A##. My first step wouldn't be the form the sets ##A - B## and ##A - C##.

For example, pseudocode for ##X = A - (B_1 \cup B_2 \dots \cup B_n)##:

Create set ##X = A##
For ##k = 1## to ##n##:
Remove any element in ##B_k## from ##X##
(or, ##X = X - B_k## for short)
Loop
Print ##X##
 
  • Like
Likes Hall and chwala

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
Replies
15
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 23 ·
Replies
23
Views
2K
Replies
8
Views
2K
Replies
4
Views
2K
Replies
18
Views
3K
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K