4-6 Monge arrays

An m×nm \times n array AA of real numbers is a Monge array if for all ii, jj, kk, and ll such that 1i<km1 \le i < k \le m and 1j<ln1 \le j < l \le n, we have

A[i,j]+A[k,l]A[i,l]+A[k,j].A[i, j] + A[k, l] \le A[i, l] + A[k, j].

In other words, whenever we pick two rows and two columns of a Monge array and consider the four elements at the intersections of the rows and columns, the sum of the upper-left and lower-right elements is less than or equal to the sum of the lower-left and upper-right elements. For example, the following array is Monge:

1017132823172216292324282234241113617745443237233633192167566515334 \begin{matrix} 10 & 17 & 13 & 28 & 23 \\ 17 & 22 & 16 & 29 & 23 \\ 24 & 28 & 22 & 34 & 24 \\ 11 & 13 & 6 & 17 & 7 \\ 45 & 44 & 32 & 37 & 23 \\ 36 & 33 & 19 & 21 & 6 \\ 75 & 66 & 51 & 53 & 34 \end{matrix}

a. Prove that an array is Monge if and only if for all i=1,2,,m1i = 1, 2, \ldots, m - 1, and j=1,2,,n1j = 1, 2, \ldots, n - 1 we have

A[i,j]+A[i+1,j+1]A[i,j+1]+A[i+1,j].A[i, j] + A[i + 1,j + 1] \le A[i, j + 1] + A[i + 1, j].

(Hint:\textit{Hint:} For the "if" part, use induction seperately on rows and columns.)

b. The following array is not Monge. Change one element in order to make it Monge. (Hint:\textit{Hint:} Use part (a).)

37232232216710533430313213964321158 \begin{matrix} 37 & 23 & 22 & 32 \\ 21 & 6 & 7 & 10 \\ 53 & 34 & 30 & 31 \\ 32 & 13 & 9 & 6 \\ 43 & 21 & 15 & 8 \end{matrix}

c. Let f(i)f(i) be the index of the column containing the leftmost minimum element of row ii. Prove that f(1)f(2)f(m)f(1) \le f(2) \le \cdots \le f(m) for any m×nm \times n Monge array.

d. Here is a description of a divide-and-conquer algorithm that computes the leftmost minimum element in each row of an m×nm \times n Monge array AA:

Construct a submatrix AA' of AA consisting of the even-numbered rows of AA. Recursively determine the leftmost minimum for each row in AA'. Then compute the leftmost minimum in the odd-numbered rows of AA.

Explain how to compute the leftmost minimum in the odd-numbered rows of AA (given that the leftmost minimum of the even-numbered rows is known) in O(m+n)O(m + n) time.

e. Write the recurrence describing the running time of the algorithm described in part (d). Show that its solution is O(m+nlogm)O(m + n\log m).

a. The "only if" part is trivial, it follows form the definition of Monge array.

As for the "if" part, let's first prove that

A[i,j]+A[i+1,j+1]A[i,j+1]+A[i+1,j]A[i,j]+A[k,j+1]A[i,j+1]+A[k,j], \begin{aligned} A[i, j] + A[i + 1, j + 1] & \le A[i, j + 1] + A[i + 1, j] \\ \Rightarrow A[i, j] + A[k, j + 1] & \le A[i, j + 1] + A[k, j], \end{aligned}

where i<ki < k.

Let's prove it by induction. The base case of k=i+1k = i + 1 is given. As for the inductive step, we assume it holds for k=i+nk = i + n and we want to prove it for k+1=i+n+1k + 1 = i + n + 1. If we add the given to the assumption, we get

A[i,j]+A[k,j+1]A[i,j+1]+A[k,j](assumption)A[k,j]+A[k+1,j+1]A[k,j+1]+A[k+1,j](given)A[i,j]+A[k,j+1]+A[k,j]+A[k+1,j+1]A[i,j+1]+A[k,j]+A[k,j+1]+A[k+1,j]A[i,j]+A[k+1,j+1]A[i,j+1]+A[k+1,j] \begin{aligned} A[i, j] + A[k, j + 1] & \le A[i, j + 1] + A[k, j] & \text{(assumption)} \\ A[k, j] + A[k + 1, j + 1] & \le A[k, j + 1] + A[k + 1, j] & \text{(given)} \\ \Rightarrow A[i, j] + A[k, j + 1] + A[k, j] + A[k + 1, j + 1] & \le A[i, j + 1] + A[k, j] + A[k, j + 1] + A[k + 1, j] \\ \Rightarrow A[i, j] + A[k + 1, j + 1] & \le A[i, j + 1] + A[k + 1, j] \end{aligned}

