From my understanding, both lists and multisets are collections of ordered values in which values can occur more than once. Is there any difference?
No, lists and multisets are different. Order matters in lists, and doesn't in multisets.
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.
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.
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.
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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With