Analysis of the gift exchange problem
Moa Apagodu, David Applegate, N. J. A. Sloane, Doron Zeilberger

TL;DR
This paper investigates the combinatorial structure of the gift exchange game, deriving formulas and asymptotic behaviors for the number of possible game sequences based on parameters n and sigma.
Contribution
It provides new formulas and asymptotic expansions for counting the game sequences, extending previous work inspired by integer sequence analysis.
Findings
Derived formulas for the number of game sequences.
Provided asymptotic expansions for large n.
Connected the problem to integer sequence analysis.
Abstract
In the gift exchange game there are n players and n wrapped gifts. When a player's number is called, that person can either choose one of the remaining wrapped gifts, or can "steal" a gift from someone who has already unwrapped it, subject to the restriction that no gift can be stolen more than a total of sigma times. The problem is to determine the number of ways that the game can be played out, for given values of sigma and n. Formulas and asymptotic expansions are given for these numbers. This work was inspired in part by a 2005 remark by Robert A. Proctor in the On-Line Encyclopedia of Integer Sequences.
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsAdvanced Combinatorial Mathematics · semigroups and automata theory · Advanced Mathematical Identities
**Analysis of the gift exchange problem **
Moa Apagodu
Virginia Commonwealth University
Richmond, VA 23284, U.S.A.
David Applegate
Google, Inc.
76 Ninth Ave., New York, NY 10011, U.S.A.
N. J. A. Sloane111Corresponding author
The OEIS Foundation Inc.
11 So. Adelaide Ave., Highland Park, NJ 08904, U.S.A.
Doron Zeilberger
Rutgers University (New Brunswick)
Piscataway, NJ 08854, U.S.A.
Abstract
In the gift exchange game there are players and wrapped gifts. When a player’s number is called, that person can either choose one of the remaining wrapped gifts, or can “steal” a gift from someone who has already unwrapped it, subject to the restriction that no gift can be stolen more than a total of times. The problem is to determine the number of ways that the game can be played out, for given values of and . Formulas and asymptotic expansions are given for these numbers. This work was inspired in part by a 2005 remark by Robert A. Proctor in the On-Line Encyclopedia of Integer Sequences.
Keywords: gift swapping, set partitions, restricted Stirling numbers, Bessel polynomials, hypergeometric functions, Almkvist-Zeilberger algorithm, Wilf-Zeilberger summation
This is a sequel to the earlier (electronically published) article [5], differing from it in that there are two additional authors and several new theorems, including the resolution of most of the conjectures, and the extensive tables have been omitted.
Mathematics Subject Classifications: 05A, 11B37, 33F10
1 The problem
The following game is sometimes played at parties. A number (typically or ) is fixed in advance. Each of the guests brings a wrapped gift, the gifts are placed on a table (this is the “pool” of gifts), and slips of paper containing the numbers to are distributed randomly among the guests. The host calls out the numbers through in order.
When the number you have been given is called, you can either choose one of the wrapped (and so unknown) gifts remaining in the pool, or you can take (or “steal”) a gift that some earlier person has unwrapped, subject to the restriction that no gift can be “stolen” more than a total of times.
If you choose a gift from the pool, you unwrap it and show it to everyone. If a person’s gift is stolen from them, they immediately get another turn, and can either take a gift from the pool, or can steal someone else’s gift, subject always to the limit of thefts per gift. The game ends when someone takes the last (th) gift.
The problem is to determine the number of possible ways the game can be played out, for given values of and .
For example, if and , with guests and gifts numbered , , , there are 42 different scenarios, as follows. We write to indicate that guest took gift – it is always clear from the context whether the gift was stolen or taken from the pool. Also, provided we multiply the final answer by 6, we can assume that the gifts are taken from the pool in the order . There are then seven possibilities:
[TABLE]
and so the final answer is .
If we continue to ignore the factor of that arises from the order in which the gifts are selected from the pool, the numbers of scenarios for the cases and are , respectively.
We noticed that these five terms matched the beginning of entry A001515 in [16], although indexed differently. The th term of A001515 is defined to be , where is a Bessel polynomial [12, 13, 18], and for the values are indeed . Although there was no suggestion of gift-exchanging in that entry, one of the comments there (contributed by Robert A. Proctor on April 18, 2005) mentioned set partitions and restricted Stirling numbers, and this was enough of a hint to lead us to a solution of the general problem.
Outline of paper. The connection with set partitions is discussed in §2, where Theorem 1 expresses the general solution to the problem—the function —as a sum of restricted Stirling numbers of the second kind. We find it convenient to introduce our own notation, (see (3)), for the latter numbers. Theorem 3 gives various properties of the , and Theorem 4 gives an integral representation for that will enable us to use the methods of [1] and [4] to find recurrences.
We will obtain two different linear recurrences for , which we label Type C and Type D. Type C is somewhat simpler, and has leading coefficient , while Type D has lower order (order , in fact, see Theorem 11). To see the difference between the two types of recurrence for , , and , compare (8) with (9), (51) with (5), and (52) with the expression in Table 2 (the first of each pair being the Type C recurrence, the second the Type D recurrence).
Sections 3, 4, and 5 deal with cases (where there are connections with Bessel polynomials and hypergeometric functions, see Theorem 5), (where we introduce the two types of recurrence), and , respectively.
Comments on the rules. (i) If then once a gift has been stolen it can never be stolen again.
(ii) If , and someone steals your gift, then if you wish you may immediately steal it back (provided you hadn’t stolen it to begin with), and then it cannot be stolen again. Retrieving a gift in this way, although permitted by a strict interpretation of the rules, may be prohibited at real parties.
(iii) A variation of the game allows the last player to take any gift that has been unwrapped, regardless of how many times it has already been stolen, as an alternative to taking the last gift from the pool. This case only requires minor modifications of the analysis, and we will not consider it here.
(iv) We also ignore the complications caused by the fact that you brought (and wrapped) one of the gifts yourself, and so are presumably unlikely to choose it when your number is called.
2 Connection with partitions of labeled sets
Let be the number of scenarios with gifts and a limit of steals, for . Then is a multiple of , and we write , where in we assume that the gifts are taken from the pool in the order . We write rather than as the argument of because the th gift plays a special (and less important) role. This also simplifies the statement of Theorem 1.
In words, is the number of scenarios when there are gifts, with a limit of steals per gift, and the gifts are taken from the pool in the order .
We recall that the Stirling number of the second kind, , is the number of partitions of the labeled set into parts [10, 11], while for the -restricted Stirling number of the second kind, , is the number of partitions of into parts of size at most [7, 8, 9]. It is understood that parts are always nonempty.
Theorem 1**.**
For and ,
[TABLE]
Proof.
Equation (2) is an assertion about , so we are now discussing scenarios where there are gifts. For , , so , in agreement with .
We may assume therefore that . Let an “action” refer to a player choosing a gift , either by taking it from the pool or by stealing it from another player. Since we are now assuming that the gifts are taken from the pool in order, determines both the player and whether the action was to take a gift from the pool or to steal it from another player. So the scenario is fully specified simply by the sequence of values, recording which gift is chosen at each action. For example, the scenarios in (1) are represented by the sequences , , , , , , . Since the game ends as soon as the st gift is selected, the number of actions is at least and at most .
The sequence of values is therefore a sequence of integers from which begins with , ends with , where each number appears at least once and at most times and appears just once, and in which the first can appear only after has appeared. Conversely, any sequence with these properties determines a unique scenario.
Let denote the length of the sequence with the last entry (the unique ) deleted. We map this shortened sequence to a partition of into parts: the first part records the positions of the ’s, the second part records the positions of the ’s, , and the th part records the positions of the ’s. Continuing the example, for the seven sequences above, the values of and the corresponding partitions are as shown in Table 1.
The number of such partitions is precisely . Since the mapping from sequences to partitions is completely reversible, the desired result follows. ∎
Corollary 2**.**
* is equal to the number of partitions of , for , into parts, each of size at most .*
Remark. The sums are the classical Bell numbers. The sums also have a long history [14, 15]. However, the sums mentioned in (2) (where we sum on the first index rather than the second) do not seem to have studied before. Note that the limits in (2) are the natural limits on the summand , and could be omitted.
To simplify the notation, and to put the most important variable first, let
[TABLE]
for , , . In words, is the number of partitions of into exactly parts of sizes in the range .
For , is nonzero only for . To avoid having to worry about negative arguments, we define to be zero if either or is negative. Then the answer to our problem can be written as
[TABLE]
Stirling numbers of the second kind satisfy many different recurrences and generating functions [10, Chap. V], and to a lesser extent this is also true of . We begin with four general properties.
Theorem 3**.**
(i) Suppose , , . Then for or , if , and otherwise, for ,
[TABLE]
(ii) For , , ,
[TABLE]
where the sum is over all -tuples of nonnegative integers satisfying
[TABLE]
(iii) The numbers have the exponential generating functions
[TABLE]
[TABLE]
(iv) Suppose . Then for or , if , and otherwise, for ,
[TABLE]
Proof.
(i) This is an analog of the “vertical” recurrence for the Stirling numbers [10, Eq. 3c, p. 209] (note that because (3) involves a transposition, “horizontal” recurrences for correspond to “vertical” recurrences for Stirling numbers). The idea of the proof is to take a partition of into parts, remove the part containing , and renumber the remaining parts. If the part containing has size , , there are possibilities for the other elements in that part. (ii) This follows by standard counting arguments (cf. [10, Th. B, p. 205]), taking to be the number of parts of size in the partition. (iii) (8) and (9) are analogs of the “vertical” generating functions for the Stirling numbers [10, Eqs. 2a,2b, p. 206], and follow directly from (i). (iv) We let (the “excess” of over ), and rewrite (8) as
[TABLE]
We now apply the J. C. P. Miller method for exponentiating a polynomial. In the notation of [22], we take
[TABLE]
Then (10) follows at once from (11) and the main theorem of [22]. ∎
[TABLE]
where the inner sum is over all -tuples of nonnegative integers satisfying (3). This may be rewritten as a sum of multinomial coefficients:
[TABLE]
where is the size of the th part, or, equivalently, the number of times the th gift is chosen in an action.
Equation (6) also leads to an integral representation and generating function for .
Theorem 4**.**
(i) For ,
[TABLE]
(ii) The have ordinary generating function
[TABLE]
Proof.
(i) Using Euler’s integral representation for the factorial,
[TABLE]
the right-hand side of (15) is
[TABLE]
where the sums are over all -tuples of nonnegative integers satisfying . This is the same as the expression for in (13). (ii) is an immediate consequence of (i). ∎
The recurrence (5) makes it easy to compute as many values of and as one wishes. In the rest of the paper we will derive further formulas and recurrences, and asymptotic estimates for these numbers.
3 The case
In the case , i.e., when a gift can be stolen at most once, from Theorem 3 we have , and, for , for and , , and
[TABLE]
for . We also have the explicit formula
[TABLE]
for ; and the generating function
[TABLE]
It follows from (4) and (20) that
[TABLE]
Equation (22) shows that the sequence is indeed given by entry A001515 in [16]. That entry states (mostly without proof) several other properties of these numbers, taken from various sources, notably Grosswald [12]. We collect some of these properties in the next theorem. We recall from [12] that the Bessel polynomial is given by
[TABLE]
Also and (later) denote hypergeometric functions.
Theorem 5**.**
(i)
[TABLE]
(ii)
[TABLE]
(iii)
[TABLE]
for , with .
(iv) The have exponential generating function
[TABLE]
(v)
[TABLE]
Proof.
(i) and (ii) are immediate consequences of (22). (iii) It is easy to verify from (20) that
[TABLE]
Our conventions about negative arguments make it unnecessary to put any restrictions on the range over which (29) holds. By summing (29) on we obtain (26). (Equation (26) also follows from one of the recurrences for Bessel polynomials [12, Eq. (7), p. 18], [13].) (iv) By multiplying (26) by and summing on from to we obtain the differential equation
[TABLE]
Then the right-hand side of (27) is the unique solution of (30) which satisfies , . (v) This follows from (22), since the terms and dominate the sum (see also [12, Eq. (1), p. 124]). ∎
4 The case
In the case when , i.e., when a gift can be stolen at most once, the problem, as we saw in the previous section, turned out to be related to the values of Bessel polynomials, and the principal sequence, , had been studied before. For , we appear to be in new territory—for one thing, the sequences were not in [16].222 are now entries A144416, A144508, A144509 in [16].
We naturally tried to find analogs of the various parts of Theorem 5 that would hold for . Let us begin with the simplest result, the asymptotic behavior. This is directly analogous to Theorem 5(v).
Theorem 6**.**
For fixed ,
[TABLE]
Proof.
(Sketch) The two terms of (13) corresponding to , other and , other dominate the right-hand side of (13), and are both equal to . Dividing the sum by this quantity gives a converging sum, in which a subset of terms approach , while the others vanish as . ∎
Concerning Theorem 5(i), we do not know if there is a generalization of Bessel polynomials whose value gives (13) for .
As for Theorem 5(ii), there is a relationship with hypergeometric functions in the case . From (6) we have
[TABLE]
where .
Theorem 7**.**
(i) Let .
If then
[TABLE]
If then
[TABLE]
(ii)
[TABLE]
Proof.
(i) follows from (32) using the standard rules for converting sums of products of factorials to hypergeometric functions (cf. [3]), and (ii) follows from (4). ∎
We next give an analog of (29) and our first (Type C) recurrence for .
Theorem 8**.**
(i)
[TABLE]
(ii)
[TABLE]
for , with , , , .
Proof.
(i) Equation (8) follows by applying the Almkvist-Zeilberger technique of “differentiating under the integral sign” from [1], starting with the integral representation for given in (15). (ii) Eq. (8) follows by summing (8) on , just as (26) followed from (29). ∎
Remarks. (i) To apply the technique of “differentiating under the integral sign” from [1], we used the Maple implementation given in [2].
(ii) The recurrence (8) can also be proved using (33), (34), and Gauss’s contiguity relations for hypergeometric functions [6, §2.1.2], [19, §14.7].
(iii) A third proof may be obtained using the method of Sister Mary Celine Fasenmyer, as described in §4.1 of [17].
We discovered (8) by experiment, using Theorem 6 to suggest the leading term. (If denotes the right-hand side of (31), then .) This is a fourth-order recurrence for . We also discovered (again by experimenting) a third-order recurrence for , although the coefficient of on the left side is now rather than 1.
Theorem 9**.**
For ,
[TABLE]
with , , .
In view of (38), (9) is equivalent to a complicated identity involving hypergeometric functions.
Proof.
To prove (9) we apply the Almkvist-Zeilberger technique of “differencing under the integral sign” from [1, §7], again starting from the integral representation for given in (15). (We again used the Maple implementation of the technique from [2].) ∎
Since (8) uses the continuous version of the algorithm in [1], and (9) the discrete version, we refer to these recurrences as Types C and D respectively. When , both Types C and D produce (26).
Finally, if we need more terms of the asymptotic expansion than are given in Theorem 6 (or a computer-certified proof of it!), we can apply the Poincaré–Birkhoff–Trjitzinsky method as presented in [21] to the Type C recurrence (8). This works for any ; for , we find that
[TABLE]
5 The cases
In this final section we discuss the cases , mostly concentrating on rather than . We have not found any connections between these and generalized Bessel polynomials or hypergeometric functions.
Let us first prove that recurrences for and always exist. This follows from the Wilf–Zeilberger “Fundamental Theorem for multivariate sums” ([17, Theorem 4.5.1], [20]).
Theorem 10**.**
(i) For , there is a number such that satisfies a recurrence of the form
[TABLE]
where the coefficients are polynomials in with coefficients depending on and .
(ii) For , there is a number such that satisfies a recurrence of the form
[TABLE]
where the coefficients are polynomials in with coefficients depending on .
Proof.
(ii) As usual, Eq. (48) follows by summing (47) on . (i) We will use the case to illustrate the proof, the general case being similar. We know from (6) that
[TABLE]
where the sum is over all -tuples of nonnegative integers satisfying
[TABLE]
In other words,
[TABLE]
where now the sum is over all values of and for which the summand is defined. This summand is a “holonomic proper-hypergeometric term”, in the sense of [20], and it follows from the Fundamental Theorem in that paper that and hence satisfies a recurrence of the desired form. Similarly, in the general case, we write the summand in as a function of , again obtaining a holonomic proper-hypergeometric term. ∎
The Type C recurrences for and (obtained as in §4) are:333The Types C and D recurrences for all of through are given in two on-line appendices to this article, http://www.math.rutgers.edu/$\sim$zeilberg/tokhniot/oGifts2.txt and http://www.math.rutgers.edu/$\sim$zeilberg/tokhniot/oGifts1.txt respectively.
[TABLE]
[TABLE]
We also found analogous recurrences for the , which we omit.
The Type D recurrence for is given in (5), and that for can be seen in Table 2.
[TABLE]
Equation (5) and the expression in Table 2 are linear recurrences of orders and , respectively, and the Type D recurrences for and are similarly of orders and . An analogous property holds for all .
Theorem 11**.**
For , the Type D recurrence for has order at most .
Proof.
This follows from Theorem AZ of [4]. To see this we apply that theorem to the quantity
[TABLE]
That is, for the expression in the statement of Theorem AZ we take , , , , , and . The conclusion of the theorem is that (and hence ) satisfies a linear recurrence of order at most . ∎
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] G, Almkvist and D. Zeilberger. The method of differentiating under the integral sign. J. Symbolic Computation , 10:571–591, 1990.
- 2[2] G, Almkvist and D. Zeilberger. A MAPLE program that finds, and proves, recurrences and differential equations satisfied by hyperexponential definite integrals. ACM SIGSAM Bulletin , 25.3:14–17, 1991.
- 3[3] G. E. Andrews. Applications of basic hypergeometric series. SIAM Rev. , 16:441–484, 1974.
- 4[4] M. Apagodu and D. Zeilberger. Multi-variable Zeilberger and Almkvist-Zeilberger algorithms and the sharpening of Wilf-Zeilberger theory. Adv. Appl. Math. , 37:139–152, 2006.
- 5[5] D. Applegate and N. J. A. Sloane. The gift exchange problem. ar Xiv preprint ar Xiv:0907.0513, July 2, 2009.
- 6[6] H. Bateman et al. Higher transcendental functions . Mc Graw-Hill, NY, Vol. 1, 1953.
- 7[7] J. Y. Choi, L. Long and J. D. H. Smith. Reciprocity for multirestricted Stirling numbers. J. Combin. Theory, Ser. A , 113:1050–1060, 2006.
- 8[8] J. Y. Choi and J. D. H. Smith. On the combinatorics of multi-restricted numbers. Ars Combin. , 75:45–63, 2005.
