Affiliation:
1. University of Copenhagen, Copenhagen, Denmark
Abstract
We introduce the notion of
discrimination
as a generalization of both sorting and partitioning and show that worst-case linear-time discrimination functions (discriminators) can be defined
generically
, by (co-)induction on an expressive language of
order denotations
. The generic definition yields discriminators that generalize both distributive sorting and multiset discrimination. The generic discriminator can be coded compactly using list comprehensions, with order denotations specified using Generalized Algebraic Data Types (GADTs). A GADT-free combinator formulation of discriminators is also given.
We give some examples of the uses of discriminators, including a new most-significant-digit lexicographic sorting algorithm.
Discriminators generalize binary comparison functions: They operate on
n
arguments at a time, but do not expose more information than the underlying equivalence, respectively ordering relation on the arguments. We argue that primitive types with equality (such as references in ML) and ordered types (such as the machine integer type), should expose their equality, respectively standard ordering relation, as discriminators: Having
only
a binary equality test on a type requires Θ(
n
2
) time to find all the occurrences of an element in a list of length
n
, for each element in the list, even if the equality test takes only constant time. A discriminator accomplishes this in linear time. Likewise, having only a (constant-time) comparison function requires Θ(
n
log
n
) time to sort a list of
n
elements. A discriminator can do this in linear time.
Publisher
Association for Computing Machinery (ACM)
Subject
Computer Graphics and Computer-Aided Design,Software
Cited by
1 articles.
订阅此论文施引文献
订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献