English

Lucky Cars and the Quicksort Algorithm

Combinatorics 2023-06-23 v1

Abstract

Quicksort is a classical divide-and-conquer sorting algorithm. It is a comparison sort that makes an average of 2(n+1)Hn4n2(n+1)H_n - 4n comparisons on an array of size nn ordered uniformly at random, where Hn=i=1n1iH_n = \sum_{i=1}^n\frac{1}{i} is the nnth harmonic number. Therefore, it makes n![2(n+1)Hn4n]n!\left[2(n+1)H_n - 4n\right] comparisons to sort all possible orderings of the array. In this article, we prove that this count also enumerates the parking preference lists of nn cars parking on a one-way street with nn parking spots resulting in exactly n1n-1 lucky cars (i.e., cars that park in their preferred spot). For n2n\geq 2, both counts satisfy the second order recurrence relation fn=2nfn1n(n1)fn2+2(n1)! f_n=2nf_{n-1}-n(n-1)f_{n-2}+2(n-1)! with f0=f1=0f_0=f_1=0.

Cite

@article{arxiv.2306.13065,
  title  = {Lucky Cars and the Quicksort Algorithm},
  author = {Pamela E. Harris and Jan Kretschmann and J. Carlos Martínez Mori},
  journal= {arXiv preprint arXiv:2306.13065},
  year   = {2023}
}

Comments

8 pages, and 2 figures, to appear in The American Mathematical Monthly

R2 v1 2026-06-28T11:12:11.437Z