0% found this document useful (0 votes)
30 views9 pages

VKDSL 1

The document describes operations performed on two sets s1 and s2 using an ADT for sets. Elements are added to and removed from the sets, their sizes and relationships are checked, and set operations like union, intersection and difference are performed.

Uploaded by

theredtomato11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views9 pages

VKDSL 1

The document describes operations performed on two sets s1 and s2 using an ADT for sets. Elements are added to and removed from the sets, their sizes and relationships are checked, and set operations like union, intersection and difference are performed.

Uploaded by

theredtomato11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Name : Saiprasad Nagappa Shivpuje

Class : SE Div : B Batch : C


Roll No. : 2102054

Assignment No. 1

Title: Create ADT that implement the "set" concept.

Problem Statement: Create ADT that implements the "set" concept and perform following
operations: a. Add (new Element) -Place a value into the set, b. Remove (element) Remove the
value c. Contains (element) Return true if element is in collection, d. Size () Return number of
values in collection Iterator () Return an iterator used to loop over collection, e. Intersection of two
sets, f. Union of two sets, g. Difference between two sets, h. Subset

Input :

s1 = []
s2 = []
def add(s):
a= int(input("Enter number of elements you want to insert: "))
for i in range (a):
ele = int(input("Enter element: "))
if ele not in s:
s.append(ele)

def display(s):
print(s)

def remove(s):
ele = int(input("Enter element you want to remove: "))
s.remove(ele)

def check(s):
ele = int(input("Enter element to check in set: "))
print(ele in s)

def size(s):
print(len(s))

def union(a,b):
result = []
for i in (a):
result.append(i)
for i in (b):
if i not in (result):
result.append(i)
return result

def intersection(a,b):
result = []
for i in (a):
for j in (b):
if(i == j):
result.append(i)
return result

def difference(a,b):
result = []
for i in (a):
if i not in (b):
result.append(i)
return result

def subset(a,b):
for i in (a):
if i not in (b):
return False
return True
def propersubset(a,b):
if (subset(a,b) == True and len(b)> len(a)):
print("S2 is proper subset of s1")
else:
print("S2 is not proper subset of s1")

while True:
print("""
Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit
""")
choice = int(input("Enter your choice (0-15): "))
if choice == 1:
add(s1)
elif choice == 2:
add(s2)
elif choice == 3:
display(s1)
elif choice == 4:
display(s2)
elif choice == 5:
remove(s1)
print("Remaining elements in Set 1 : ")
display(s1)
elif choice == 6:
remove(s2)
print("Remaining elements in Set 2 : ")
display(s2)
elif choice == 7:
check(s1)
elif choice == 8:
check(s2)
elif choice == 9:
size(s1)
elif choice == 10:
size(s2)
elif choice == 11:
print(union(s1, s2))
elif choice == 12:
print(intersection(s2, s1))
elif choice == 13:
print(difference(s1, s2))
elif choice == 14:
print(subset(s2, s1))
elif choice == 15:
propersubset(s2,s1)
elif choice == 0:
break
else:
print("Invalid choice. Please enter a number between 0 and 15.")

Output :

Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit
Enter your choice (0-15): 1
Enter number of elements you want to insert: 4
Enter element: 2
Enter element: 3
Enter element: 4
Enter element: 6

Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit

Enter your choice (0-15): 2


Enter number of elements you want to insert: 3
Enter element: 2
Enter element: 3
Enter element: 4

Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit

Enter your choice (0-15): 3


[2, 3, 4, 6]
Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit

Enter your choice (0-15): 4


[2, 3, 4]

Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit

Enter your choice (0-15): 7


Enter element to check in set: 2
True

Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit

Enter your choice (0-15): 10


3

Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit

Enter your choice (0-15): 11


[2, 3, 4, 6]

Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit
Enter your choice (0-15): 12
[2, 3, 4]

Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit

Enter your choice (0-15): 13


[6]

Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit

Enter your choice (0-15): 14


True

Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit

Enter your choice (0-15): 15


S2 is proper subset of s1

Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit

Enter your choice (0-15): 5


Enter element you want to remove: 2
Remaining elements in Set 1 :
[3, 4, 6]

Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit

Enter your choice (0-15): 6


Enter element you want to remove: 3
Remaining elements in Set 2 :
[2, 4]

Menu:
1. Add element to set s1
2. Add element to set s2
3. Display set s1
4. Display set s2
5. Remove from set s1
6. Remove from set s2
7. Check element in set s1
8. Check element in set s2
9. Size of set s1
10. Size of set s2
11. Union of sets
12. Intersection of sets s2 and s1
13. Difference of sets s1 and s2
14. Check if s2 is a subset of s1
15. Check if s2 is proper subset of s1
0. Exit

Enter your choice (0-15): 0

You might also like