b.

37232432216710533430313213964321158 \begin{matrix} 37 & 23 & \mathbf{24} & 32 \\ 21 & 6 & 7 & 10 \\ 53 & 34 & 30 & 31 \\ 32 & 13 & 9 & 6 \\ 43 & 21 & 15 & 8 \\ \end{matrix}

c. Let aia_i and bjb_j be the leftmost minimal elements on rows aa and bb and let's assume that i>ji > j. Then we have

A[j,a]+A[i,b]A[i,a]+A[j,b].A[j, a] + A[i, b] \le A[i, a] + A[j, b].

But

A[j,a]A[i,a](ai is minimal)A[i,b]A[j,b](bj is minimal) \begin{aligned} A[j, a] \ge A[i, a] & (a_i \text{ is minimal}) \\ A[i, b] \ge A[j, b] & (b_j \text{ is minimal}) \\ \end{aligned}

Which implies that

A[j,a]+A[i,b]A[i,a]+A[j,b]A[j,a]+A[i,b]=A[i,a]+A[j,b] \begin{aligned} A[j, a] + A[i, b] & \ge A[i, a] + A[j, b] \\ A[j, a] + A[i, b] & = A[i, a] + A[j, b] \end{aligned}

Which in turn implies that either:

A[j,b]<A[i,b]A[i,a]>A[j,a]ai is not minimalA[j,b]=A[i,b]bj is not the leftmost minimal \begin{aligned} A[j, b] < A[i, b] & \Rightarrow A[i, a] > A[j, a] \Rightarrow a_i \text{ is not minimal} \\ A[j, b] = A[i, b] & \Rightarrow b_j \text{ is not the leftmost minimal} \end{aligned}

d. If μi\mu_i is the index of the ii-th row's leftmost minimum, then we have

μi1μiμi+1.\mu_{i - 1} \le \mu_i \le \mu_{i + 1}.

For i=2k+1i = 2k + 1, k0k \ge 0, finding μi\mu_i takes μi+1μi1+1\mu_{i + 1} - \mu_{i - 1} + 1 steps at most, since we only need to compare with those numbers. Thus

T(m,n)=i=0m/21(μ2i+2μ2i+1)=i=0m/21μ2i+2i=0m/21μ2i+m/2=i=1m/2μ2ii=0m/21μ2i+m/2=μmμ0+m/2=n+m/2=O(m+n). \begin{aligned} T(m, n) & = \sum_{i = 0}^{m / 2 - 1} (\mu_{2i + 2} - \mu_{2i} + 1) \\ & = \sum_{i = 0}^{m / 2 - 1} \mu_{2i + 2} - \sum_{i = 0}^{m / 2 - 1}\mu_{2i} + m / 2 \\ & = \sum_{i = 1}^{m / 2} \mu_{2i} - \sum_{i = 0}^{m / 2 - 1}\mu_{2i} + m / 2 \\ &= \mu_m - \mu_0 + m / 2 \\ & = n + m / 2 \\ & = O(m + n). \end{aligned}

e. The divide time is O(1)O(1), the conquer part is T(m/2)T(m / 2) and the merge part is O(m+n)O(m + n). Thus,

T(m)=T(m/2)+cn+dm=cn+dm+cn+dm/2+cn+dm/4+=i=0lgm1cn+i=0lgm1dm2i=cnlgm+dmi=0lgm1<cnlgm+2dm=O(nlgm+m). \begin{aligned} T(m) & = T(m / 2) + cn + dm \\ & = cn + dm + cn + dm / 2 + cn + dm / 4 + \cdots \\ & = \sum_{i = 0}^{\lg m - 1}cn + \sum_{i = 0}^{\lg m - 1}\frac{dm}{2^i} \\ & = cn\lg m + dm\sum_{i = 0}^{\lg m - 1} \\ & < cn\lg m + 2dm \\ & = O(n\lg m + m). \end{aligned}