Let n and r be positive integers. For i=1,2,…,n, let fi be a univariate real-valued function defined in the integer domain and let fi(xi) be −∞ for negative integer xi. Any non-negative integer solution (x1,…,xn) that satisfies ∑i=1nxi=r is called a feasible solution. In addition, a feasible solution that maximizes the objective function ∑i=1nfi(xi) is called an optimal solution and the objective function value at the solution is called the optimal value. This problem is expressed as follows.
(P)Maximizesubject toi=1∑nfi(xi)i=1∑nxi=rxi is a non-negative integer, i=1,…,n
For i=1,2,…,n and non-negative integer α, define the function di(α):=fi(α)−fi(α−1) and assume that di(α) is non-increasing in terms of α. Apply the following greedy algorithm AG to (P).
Step 0: For i=1,2,…,n, set xi←0.
Step 1: Repeat the following procedure for r times: Let γ be any index i that maximizes di(xi+1) among i=1,2,…,n, and set xγ←xγ+1.
Answer the following questions.
(1-1) Let r=5,n=3, and let f1,f2,f3 take the following values. Notice that d1,d2,d3 are non-increasing. Answer the solution obtained by the greedy algorithm AG.
α
0
1
2
3
…
f1(α)
0
0
-8
-24
…
f2(α)
-2
1
-14
-40
…
f3(α)
0
-3
-12
-22
…
(1-2) Let (x1∗,x2∗,…,xn∗) be a feasible solution. Show that it is an optimal solution of (P) if and only if the following condition holds.
i=1,2,…,nmaxdi(xi∗+1)≤i=1,2,…,nmindi(xi∗)
(1-3) Show that the greedy algorithm AG outputs an optimal solution of (P).
Unless the non-increasing assumption of (1) holds, the greedy algorithm AG does not always output an optimal solution of (P). To apply dynamic programming, we consider the following problem (PNR) in which n and r in (P) are replaced with N∈{1,2,…,n} and R∈{0,1,…,r}, respectively.
(PNR)Maximizesubject toi=1∑Nfi(xi)i=1∑Nxi=Rxi is a non-negative integer, i=1,…,N
The optimal value of the problem is denoted by gN(R). Answer the following questions.
(2-1) Express gN(R) only with gN−1(c) and fN(c) for any non-negative integer c in the case of N≥2.
(2-2) Write a pseudo-code of a dynamic programming algorithm within 15 lines to output the optimal value gn(r) of (P). Hereafter, this algorithm is called AD.
(2-3) Show that the optimal value of (P) is obtained by the dynamic programming algorithm AD.
(2-4) Answer the computational complexity of the dynamic programming algorithm AD and the computational complexity of the greedy algorithm AG. Ignore the computational cost of calculating f1,…,fn.
If the condition fails, choose p,q such that
dp(xp∗+1)>dq(xq∗). Necessarily xq∗>0. Moving one unit from q to p changes the objective by
dp(xp∗+1)−dq(xq∗)>0,
so x∗ is not optimal.
Conversely, compare x∗ with any feasible x. Every marginal added where xi>xi∗ is at most maxidi(xi∗+1), while every marginal removed where xi<xi∗ is at least minidi(xi∗). The numbers added and removed are equal. Under the stated inequality, the objective at x cannot exceed that at x∗; hence x∗ is optimal.
Fix j with final xj>0 and consider the last iteration that increments xj. Greedy selection gives, for every i, the selected marginal dj(xj) at least the then-available marginal of i. Since each di is non-increasing, the final value satisfies
di(xi+1)≤dj(xj).
For xj=0, dj(0)=+∞. Thus the condition in (1-2) holds, so the greedy output is optimal.
for R = 0 to r: g[1,R] = f_1(R) for N = 2 to n: for R = 0 to r: g[N,R] = -infinity for c = 0 to R: g[N,R] = max(g[N,R], g[N-1,R-c] + f_N(c)) return g[n,r]
The base row is the exact optimum for one variable. Assuming row N−1 is optimal, every feasible solution for (PNR) has one value xN=c and an optimal value at most gN−1(R−c)+fN(c). Conversely, combining the maximizing c with an optimizer of that subproblem is feasible. Induction proves that the algorithm returns gn(r).
The dynamic program takes Θ(nr2) time and Θ(nr) space, reducible to Θ(r) space with two rows. A direct implementation of the stated greedy algorithm scans n marginals in each of r iterations, taking Θ(nr) time and Θ(n) space.