Sets & Multisets
1. What is a Set?
Definition:
Set ek aisa well-defined collection of distinct elements hai, jisme koi bhi element repeat nahi hota. Yani har element unique hota hai aur ek hi baar set me appear hota hai.
Explanation:
-
Set ka order important nahi hota, matlab {1, 2, 3} aur {3, 2, 1} same set hai.
-
Elements kisi bhi type ke ho sakte hain: numbers, alphabets, objects, ya even strings.
-
Set me duplicate elements automatically remove ho jaate hain.
Example:
-
Set of numbers: {1, 2, 3, 4}
-
Set of alphabets: {'a', 'b', 'c'}
-
Set of strings: {"apple", "banana", "orange"}
2. Multiset Kya Hai? (Definition + Explanation)
Definition:
Multiset ek collection hai jisme elements repeat ho sakte hain. Matlab ek element ek se zyada baar appear ho sakta hai.
Explanation:
-
Order abhi bhi important nahi hota.
-
Duplicate elements allow kiye jaate hain.
-
Multiset ka size total elements count karta hai including duplicates.
Example:
-
Multiset of numbers: {1, 2, 2, 3, 3, 3}
-
Multiset of alphabets: {'a', 'a', 'b', 'b', 'b', 'c'}
3. Set ke Operations
-
Union (∪): Dono sets ke saare unique elements ka combination.
-
Example: {1,2} ∪ {2,3} = {1,2,3}
-
-
Intersection (∩): Dono sets me common elements.
-
Example: {1,2} ∩ {2,3} = {2}
-
-
Difference (-): Pehle set me jo elements hai aur dusre me nahi hai.
-
Example: {1,2,3} - {2,3,4} = {1}
-
-
Subset (⊆): Agar saare elements ek set ke dusre set me hain.
-
Example: {1,2} ⊆ {1,2,3} → True
-
-
Complement: Ek universal set ke hisaab se ek set ke bahar ke elements.
4. Multiset ke Operations
-
Union: Sab elements including duplicates.
-
Intersection: Minimum count of each common element.
-
Addition of elements: Duplicate allowed.
-
Removal of elements: Ek ya sab duplicates remove kar sakte hain.
5. Difference Between Set and Multiset
-
Set me elements unique hote hain, Multiset me duplicates allowed hote hain.
-
Set ka size = unique elements count, Multiset ka size = total elements count including duplicates.
-
Set ke operations simple hote hain, Multiset operations duplicates ke count ke hisaab se hote hain.
6. Use Cases
-
Set: Removing duplicates, membership testing, mathematical operations, fast lookup.
-
Multiset: Counting frequencies, bag of words in NLP, handling duplicate records, inventory management.
Conclusion:
Sets aur Multisets programming aur mathematics me fundamental concepts hain. Set se duplicate avoid kar sakte hain, aur Multiset se duplicate elements ka counting manage hota hai. Inhe samajhna important hai efficient algorithms aur data handling ke liye.
Comments
Post a Comment