समुच्चय सिद्धांत में, समुच्चय A का पूरक उन तत्वों को संदर्भित करता है जो A में नहीं हैं। समुच्चय B के सापेक्ष A के सापेक्ष पूरक, जिसे समुच्चय A और B का अंतर भी कहा जाता है। हम इस सिद्धांत को यहाँ लागू करते हैं। पायथन में अंतर कार्य है।
एल्गोरिदम
Step 1 : first we create two user input list. A & B Step 2 : Insert A and B to a set. Step 3 : for finding the missing values of first list we apply difference function, difference of B from A. Step 4 : for finding the Additional values of first list we apply difference function, difference of A from B. Step 5 : Same procedure apply for Second list also.
उदाहरण कोड
#To find the missing and additional elements A=list() B=list() n1=int(input("Enter the size of the First List ::")) n2=int(input("Enter the size of the second List ::")) print("Enter the Element of first List ::") for i in range(int(n1)): k=int(input("")) A.append(k) print("Enter the Element of second List ::") for j in range(int(n2)): k1=int(input("")) B.append(k1) # prints the missing and additional elements in first list print("Missing values in first list:", (set(B).difference(A))) print("Additional values in first list:", (set(A).difference(B))) # prints the missing and additional elements in second list print("Missing values in second list:", (set(A).difference(B))) print("Additional values in second list:", (set(B).difference(A)))
आउटपुट
Enter the size of the First List :: 6 Enter the size of the second List :: 5 Enter the Element of first List :: 1 2 3 4 5 6 Enter the Element of second List :: 4 5 6 7 8 Missing values in first list: {7, 8} Additional values in first list: {1, 2, 3} Missing values in second list: {1, 2, 3} Additional values in second list: {7, 8}