Algorithm Search⌘K

Proofs: Auction algorithm

These are the human proofs of Auction algorithm, at full length.

The auction algorithm runs in O(n^3 C + n^2) time full

This proof shows: time.worst.

Let AA be an n×nn \times n matrix of integers with no forbidden pairs, and let C=max⁡i,jaij−min⁡i,jaijC = \max_{i,j} a_{ij} - \min_{i,j} a_{ij}. Each arithmetic operation and comparison on the scaled benefits and prices costs O(1)O(1) on the word RAM; by the argument of Claim 4 of the correctness proof every price stays between 0 and 2(n+1)C+22(n + 1)C + 2, so prices and scaled benefits fit in O(1)O(1) words when nn and the benefits do.

Setup. Lines L1 to L3 cost O(n2)O(n^2), for the scaled matrix, and so does finding the smallest and largest benefit.

Number of iterations. With no forbidden pairs, Aˉ=A\bar A = A and Cˉ=C\bar C = C in Claim 4 of the correctness proof, so the loop of line L4 runs at most n((n+1)C+1)+1=O(n2C+n)n((n + 1)C + 1) + 1 = O(n^2 C + n) times. For n=0n = 0 it runs zero times.

One iteration. Lines L5 and L6 scan the nn entries of row ii and the nn prices twice, O(n)O(n). Lines L7 to L9 and the queue operations cost O(1)O(1). So an iteration costs O(n)O(n).

Line L10 checks nn pairs and sums nn benefits, O(n)O(n).

Total. O(n2)+O(n2C+n)⋅O(n)=O(n3C+n2)O(n^2) + O(n^2 C + n) \cdot O(n) = O(n^3 C + n^2) time. The extra space is the scaled matrix, Θ(n2)\Theta(n^2), plus O(n)O(n) for the prices, the two assignment arrays and the queue.

