# Genericity

## Definition

An algorithmic problem, algorithm, abstract data structure, or implementation of a data structure is generic if one or more related types are left open in the definition. The choice of these types is deferred until the algorithm is called or an object of the data structure is created.

Remark: Typically, there are requirements on the open types. This means an open type must offer some methods with prescribed syntax and semantics. Quite different concepts to formulate and ensure syntactical requirements are implemented in the various programming languages that support genericity.

## Comparison

A comparison on a finite or infinite set $S$ is a binary relation $c:S\times S \rightarrow \{ -1,0,+1\}$ with the following properties:

• $c(x,x) = 0$ for all $x \in S$ (reflexivity),
• $c(x,y)=-c(y,x)$ for all $x,y \in S$ (anti-symmetry), and
• $(c(x,y) = 1 \land c(y,z) = 1) \Rightarrow c(x,z)=1$ for all $x,y,z \in S$ (transitivity).

For convenience, we write $x\lt y$ in case $c(x,y)=1$, $x\le y$ in case $c(x,y)\ge 0$, and so on.

### Remark

Note that $c(x,y)=0$ does not imply $x=y$. If $c(x,y)=0$ actually implies $x=y$ for all $x,y$, such a binary relation is usually called a total or linear order - as opposed to partial orders, in which $c(x,y)=0$ is possible for $x\neq y$. In the last case, we say $x$ and $y$ are incomparable.