Skip to content

Multiset Abstract Data Type

In computer science, a set is an abstract data type that can store distinct values, without any particular order.

Core Idea

In computer science, a multiset, or bag, is an abstract data type that generalizes the set: like a set it stores values without any particular order, but unlike a set it allows repeated ("equal") values. The term is used in two distinct senses. In one, equal values are treated as identical and are simply counted, so the multiset records each distinct value with its multiplicity; in this counting sense a multiset can be seen as a function from the element type to the non-negative integers, generalizing the identification of a set with its indicator function, and some libraries, such as Python's, even allow negative counts. In the other, equal values are treated only as equivalent and are stored as distinct items: a multiset of people grouped by age keeps every (name, age) pair, so selecting an age returns all the people of that age.

As with sets, multisets are commonly implemented with hash tables or trees, which give different performance characteristics; C++'s Standard Template Library, for example, provides a sorted multiset built on a self-balancing binary search tree and an unsorted multiset built on a hash table. Multisets also arise naturally in databases: an SQL selection of rows from a table generally yields a multiset unless the DISTINCT keyword is used or the selection includes a key.

How would you explain it like I'm…

Bag With Repeats

A set is like a box of toys where each kind of toy can only be in there once. A multiset, also called a bag, is a box where you can have the same toy many times, like three red cars. The order of the toys in the bag doesn't matter. You can either just count how many of each toy you have, or keep every single toy as its own thing.

Sets That Allow Doubles

In computer science, a set is a collection of things with no order and no repeats. A multiset, also called a bag, is like a set except repeats are allowed. Sometimes a multiset just counts how many of each thing it has, like '3 apples, 2 pears.' Other times it keeps every item separately because they're only similar, not identical, like keeping each person when you group people by age. Programs build multisets using structures like hash tables or trees. Database searches often give back multisets because the same row values can show up more than once.

Unordered Collection with Duplicates