Forbidden pairs. The replacement entry FF widens the range to Cˉ=(n+1)(h−ℓ)+1\bar C = (n + 1)(h - \ell) + 1, so the same count gives O(n4C′+n2)O(n^4 C' + n^2) time, with C′=h−ℓC' = h - \ell the range of the allowed benefits. ■\blacksquare

The auction algorithm returns an optimal assignment full

This proof shows: correctness, termination.

Let A=(aij)A = (a_{ij}) be an n×nn \times n matrix of integers with forbidden pairs, and let ℓ\ell and hh be the smallest and largest allowed entries (ℓ=h=0\ell = h = 0 if there are none). Line L2 replaces each forbidden entry by F=ℓ−n(h−ℓ)−1F = \ell - n(h - \ell) - 1; call the result Aˉ\bar A, and let aij′=(n+1)aˉija'_{ij} = (n + 1)\bar a_{ij}. For n=0n = 0 the queue is empty, the empty assignment is returned, and it is the only one; assume n≥1n \ge 1. For an assignment σ\sigma, a permutation, write Aˉ(σ)=∑iaˉiσ(i)\bar A(\sigma) = \sum_i \bar a_{i\sigma(i)}.

Claim 1 (the queue). At the start of each iteration of line L4, the queue holds exactly the unassigned persons, each once, and the assignment is one-to-one: each assigned person holds one object and each object has at most one owner. Proof. True after line L3. In an iteration, the bidder ii leaves the queue unassigned, line L8 unassigns the previous owner kk of j∗j^*, if any, and puts it in the queue, and line L9 gives j∗j^* to ii alone. Since ii was unassigned, k≠ik \ne i, and no other pair changes. □\square

Claim 2 (every bid raises a price). In line L7 the increment v−w+1v - w + 1 is at least 1. Proof. vv is the largest value in the row, so v≥wv \ge w; for n=1n = 1, w=vw = v. □\square

Claim 3 (1-CS invariant). At the start of each iteration, every assigned person ii holding jj satisfies aij′−pj≥max⁡k(aik′−pk)−1a'_{ij} - p_j \ge \max_k (a'_{ik} - p_k) - 1. Proof. True at the start, when nobody is assigned. Consider a bid by ii for j∗j^*. After line L7, aij∗′−pj∗=v−(v−w+1)=w−1a'_{ij^*} - p_{j^*} = v - (v - w + 1) = w - 1, while every k≠j∗k \ne j^* has aik′−pk≤wa'_{ik} - p_k \le w by the choice of ww; for n=1n = 1 there is no such kk. So ii satisfies the condition. Every other assigned person rr holds an object j≠j∗j \ne j^*, by Claim 1, whose price did not change, and the only price that changed went up, so max⁡k(ark′−pk)\max_k (a'_{rk} - p_k) did not grow and rr still satisfies the condition. The outbid person is no longer assigned. □\square

Claim 4 (termination). The loop ends after at most n((n+1)Cˉ+1)+1n((n + 1)\bar C + 1) + 1 iterations, where Cˉ=max⁡aˉ−min⁡aˉ\bar C = \max \bar a - \min \bar a. Proof. An object that has had an owner always has one: line L8 removes an owner only in the same iteration in which line L9 gives the object to the bidder. Suppose at some iteration an object j0j_0 has never been bid for. Then pj0=0p_{j_0} = 0, and a bid by ii for j≠j0j \ne j_0 has w≥aij0′−pj0=aij0′w \ge a'_{ij_0} - p_{j_0} = a'_{ij_0}, so the new price is pj=aij′−w+1≤aij′−aij0′+1≤(n+1)Cˉ+1p_j = a'_{ij} - w + 1 \le a'_{ij} - a'_{ij_0} + 1 \le (n + 1)\bar C + 1. By Claim 2 the kk-th bid for jj leaves pj≥kp_j \ge k, so each object gets at most (n+1)Cˉ+1(n + 1)\bar C + 1 bids while some object has never been bid for. Each iteration is one bid. So after at most n((n+1)Cˉ+1)+1n((n + 1)\bar C + 1) + 1 iterations every object has been bid for, hence has an owner; by Claim 1 the nn objects have nn distinct owners, all nn persons are assigned, and the queue is empty. □\square

Claim 5 (near optimality). At the end, the assignment SS is a permutation, and Aˉ(S)≥Aˉ(σ)\bar A(S) \ge \bar A(\sigma) for every permutation σ\sigma. Proof. By Claims 1 and 4, SS is a permutation. Let πi=max⁡k(aik′−pk)\pi_i = \max_k (a'_{ik} - p_k). By Claim 3, aiS(i)′≥πi+pS(i)−1a'_{iS(i)} \ge \pi_i + p_{S(i)} - 1 for every ii, and by the definition of πi\pi_i, aiσ(i)′≤πi+pσ(i)a'_{i\sigma(i)} \le \pi_i + p_{\sigma(i)}. Summing over ii, and using that SS and σ\sigma are both permutations, so ∑ipS(i)=∑ipσ(i)=∑jpj\sum_i p_{S(i)} = \sum_i p_{\sigma(i)} = \sum_j p_j,

(n+1)Aˉ(S)≥∑iπi+∑jpj−n≥(n+1)Aˉ(σ)−n.(n + 1)\bar A(S) \ge \sum_i \pi_i + \sum_j p_j - n \ge (n + 1)\bar A(\sigma) - n.

Dividing by n+1n + 1 gives Aˉ(S)>Aˉ(σ)−1\bar A(S) > \bar A(\sigma) - 1, and both sides are integers, so Aˉ(S)≥Aˉ(σ)\bar A(S) \ge \bar A(\sigma). □\square

Claim 6 (forbidden pairs). If some permutation uses no forbidden pair, then every permutation that uses one has a smaller Aˉ\bar A. Proof. A permutation τ\tau with no forbidden pair has Aˉ(τ)≥nℓ\bar A(\tau) \ge n\ell. A permutation ρ\rho with at least one forbidden pair has Aˉ(ρ)≤(n−1)h+F=(n−1)h+ℓ−nh+nℓ−1=(n+1)ℓ−h−1≤nℓ−1\bar A(\rho) \le (n - 1)h + F = (n - 1)h + \ell - nh + n\ell - 1 = (n + 1)\ell - h - 1 \le n\ell - 1, since h≥ℓh \ge \ell. □\square

Theorem. The algorithm terminates. If some permutation avoids the forbidden pairs, it returns one that maximizes ∑iaiσ(i)\sum_i a_{i\sigma(i)} among them; otherwise it reports infeasibility. Proof. Termination is Claim 4. If a feasible permutation exists, the returned SS maximizes Aˉ\bar A by Claim 5, so by Claim 6 it uses no forbidden pair, line L10 returns it, and on feasible permutations Aˉ\bar A equals the original objective, so SS is optimal. If no feasible permutation exists, SS uses a forbidden pair and line L10 reports infeasibility, which is correct. ■\blacksquare

Back to Auction algorithm