Let us suppose that n cars enter a one-way street with n parking spaces marked \(1,2,\ldots ,n\), in that order, and each driver intends to park in a particular spot. Say, the ith driver wishes to park in the spot marked \(p(i)\in [n]\), where [n] denotes the set \(\{1,2,\ldots ,n\}\).

Suppose that if driver i finds his favorite spot free, he parks there, but if he finds it occupied by any of the previous \(i-1\) drivers, he looks for the next free space after spot p(i) for parking, and if none exists, he leaves without parking. For which functions \({\textbf{p}}:[n]\rightarrow [n]\) is it possible for all the drivers to park? Let us call such functions parking functions of length n.Footnote 1

The answer to this question was given by Konheim and Weiss [3] as follows: Let

$$\begin{aligned} \big (p(1),\ldots ,p(n)\big )^{\uparrow } \end{aligned}$$

denote the nondecreasing rearrangementFootnote 2 of

$$\begin{aligned} \big (p(1),\ldots ,p(n)\big )\,. \end{aligned}$$

If we set

$$\begin{aligned} {\textbf{q}}=(q_1,\ldots ,q_n) =\big (p(1),\ldots ,p(n)\big )^{\uparrow }\,, \end{aligned}$$

then the parking functions are those for which

$$\begin{aligned}&q_i\le i,\text { for every }i\in [n]. \end{aligned}$$
(1)

In this article, we are mainly interested in the subclass of prime parking functions, which are those \({\textbf{p}}\) such thatFootnote 3

$$\begin{aligned}&q_i< i\text { for every }i\in [n]\text { with }i>1\,. \end{aligned}$$
(2)

For an example of a parking function, suppose that \(n=15\) and take

$$\begin{aligned} {\textbf{a}}:=(3, 13, 6, 3, 7, 3, 2, 1, 10, 11, 6, 7, 14, 10, 11)\,, \end{aligned}$$

which takes \(1\mapsto 3\), \(2\mapsto 13\), etc. Then all cars can park in the previously described sense. In fact, the parking goes as follows:

figure a

And indeed,

$$\begin{aligned} {\textbf{a}}^\uparrow =(1, 2, 3, 3, 3, 6, 6, 7, 7, 10, 10, 11, 11, 13, 14)\,, \end{aligned}$$

which is componentwise less than or equal to \((1,2,\ldots ,15)\).

Parking functions occur when we consider the set of hyperplanes in \({\mathbb {R}}^n\) defined by the equations \(x_i =x_j + k\), where \(1\le i<j\le n\) and \(k=0,1\), all of which contain a line parallel to the line \(\ell \) with equation \(x_1=x_2=\cdots =x_n\). Hence, we may represent each hyperplane by its intersection with a given hyperplane orthogonal to \(\ell \), for example, the hyperplane with equation \(x_1+x_2+\cdots +x_n=0\) (Figure 1).

Figure 1.
figure 1

Representation of the hyperplane arrangements in dimensions 2 (left) and 3 (right).

Label the region \(R_0\) defined by \( x_1>x_2>\cdots>x_n>x_1+1 \) with \( (1,1,\ldots ,1)\in {\mathbb {Z}}^n\). Given regions R and \(R'\) separated by the unique hyperplane H such that R and \(R_0\) are on the same side of H, give to \(R'\) the label of R but add 1 to one coordinate: the ith coordinate if H is defined by an equation of the form \( x_i=x_j \), \(i<j\), and the jth coordinate if H is defined by an equation of the form \( x_i=x_j+1 \).

Pak and Stanley showed [4] that the labels thus defined are exactly the parking functions of length n. We proved [1] that the prime parking functions are the Pak–Stanley labels of the relatively bounded regions (shaded in Figure 1, where the cases \(n=2\) and \(n=3\) are represented, the first one directly, and both by projecting, as explained above).

Our Main Theorem

