Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Give me a practical use-case of Multi-set

I would like to know a few practical use-cases (if they are not related/tied to any programming language it will be better).I can associate Sets, Lists and Maps to practical use cases.

For example if you wanted a glossary of a book where terms that you want are listed alphabetically and a location/page number is the value, you would use the collection TreeMap(OrderedMap which is a Map)

Somehow, I can't associate MultiSets with any "practical" usecase. Does someone know of any uses?

http://en.wikipedia.org/wiki/Multiset does not tell me enough :)

PS: If you guys think this should be community-wiki'ed it is okay. The only reason I did not do it was "There is a clear objective way to answer this question".

like image 848
Kannan Ekanath Avatar asked Mar 26 '10 15:03

Kannan Ekanath


People also ask

What is multiset used for?

In mathematics, a multiset (or bag, or mset) is a modification of the concept of a set that, unlike a set, allows for multiple instances for each of its elements. The number of instances given for each element is called the multiplicity of that element in the multiset.

What is multi set in C++?

Multisets are a type of associative containers similar to the set, with the exception that multiple elements can have the same values. Some Basic Functions associated with multiset: begin() – Returns an iterator to the first element in the multiset –> O(1)

What is the difference between set and multiset?

The essential difference between the set and the multiset is that in a set the keys must be unique, while a multiset permits duplicate keys.

How does multiset store data?

In case of MultiSet also the data is stored in sorted order. In Set duplicate values are not allowed to get stored. On other hand in case of MultiSet we can store duplicate values. In case of Set, one cannot change the value once it gets inserted however we can delete or insert it again.


1 Answers

Lots of applications. For example, imagine a shopping cart. That can contain more than one instance of an item - i.e. 2 cpu's, 3 graphics boards, etc. So it is a Multi-set. One simple implementation is to also keep track of the number of items of each - i.e. keep around the info 2 cpu's, 3 graphics boards, etc.

I'm sure you can think of lots of other applications.

like image 149
Larry Watanabe Avatar answered Oct 01 '22 07:10

Larry Watanabe