### Abstract

Counting sort is a well-known algorithm that sorts objects of any kind mapped to integer keys, or else to keys in one-to-one correspondence with some subset of the integers (e.g. alphabet letters). However, it is suitable for direct use, viz. not just as a subroutine of another sorting algorithm (e.g. radix sort), only if the key range is not significantly larger than the number of the objects to be sorted. This paper describes a tail-recursive generalization of counting sort making use of a bounded number of counters, suitable for direct use in case of a large, or even infinite key range of any kind, subject to the only constraint of being a subset of an arbitrary linear order. After performing a pen-and-paper analysis of how such algorithm has to be designed to maximize its efficiency, this paper formalizes the resulting generalized counting sort (GCsort) algorithm and then formally proves its correctness properties, namely that (a) the counters' number is maximized never exceeding the fixed upper bound, (b) objects are conserved, (c) objects get sorted, and (d) the algorithm is stable.

### License

BSD License

### Topics

- Computer science/Algorithms
- Computer science/Functional programming

### Session Generalized_Counting_Sort

- Algorithm
- Conservation
- Sorting
- Stability

## Cite

×

Generalized_Counting_Sort-AFP

    @article{Generalized_Counting_Sort-AFP,
      author  = {Pasquale Noce},
      title   = {An Efficient Generalization of Counting Sort for Large, possibly Infinite Key Ranges},
      journal = {Archive of Formal Proofs},
      month   = {December},
      year    = {2019},
      note    = {\url{https://isa-afp.org/entries/Generalized_Counting_Sort.html},
                 Formal proof development},
      ISSN    = {2150-914x},
    }

Download

## Download

× Download latest

Older releases:

- Sep 13, 2023 : Isabelle2023
- Oct 27, 2022 : Isabelle2022
- Dec 14, 2021 : Isabelle2021-1
- Feb 23, 2021 : Isabelle2021
- Apr 18, 2020 : Isabelle2020
- Dec 9, 2019 : Isabelle2019