A multiset, or bag, is an abstract data type that generalizes a set: it stores values without order but allows repeated equal values. The term has two senses. In the counting sense, equal values are identical and the multiset records each distinct value with its count, so it acts like a function from elements to non-negative integers (some libraries, such as Python's, even allow negative counts). In the other sense, equal values are only equivalent and are stored as separate items, so grouping people by age keeps every (name, age) pair. Multisets are often implemented with hash tables or trees, which perform differently. An SQL query generally returns a multiset unless you use DISTINCT or include a key.

 

In computer science a multiset (bag) is an abstract data type generalizing the set: values are unordered, but repeated ('equal') values are permitted. Two senses exist. In the counting sense, equal values are identical and simply counted, so the multiset records each distinct value with its multiplicity and can be viewed as a function from the element type to the non-negative integers, generalizing a set's indicator function; some libraries, such as Python's, even permit negative counts. In the other sense, equal values are merely equivalent and stored as distinct items: a multiset of people keyed by age retains every (name, age) pair, so selecting an age returns all people of that age. Like sets, multisets are commonly implemented with hash tables or trees, with different performance characteristics; C++'s STL offers a sorted multiset on a self-balancing binary search tree and an unsorted multiset on a hash table. In databases, an SQL selection of rows generally yields a multiset unless DISTINCT is used or the selection includes a key.

Structural Signature

Sig role-phrases:

  • Defining carrier — In type theory, sets are generally identified with their indicator function (characteristic function): accordingly, a set of values of type \(A\) may be denoted by \(2^{A}\) or \(\mathcal{P}(A)\).
  • Constitutive relation — (Subtypes and subsets may be modeled by refinement types, and quotient sets may be replaced by setoids.) The characteristic function \(F\) of a set \(S\) is defined as \(F(x) = \begin{cases} 1, & \mbox{if } x \in S \\ 0, & \mbox{if } x \not \in S \end{cases}\).
  • Operating condition — Typical operations that may be provided by a static set structure S are.
  • Recognition evidence — create_from(collection) : creates a new set structure containing all the elements of the given collection or all the elements returned by the given iterator.
  • Admissible variation — A generalization of the notion of a set is that of a multiset or bag, which is similar to a set but allows repeated ("equal") values (duplicates).
  • Characteristic consequence — The set of all bags over type T is given by the expression bag T.
  • Failure boundary — If by multiset one considers equal items identical and simply counts them, then a multiset can be interpreted as a function from the input domain to the non-negative integers (natural numbers), generalizing the identification of a set with its indicator function.

What It Is Not

  • Not the whole field of abstract data types. The node requires the specific identity stated by In computer science, a set is an abstract data type that can store distinct values, without any particular order.
  • Not an over-broad reading. Where a multiset data structure is not available, a workaround is to use a regular set, but override the equality predicate of its items to always return "not equal" on distinct objects (however, such will still not be able to store multiple occurrences of the same object) or use an associative array mapping the values to their integer multiplicities (this will not be able to distinguish between equal elements at all).
  • Not an over-broad reading. Unlike most other collection types, rather than retrieving a specific element from a set, one typically tests a value for membership in a set.
  • Not an over-broad reading. add(S,x) : adds the element x to S, if it is not present already.
  • Not automatically Multimap. Retrieval proximity does not establish equivalence; the two identities must be compared by carrier, operation, and failure boundary.

Scope of Application

Multiset Abstract Data Type applies literally inside abstract data types wherever the source-defined carrier and relation can be established. Its documented habitats include:

  • Multisets in SQL. SQL allows the selection of rows from a relational table: this operation will in general yield a multiset, unless the keyword DISTINCT is used to force the rows to be all different, or the selection includes the primary (or a candidate) key.
  • Type theory. In type theory, sets are generally identified with their indicator function (characteristic function): accordingly, a set of values of type \(A\) may be denoted by \(2^{A}\) or \(\mathcal{P}(A)\).
  • Type theory. (Subtypes and subsets may be modeled by refinement types, and quotient sets may be replaced by setoids.) The characteristic function \(F\) of a set \(S\) is defined as \(F(x) = \begin{cases} 1, & \mbox{if } x \in S \\ 0, & \mbox{if } x \not \in S \end{cases}\).
  • Static sets. iterate(S) : returns a function that returns one more value of S at each call, in some arbitrary order.
  • Additional operations. Functionally, the mutator pop can be interpreted as the pair of selectors (pick, rest), where rest returns the set consisting of all elements except for the arbitrary element.
  • Additional operations. map(F,S) : returns the set of distinct values resulting from applying function F to each element of S.

Outside abstract data types, the name should be retained only when these same operational conditions survive; otherwise the comparison belongs to the broader parent Measurement or should be marked as analogy.

Clarity

A clear use of Multiset Abstract Data Type names the carrier, the operative relation, and the conditions under which the source treats the identity as present. The minimal definition is In computer science, a set is an abstract data type that can store distinct values, without any particular order. The strongest recognition evidence is: create_from(collection) : creates a new set structure containing all the elements of the given collection or all the elements returned by the given iterator. A report should distinguish that evidence from a proxy, consequence, or common implementation. It should also state the qualification Where a multiset data structure is not available, a workaround is to use a regular set, but override the equality predicate of its items to always return "not equal" on distinct objects (however, such will still not be able to store multiple occurrences of the same object) or use an associative array mapping the values to their integer multiplicities (this will not be able to distinguish between equal elements at all). so that a reader can reproduce the classification rather than infer it from topical resemblance.

Manages Complexity

Multiset Abstract Data Type compresses multiple abstract data types details into a stable diagnostic relation. The source shows both the central mechanism—(Subtypes and subsets may be modeled by refinement types, and quotient sets may be replaced by setoids.) The characteristic function \(F\) of a set \(S\) is defined as \(F(x) = \begin{cases} 1, & \mbox{if } x \in S \\ 0, & \mbox{if } x \not \in S \end{cases}\).—and the practical consequence—the set of all bags over type T is given by the expression bag T. This compression makes cases comparable while leaving parameters, conventions, exceptions, and evidential quality explicit. It is lossy by design: local history and implementation details may be omitted only when they do not alter the defining relation.

Abstract Reasoning

  1. Type the carrier. Identify the abstract data types entities to which the claim applies.
  2. State the relation. Use the source-grounded identity: In computer science, a set is an abstract data type that can store distinct values, without any particular order.
  3. Check operation and conditions. Typical operations that may be provided by a static set structure S are.
  4. Demand recognition evidence. create_from(collection) : creates a new set structure containing all the elements of the given collection or all the elements returned by the given iterator.
  5. Test variation. Change an implementation or setting while preserving a generalization of the notion of a set is that of a multiset or bag, which is similar to a set but allows repeated ("equal") values (duplicates).
  6. Run the collapse test. Remove the defining operation; if the label still seems equally apt, only a topic or correlate was retained.
  7. Reduce cautiously. When the specialist conditions cannot be carried, route the residual comparison to Measurement.

Knowledge Transfer

Within the home domain. Knowledge about Multiset Abstract Data Type transfers literally when a new case preserves the same carrier type, relation, and recognition test. SQL allows the selection of rows from a relational table: this operation will in general yield a multiset, unless the keyword DISTINCT is used to force the rows to be all different, or the selection includes the primary (or a candidate) key. In type theory, sets are generally identified with their indicator function (characteristic function): accordingly, a set of values of type \(A\) may be denoted by \(2^{A}\) or \(\mathcal{P}(A)\).

Beyond the home domain. No canonical parent is asserted for Multiset Abstract Data Type. An outside case receives the specialist name only when the same typed roles and rejection conditions can be filled literally; otherwise the comparison remains an analogy pending later graph densification.

Examples

Canonical

For example, an abstract heap can be viewed as a set structure with a min(S) operation that returns the element of smallest value. This case is canonical because it supplies a concrete carrier and lets the defining relation be checked rather than merely named.

Mapped back: carrier → the entities in the documented case; operation → In computer science, a set is an abstract data type that can store distinct values, without any particular order; recognition evidence → create_from(collection) : creates a new set structure containing all the elements of the given collection or all the elements returned by the given iterator

Applied / In Practice

There are many other operations that can (in principle) be defined in terms of the above, such as. The applied case shows how the identity is used under a second setting or qualification while keeping the same operative relation.

Mapped back: changed setting → Additional operations; invariant → In computer science, a set is an abstract data type that can store distinct values, without any particular order; boundary → the case exits the class when where a multiset data structure is not available, a workaround is to use a regular set, but override the equality predicate of its items to always return "not equal" on distinct objects (however, such will still not be able to store multiple occurrences of the same object) or use an associative array mapping the values to their integer multiplicities (this will not be able to distinguish between equal elements at all)

Structural Tensions

T1 — Stable identity versus admissible variation. Where a multiset data structure is not available, a workaround is to use a regular set, but override the equality predicate of its items to always return "not equal" on distinct objects (however, such will still not be able to store multiple occurrences of the same object) or use an associative array mapping the values to their integer multiplicities (this will not be able to distinguish between equal elements at all). The tension matters because emphasizing only one side either dissolves the identity or overstates what the evidence and domain conventions warrant.

Diagnostic: Which changes preserve the defining relation, and which replace it?

T2 — Recognition versus proxy. Unlike most other collection types, rather than retrieving a specific element from a set, one typically tests a value for membership in a set. The tension matters because emphasizing only one side either dissolves the identity or overstates what the evidence and domain conventions warrant.

Diagnostic: Does the cited evidence establish the identity or only a correlated sign?

T3 — Definition versus implementation. add(S,x) : adds the element x to S, if it is not present already. The tension matters because emphasizing only one side either dissolves the identity or overstates what the evidence and domain conventions warrant.

Diagnostic: Is the observed implementation constitutive, optional, or merely common?

T4 — Scope versus overextension. Functionally, the mutator pop can be interpreted as the pair of selectors (pick, rest), where rest returns the set consisting of all elements except for the arbitrary element. The tension matters because emphasizing only one side either dissolves the identity or overstates what the evidence and domain conventions warrant.

Diagnostic: Can every claimed application fill the same typed roles without metaphor?

T5 — Transfer versus domain accent. In type theory, sets are generally identified with their indicator function (characteristic function): accordingly, a set of values of type \(A\) may be denoted by \(2^{A}\) or \(\mathcal{P}(A)\). The tension matters because emphasizing only one side either dissolves the identity or overstates what the evidence and domain conventions warrant.

Diagnostic: Does the receiving case instantiate Multiset Abstract Data Type literally, co-instantiate Measurement, or only resemble it?

T6 — Autonomy versus reduction. (Subtypes and subsets may be modeled by refinement types, and quotient sets may be replaced by setoids.) The characteristic function \(F\) of a set \(S\) is defined as \(F(x) = \begin{cases} 1, & \mbox{if } x \in S \\ 0, & \mbox{if } x \not \in S \end{cases}\). The tension matters because emphasizing only one side either dissolves the identity or overstates what the evidence and domain conventions warrant.

Diagnostic: What does Multiset Abstract Data Type distinguish that the broader parent Measurement leaves together?

Structural–Framed Character

Multiset Abstract Data Type is mixed or framed-leaning. Its structural side is the repeatable organization summarized by In computer science, a set is an abstract data type that can store distinct values, without any particular order. Its framed side is the abstract data types vocabulary that fixes the carrier, evidence, exceptions, and admissible transformations.

Evaluative weight: the identity can be stated descriptively even when applications carry practical stakes. Human-practice dependence: the source-grounded carrier determines whether the relation exists independently or is constituted by a practice. Institutional origin: disciplinary conventions stabilize the name and test. Vocabulary portability: Typical operations that may be provided by a static set structure S are. Import versus recognition: literal transfer requires the same mechanism; shape alone is analogy.

Its portable skeleton is Measurement. Its character: a recurring specialist identity whose thin organization can be abstracted, while its operational meaning remains domain-bound.

Structural Core vs. Domain Accent

What is skeletal. In computer science, a set is an abstract data type that can store distinct values, without any particular order. The stable skeleton is the typed relation expressed in that definition and the entry's recognition and collapse tests. The source identifies these operative conditions: In type theory, sets are generally identified with their indicator function (characteristic function): accordingly, a set of values of type \(A\) may be denoted by \(2^{A}\) or \(\mathcal{P}(A)\). (Subtypes and subsets may be modeled by refinement types, and quotient sets may be replaced by setoids.) The characteristic function \(F\) of a set \(S\) is defined as \(F(x) = \begin{cases} 1, & \mbox{if } x \in S \\ 0, & \mbox{if } x \not \in S \end{cases}\). It further constrains recognition and variation through: Typical operations that may be provided by a static set structure S are. createfrom(collection) : creates a new set structure containing all the elements of the given collection or all the elements returned by the given iterator.

What is domain-bound. abstract data types supplies the operative entities, technical vocabulary, warrants, and exceptions that make Multiset Abstract Data Type literal. Its documented scope includes the condition that SQL allows the selection of rows from a relational table: this operation will in general yield a multiset, unless the keyword DISTINCT is used to force the rows to be all different, or the selection includes the primary (or a candidate) key. Another bounded application condition is that In type theory, sets are generally identified with their indicator function (characteristic function): accordingly, a set of values of type \(A\) may be denoted by \(2^{A}\) or \(\mathcal{P}(A)\). These are not decorative examples; they determine which carrier and evidence can fill the abstraction's roles.

Why no parent is asserted. Removing those specialist details does not currently yield one live catalog node that is a necessary genus for every instance. The entry is therefore approved as unparented rather than attached by topical resemblance. Its collapse evidence remains specific—A generalization of the notion of a set is that of a multiset or bag, which is similar to a set but allows repeated ("equal") values (duplicates).—and future graph densification may discover a defensible relation only if it preserves that boundary.

  • Approved unparented node. No current live node supplies a defensible necessary genus or structural prerequisite for Multiset Abstract Data Type. The reviewed identity is: In computer science, a set is an abstract data type that can store distinct values, without any particular order. The accelerated suggestion was declined because topical or lexical similarity does not establish hierarchy; the node is admitted without a parent pending later graph densification.
  • Related reasoning operations. Evidence, representation, comparison, classification, transformation, or evaluation may participate in particular cases, but participation does not make any one of them a necessary parent of every instance.

Neighborhood in Abstraction Space

Multiset Abstract Data Type sits in a moderately populated region (48th percentile for distinctiveness): it has near-neighbors but no dense thicket of look-alikes.

Family — Algebraic Structures & Order Relations (18 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14

Not to Be Confused With

  • Measurement. The parent omits the specialist differentia. Tell: Can the case establish In computer science, a set is an abstract data type that can store distinct values, without any particular order?
  • Multimap. A multimap is an abstract data type that associates one key with zero or more values while preserving key-based insertion, lookup, removal, and iteration semantics beyond an ordinary one-value map. Tell: Which entry's carrier, operation, and failure condition are satisfied?
  • Index set (computability). A set of program indices whose membership depends only on the partial computable function or computably enumerable set denoted by the index, not on the particular code chosen. Tell: Which entry's carrier, operation, and failure condition are satisfied?
  • Set theoretic programming. A programming paradigm that treats sets, relations, mappings, and high-level set operations as primary data and control abstractions. Tell: Which entry's carrier, operation, and failure condition are satisfied?
  • A measurement, proxy, or consequence. Those may provide evidence without being the identity. Tell: Would Multiset Abstract Data Type remain present if the detector or downstream effect changed?
  • A metaphorical analogue. A similar shape outside abstract data types lacks the specialist mechanism. Tell: Do the native roles transfer literally, or only the parent Measurement?

References

  • Frozen Wikipedia discovery revision: https://en.wikipedia.org/wiki/Set_(abstract_data_type) (revision 1335354914).