Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a list and a multiset?

From my understanding, both lists and multisets are collections of ordered values in which values can occur more than once. Is there any difference?

like image 910
Aaron Avatar asked Mar 10 '13 23:03

Aaron


People also ask

Is a multiset a list?

No, lists and multisets are different. Order matters in lists, and doesn't in multisets.

What is the difference between a set and a 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. This is analogous to the situation with maps and multimaps.

What is the difference between listing and sequence?

A list is a sequence but a sequence is not necessarily a list. A sequence is any type that supports the sequence interface ("protocol"). Sequence types describe a functional superset.

What is a 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.


2 Answers

No, lists and multisets are different. Order matters in lists, and doesn't in multisets.

(list 1 2 3 2) != (list 2 1 3 2)
(multiset 1 2 2 3) == (multiset 1 3 2 2)
like image 138
tom Avatar answered Jan 03 '23 20:01

tom


Besides order, each container has it own set of available methods and their complexity. For example, searching in a list is o(n) (you'll have to check every element until you find the one). Searching in multiset is o(log(n)). It is usually implemented as a red-black tree to fit this requirement

like image 41
Dmitry Galchinsky Avatar answered Jan 03 '23 20:01

Dmitry Galchinsky