Let \(\text {PF}_{n}\) be the set of parking functions of length n, and \(\text {PF}'_{n}\subseteq \text {PF}_{n}\) the set of prime parking functions of length n. We know that

$$\begin{aligned} |\text {PF}_{n}|&=(n+1)^{n-1}\,, \end{aligned}$$
(3)
$$\begin{aligned} |\text {PF}'_{n}|&=(n-1)^{n-1}\,. \end{aligned}$$
(4)

The goal of this paper is to prove (4) in a simple and original manner, as a direct consequence of Theorem 1 below.

Prime parking functions were introduced by Gessel, who proved (4) through generating functions (cf. [5, Exercise 5.49f]). Soon thereafter, Kalikow [2, p. 37] gave a direct proof, which inspired ours.

Theorem 1.

For every \({\textbf{a}}=(a_1,\ldots ,a_n):[n]\rightarrow [n-1]\), there exist a unique \(k\in [n-1]\) and a unique prime parking function \({\textbf{b}}=(b_1,\ldots ,b_n)\) such that

$$\begin{aligned} a_i\equiv b_i+k-1\pmod {n-1}\quad \textit { for every }i\in [n]\,. \end{aligned}$$
(5)

Conversely, given \(k\in [n-1]\) and the parking function \({\textbf{b}}=(b_1,\ldots ,b_n)\), (5) defines the function \({\textbf{a}}=(a_1,\ldots ,a_n)\) uniquely.

Proof.


Without loss of generality, suppose that \({\textbf{a}}^\uparrow ={\textbf{a}}\), and define, for every \(i\in [n-1]\),

$$\begin{aligned} s_i&= (a_{i+1}-a_i)+\cdots +(a_n-a_i)\\&\quad +(a_1-a_i+n-1)+\cdots +(a_{i-1}-a_i+n-1)\\&=\sum _{j=1}^n a_j-n\,a_i+(i-1)(n-1)\,,\\ s_n&=(a_1-a_n+n-1)+\cdots +(a_{n-1}-a_n+n-1)\\&=\sum _{j=1}^n a_j-n\,a_n+(n-1)^2\,, \end{aligned}$$

and let \(d\in [n]\) be such that \(s_d=\min \{s_i\mid i\in [n]\}\). Let \(k=a_d\), and

$$\begin{aligned}&{\textbf{b}}= (1,a_{d+1}-k+1,\ldots ,a_n-k+1,\\&\quad a_1-k+n,\ldots ,a_{d-1}-k+n) \,. \end{aligned}$$

Since for \(i\ne d\), we have

$$\begin{aligned}&s_i-s_d=(n-1)(i-d)-n(a_i-a_d)\ge 0\,, \end{aligned}$$

it follows that

$$\begin{aligned}&a_i-k \le (i-d)- \frac{i-d}{n}< {\left\{ \begin{array}{ll}i-d,&{}\text {if }i > d,\\ i-d+1,&{}\text {if }i< d.\end{array}\right. } \end{aligned}$$

Therefore, \({\textbf{b}}\) is a prime parking function, for it is componentwise less than or equal to

$$\begin{aligned} (1,1,2,\ldots ,n-d+1,n-d+2,\ldots ,n-1)\,. \end{aligned}$$

For proving the uniqueness, suppose, contrary to our assumptions, that both \({\textbf{b}}=(b_1,\ldots ,b_n)\) and \({\textbf{c}}=(c_1,\ldots ,c_n)\) were prime parking functions and that they satisfied the hypothesis of our theorem. Then there would exist \(\ell \in {\mathbb {N}}\) such that \(c_i\equiv b_i+\ell \pmod {n-1}\) for every \(i\in [n]\). Without loss of generality, we suppose that \({\textbf{b}}^\uparrow ={\textbf{b}}\). If \(b_n+\ell <n\), then \(c_1=1+\ell =1\), and \(\ell =0\) and \({\textbf{b}}={\textbf{c}}\). Otherwise, let \(b_{i-1}<n-\ell \le b_i\). Then

$$\begin{aligned} {\textbf{c}}^\uparrow=\, & {} (\overbrace{b_i+\ell -n+1}^{1},\ldots , \overbrace{b_n+\ell -n+1}^{{}\le n-i}, \\{} & {} \quad \overbrace{1+\ell }^{{}\le n-i+1},\ldots , \overbrace{b_{i-1}+\ell }^{{}\le n-1})\,. \end{aligned}$$

Hence, \(b_i=n-\ell <i\) and \(\ell +1\le n-i+1\). This contradiction concludes the proof. \(\square \)

For example, as before, let

$$\begin{aligned} {\textbf{a}}=(3, 13, 6, 3, 7, 3, 2, 1, 10, 11, 6, 7, 14, 10, 11)\in \text {PF}_{15}\,. \end{aligned}$$

Then if \(k=10\) and \(a_i\equiv b_i+k-1\pmod {n-1}\) for every \(i\in [n]\), it follows that

$$\begin{aligned} {\textbf{b}}=(8, 4, 11, 8, 12, 8, 7, 6, 1, 2, 11, 12, 5, 1, 2)\in \text {PF}'_{15}\,. \end{aligned}$$

Note that Theorem 1 shows that \((n-1)^n = (n-1) |\text {PF}'_{n}|\), whence the number of prime parking functions is indeed \((n-1)^{n-1}\).

The Parking Point of View

Note that by (1) and (2), a prime parking function of length n is a parking function of length \(n-1\) with an extra 1. More precisely, if \({\textbf{a}}=(a_1,\ldots ,a_n):[n]\rightarrow [n-1]\), \(a_i=1\) for some \(i\in [n]\), and

$${\textbf{b}}=(a_1,\ldots ,a_{i-1},a_{i+1},\ldots ,a_n):[n-1]\rightarrow [n-1],$$

then \({\textbf{a}}\in \text {PF}'_{n}\) if and only if \({\textbf{b}}\in \text {PF}_{n-1}\). Hence \({\textbf{a}}:[n]\rightarrow [n-1]\) is a prime parking function if all cars can park in a one-way street with n spots labeled 1, 1, 2, . . . , \(n-1\). For instance,

$$\begin{aligned} {\textbf{b}}=(8, 4, 11, 8, 12, 8, 7, 6, 1, 2, 11, 12, 5, 1, 2)\in \text {PF}'_{15} \end{aligned}$$

parks as follows:

figure b

In fact, if all elements of \({\textbf{a}}\) park as described, the element of \({\textbf{a}}\) that parks in the first spot labeled 1 must be \(a_i=1\), so that \(a_j>1\) for every \(j<i\). Then let \({\textbf{b}}\) be as defined above.

Since \({\textbf{b}}\) is \({\textbf{a}}\) with ith coordinate (equal to 1) deleted, and by hypothesis, \({\textbf{a}}\) parks where the n spots are labeled \(1,1,2,\ldots ,n-1\), then \({\textbf{a}}\) parks the ith element in the first spot labeled 1, and afterward, it parks the elements of \({\textbf{b}}\) in the subsequent spots (labeled \(1,2,\ldots ,n-1\)). So \({\textbf{b}}\) is a parking function.

On the other hand, if again, \(a_i=1\) for some \(i\in [n]\) such that \(a_j>1\) for every \(j\in [i-1]\), then the parking procedure parks \(a_i\) in the first spot labeled 1 and parks the remaining elements of \({\textbf{a}}\) in the next positions, since they are the elements of \({\textbf{b}}\).

An immediate consequence of Theorem 1 is the following addendum to Konheim and Weiss’s result.

Proposition 2.

Let n cars enter a one-way street with n spots, and suppose driver i wants to park in position \(p(i)\le n-1\) . Then there is a unique \(k\in [n-1]\) such that all cars can park in the previous sense, provided the spots are labeled consecutively

figure c

For example, for

$${\textbf{a}}=(3, 13, 6, 3, 7, 3, 2, 1, 10, 11, 6, 7, 14, 10, 11),$$

we have

figure d