Unit 1 Lecture 4 Multiset Multiset It is

  • Slides: 7
Download presentation
Unit 1 Lecture 4 Multiset

Unit 1 Lecture 4 Multiset

Multiset • It is generalization of set, it is collection of distinct objects. •

Multiset • It is generalization of set, it is collection of distinct objects. • In multiset, an object can occur more than once. Eg- the collection of books in a library can contain multiple copies of the same books such a collection is multiset. • It is also called as bags, heap or bunch or weighted set.

Multiset • To distinguish a set and a multiset, we denote the letter by

Multiset • To distinguish a set and a multiset, we denote the letter by enclosing the elements within square brackets eg. [a , b , a] is m set. • Multiplicity of M set: Ø Multiplicity of mset is defined as the number of times the elements appears in the mset. Thus in the mset [a, b, a, a] multiplicity of a is 3 while multiplicity of b is 1. Ø If an element does not belongs to mset, its multiplicity is zero.

Multiset • We can characterize a multiset as a pair (A, µ) where A

Multiset • We can characterize a multiset as a pair (A, µ) where A is the generic set and µ is the multiplicity function defined asµ: A {1, 2, 3, ……. } So that µ(a)=k where k is the number of times the element a occur in the mset. Eg. If [a, b, c, c, a, c] is the mset µ(a)=2, µ(b)=1, µ( c)=3.

Mset operations 1. Equality of mset: If number of occurrences of each element is

Mset operations 1. Equality of mset: If number of occurrences of each element is the same in both the msets, then the msets are equal. Eg [a, b, a, a]=[a, a, b, a] However [a, b, a]≠ [a, b] 2. Multisubset(msubset): A multiset A is said to be a multi subset of B if multiplicity of each element in A is less or equal to its multiplicity in B. Eg [1, 2, 2, 3] C [1, 1, 1, 2, 2, 3]

Mset operations 3. Union of mset: If A & B are two msets, then

Mset operations 3. Union of mset: If A & B are two msets, then AUB is the mset such that for each element x ∈ AUB, µ(x)=max[µA (x), µB (x)] Eg A=[a, b, b, c], B=[b, c, c, d] Then AUB=[a, b, b, c, c, d] 4. Intersection of Mset: If A & B are two msets then A ∩ B is defined as the mset such that for each element x ∈ A ∩ B, µ(x)=min[µA (x), µB (x)] Eg. A=[1, 1, 1, 2, 2, 3] B=[1, 2, 2, 2, 3, 3] then A ∩ B=[1, 2, 2, 3]

Mset operations 5. Difference of msets: for multisets A & B the difference A-B

Mset operations 5. Difference of msets: for multisets A & B the difference A-B is an mset such tht for each x ∈ A-B, µ(x)=µA (x)- µB (x), if the difference is greater than zero. µ(x)= 0 if difference is zero or negative from the above definition it follows that A-A = φ[ ] Eg. A=[a, b, c, c, c], B=[b, c, d, d] then A-B=[a, c, c]