Mathematics > Combinatorics
[Submitted on 22 Jun 2023]
Title:Lucky Cars and the Quicksort Algorithm
View PDFAbstract:Quicksort is a classical divide-and-conquer sorting algorithm. It is a comparison sort that makes an average of $2(n+1)H_n - 4n$ comparisons on an array of size $n$ ordered uniformly at random, where $H_n = \sum_{i=1}^n\frac{1}{i}$ is the $n$th harmonic number. Therefore, it makes $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 $n$ cars parking on a one-way street with $n$ parking spots resulting in exactly $n-1$ lucky cars (i.e., cars that park in their preferred spot). For $n\geq 2$, both counts satisfy the second order recurrence relation $ f_n=2nf_{n-1}-n(n-1)f_{n-2}+2(n-1)! $ with $f_0=f_1=0$.
References & Citations
Bibliographic and Citation Tools
Bibliographic Explorer (What is the Explorer?)
Connected Papers (What is Connected Papers?)
Litmaps (What is Litmaps?)
scite Smart Citations (What are Smart Citations?)
Code, Data and Media Associated with this Article
alphaXiv (What is alphaXiv?)
CatalyzeX Code Finder for Papers (What is CatalyzeX?)
DagsHub (What is DagsHub?)
Gotit.pub (What is GotitPub?)
Hugging Face (What is Huggingface?)
Papers with Code (What is Papers with Code?)
ScienceCast (What is ScienceCast?)
Demos
Recommenders and Search Tools
Influence Flower (What are Influence Flowers?)
CORE Recommender (What is CORE?)
arXivLabs: experimental projects with community collaborators
arXivLabs is a framework that allows collaborators to develop and share new arXiv features directly on our website.
Both individuals and organizations that work with arXivLabs have embraced and accepted our values of openness, community, excellence, and user data privacy. arXiv is committed to these values and only works with partners that adhere to them.
Have an idea for a project that will add value for arXiv's community? Learn more about arXivLabs.