Sets and sequences

From Algowiki
Jump to: navigation, search

Sets and multisets

  1. In a proper set (or set, for short), each element occurs at most once, that is, no duplications of elements within a set.
  2. In contrast, in a multiset, an element may occur more than once. The multiplicity of an element in a multiset is the number of its occurrences in that multiset.

Remarks:

  1. In computer science, as opposed to math, sets and multisets are usually dynamic, that is, elements may be inserted and removed.
  2. Uniting two multisets amounts to adding the multiplicities. To intersect two multisets, take the minimum of the multiplicities. (Multi)set difference is realized by subtracting the multiplicities in the subtrahend from the multiplicities in the minuend.

Maximal and minimal sets

Let be a set of (multi)sets.

  1. A set is inclusion-minimal (resp., inclusion-maximal) in if (resp., ) for no .
  2. A set is cardinality-minimal (resp., cardinality-maximal) in if (resp., ) for no .

Remark: Typically, is given as all subsets of a ground set that fulfill a certain property.

Ordered and sorted sequences

An ordered sequence (or sequence, for short) is given by

  1. a number , its length,
  2. some component type , and
  3. a mapping .

We say that are the positions in the sequence (a.k.a. the indexes). The element of sequence at position is denoted by . The element is the head of , and the element is the tail of .

Consider a comparison on . Then a sequence of length is sorted with respect to , if for all .

Remarks:

  1. Note that the first position is , not , as opposed to array indexes in many popular programming languages such as C, C++, and Java.
  2. Like sets and multisets, sequences are dynamic.

Singleton, pair, triple, quadruple

A set, multiset or sequence with only one, two, three, or four elements is called a singleton, pair, triple, and quadruple, respectively.

Stacks and queues

  1. A stack (a.k.a. LIFO queue, LIFO = last-in-first-out) is a dynamic ordered sequence such that new elements may only be inserted before the head (a.k.a. top), and no element except for the current head may be accessed and removed.
  2. A queue (a.k.a. FIFO queue, FIFO = first-in-first-out) is a dynamic ordered sequence such that new elements may only be inserted at the end (that is, after the current tail), and no element except for the head may be accessed and removed.

Remark: For fast access, an implementation of a FIFO queue should maintain an additional pointer to the tail. To update this pointer after an append, simply move it one step forward in the sequence.

Maps

A map is given by

  1. a number , its size,
  2. a key type and a value type ,
  3. a finite subset (a proper set) , the map's keys, and
  4. a mapping , which assigns a value to each key in the map.

Like sets, multisets and sequences, maps are dynamic in computer science.

Remark: A sequence may also implement a map, namely if its component type is and each value of occurs at most once.

Partitions

Let be a finite or infinite set of positive integral numbers.

  1. A partition of a finite or infinite set is a family of subsets of such that
    1. for all , , and
    2. .
  2. If is finite, we speak of a -partition, where .
  3. In particular, if , we speak of a bipartition.