For every set A and B,
for example A=[A,B]. B=[B,D,E]
Use java or python to crate 4 function:
1: union
A union B = [A,B,D,E]
2: intersection
A intersection B = [B]
3: A-B =[A]
4: subset (boolean)
False
Here is the completed code for this problem in Python. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.
#code
'''
Implementation of required functions in Python using lists.
You can also use sets instead of lists, so that we dont need to check
for duplicate values.
'''
#method to implement union of setA and setB
def union(setA, setB):
#creating a list to store the result
result=[]
#adding each element of setA to result
for i in setA:
result.append(i)
#adding each element of setB to result, avoiding duplicates
for i in setB:
if i not in result:
result.append(i)
#returning result
return result
#method to find the intersection of setA and setB
def intersection(setA, setB):
result=[]
#looping through each element in setA, adding to setB only if
#the element is present on setB also
for i in setA:
if i in setB:
result.append(i)
return result
#method to find the set difference of setA and setB
def difference(setA, setB):
result=[]
# looping through each element in setA, adding to setB only if
# the element is NOT present on setB
for i in setA:
if i not in setB:
result.append(i)
return result
#method to check if setA is a subset of setB
def subset(setA, setB):
#looping and checking if all elements of setA is present on setB
for i in setA:
if i not in setB:
#current element of setA is not present in setB
return False
return True #subset
#creating two sets and demonstrating all operations
A=['A','B','C','D']
B=['C','D','E','F']
print('A =',A)
print('B =',B)
print('A union B =',union(A,B))
print('A intersection B =',intersection(A,B))
print('A - B =',difference(A,B))
print('B - A =',difference(B,A))
print('A subset of B =',subset(A,B))
#output

For every set A and B, for example A=[A,B]. B=[B,D,E] Use java or python to crate...
Justify your answer to each of the following true/false statements: l. Every subset of a regular set is regular 2. The intersection of a regular set with a finite set is regular 3. The union of a regular set with an infinite set is regular 4. The positive closure of a regular set is regular
5- Recall that a set KCR is said to be compact if every open cover for K has a finite subcover 5-1) Use the above definition to prove that if A and B are two compact subsets of R then AUB is compact induction to show that a finite union of compact subsets of R is compact. 5-2) Now use 5-3) Let A be a nonempty finite subset of R. Prove that A is compact 5-4) Give an example of...
1. Let A be the set {e, f, g, h} and B be the set {e, g, h}. a. Is A a subset of B? b. Is B a subset of A? c. What is A Ս B? d. What is A x B? e. What is the power set of B? 2. Determine whether these statements are true or false? a. ∅ ∈ {∅} b. {∅} ∈ {∅} c. {∅} ⊂ {∅, {∅}} d. ∅ ∈ {∅, {∅}} e....
ML LANGUAGE.
1. Use ML patterns to write a function member (e, L) that returns true if e is an element of ist L. 2. Use ML patterns to write a function less (e, L) that returns the list of all elements of L that are less than e. 3. Use ML patterns to write a function union (S1, S2) that returns the union of sets S1 and S2. We implement sets as unordered lists of elements, without repetitions. Hint:...
1. Define the set S = {a, b, c, d, e, f, g}. a. Give an example of a 4-permutation from the set S. b. Give an example of a 4-subset from the set S. c. How many subsets of S have two or more elements? d. How many subsets of S have 3 or 4 elements?
python List1=[ ["a", 1], ["b", 3], ["c", 3], ["d", 2], ["e", 1], ["f", 4], ["g", 2]] 1 def function(Letter,List),example, function("c",List) return 3 2 def function(word,List),example, function("a",List) return 1, function("be",List) return 4, function("bee",[b,5],[e,20]) return 45 Dictionary = ["a","bee","ad","ae"] 3 ["a","b","y","e"] return[["a",1],["ae",2],["bee",5]] 4 input a list, find largest value words can spell, return words and value dont using loop, using recursion for those code
Using Java programming language, build a class called IntegerSet. Instructions - Create class IntegerSet An IntegerSet object holds integers in the range 0-100 Represented by an array of booleans, such that array element a[i] is set to true if integer i is in the set, and false otherwise Create these constructors and methods for the class IntegerSet() public IntegerSet union(IntegerSet iSet) public IntegerSet intersection(IntegerSet iSet) public IntegerSet insertElement(int data) public IntegerSet deleteElement(int data) public boolean isEqualTo(IntegerSet iSet) public String toString()...
use python
2a. Union (1 points) Make a union function which takes in 2 lists as parameters and returns a list. It should return a list that contain all elements that are in either list. Your results list should contain no duplicates. For example, if the two lists are [1,5,6,5, 2] and [3,5, 1,9] then the result list is (1,5,6,2,3,9). Note that the list sizes don't have to be equal. Note that the input lists could have duplicates, but your...
1. Consider the sets: A = {a, b, c, d, e, f, h, j}, B = {a, b, i }, C = {f, h} and U = {a,b,c,d,e,f,g, h,i,j} a. Draw a Venn diagram and place each element in its appropriate region. Insert a photo of your diagram into your HW document. b. Is C a subset of A? Why? C. Is C a subset of B? Why? d. Is A a subset of B? Why? e. Are B and...
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the...