On this page
Picture a one-way street with n spaces numbered 1 to n, and n cars arriving one at a time. Each driver goes to their favourite space and parks there if it is free, or else in the next free space further down. A driver who passes space n leaves. A list of favourites that lets every car park is called a parking function, and the Wikipedia entry on parking functions states the surprising count: there are exactly (n + 1)^(n − 1) of them.
What is a parking function?
Write the favourites as a list: (2, 1, 1) means car 1 wants space 2, car 2 wants space 1 and car 3 wants space 1. Car 1 takes 2, car 2 takes 1, car 3 finds 1 and 2 full and takes 3. Everyone parks, so (2, 1, 1) is a parking function.
Now try (3, 3, 1). Car 1 takes 3, car 2 wants 3, finds it full and drives off the end. Not a parking function.
There is a quick test that needs no simulation. A list of n numbers from 1 to n is a parking function exactly when, for every i, at least i of the values are at most i (Wikipedia). Equivalently, sort the list: the smallest entry must be at most 1, the second smallest at most 2, and so on.
The idea has a practical side too: parking functions come up in the study of hash tables that use linear probing, where a key that finds its slot full moves to the next one. Wikipedia cites Alan Konheim and Benjamin Weiss's 1966 paper An occupancy discipline and applications for this.
Why are there (n + 1)^(n − 1) parking functions?
John Riordan credited the following argument to Henry O. Pollak, as the Wikipedia article records. It turns the street into a loop.
Bend the street into a circle and add a space n + 1. Each car may now choose any of n + 1 spaces, giving (n + 1)^n lists.
On a circle no car falls off; it drives round until it finds a gap. All n cars park and exactly one space stays empty.
Add 1 to every choice (n + 1 becomes 1). Every car parks one space further round, so the empty space moves by one too. The n + 1 shifts of a list leave n + 1 different empty spaces, and exactly one leaves space n + 1 empty.
Space n + 1 stays empty precisely when the list is a parking function: no car chose it or drove past it, so the circle behaved like the straight street.
So one list in every group of n + 1 is a parking function, and there are (n + 1)^n ÷ (n + 1) = (n + 1)^(n − 1) of them.
What are the 16 parking functions for n = 3?
For three cars the formula gives 4^2 = 16, and the Wikipedia article lists the same 16. Group them by their sorted form, since every rearrangement of a parking function is again one:
Sorted (1, 1, 1): 111. That is 1 list.
Sorted (1, 1, 2): 112, 121, 211. That is 3 lists.
Sorted (1, 1, 3): 113, 131, 311. That is 3 lists.
Sorted (1, 2, 2): 122, 212, 221. That is 3 lists.
Sorted (1, 2, 3): 123, 132, 213, 231, 312, 321. That is 6 lists.
The total is 1 + 3 + 3 + 3 + 6 = 16. Lists such as 222 and 133 fail the sorted test, so they are missing.
How do parking functions connect to Cayley's formula?
Cayley's formula says there are n^(n − 2) trees on n labelled vertices. Carl Wilhelm Borchardt found it first, in 1860; Arthur Cayley's 1889 note extended it, and his name stuck.
Put n + 1 in place of n and you get (n + 1)^(n − 1) trees on n + 1 labelled vertices: exactly the number of parking functions of length n. For n = 3, there are 16 trees on 4 labelled vertices and 16 parking functions. The sequence of tree counts, 1, 1, 1, 3, 16, 125, 1296, is OEIS A000272, whose notes say it also counts parking functions.
The match is no accident. As the Cayley's formula article notes, Marcel-Paul Schützenberger gave a one-to-one correspondence between rooted forests and parking functions in a 1968 paper80003-1), and Dominique Foata and John Riordan returned to such correspondences in Mappings of acyclic and parking functions (1974). For the tree side, see our post on counting trees on n labelled vertices with Cayley's formula.
How can you practise this?
Do n = 2 by hand. You should find 3^1 = 3 lists: 11, 12 and 21.
Pick three choices from 1 to 4, park them on the 4-space circle, and find the shift that leaves space 4 empty.
Count the n = 4 cases by sorted form and check you reach 5^3 = 125.
Compare Pollak's trick with the reflection argument in the ballot problem and why the answer is (a − b)/(a + b): both count awkward objects by grouping them with easier ones.
When a counting idea will not settle, the Fermi Concept Library gives every concept in mathematics its own lesson and its place in the map, and the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer.



