4-6 Monge arrays
An m×n array A of real numbers is a Monge array if for all i, j, k, and l such that 1≤i<k≤m and 1≤j<l≤n, we have
A[i,j]+A[k,l]≤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:
1017241145367517222813443366131622632195128293417372153232324723634
a. Prove that an array is Monge if and only if for all i=1,2,…,m−1, and j=1,2,…,n−1 we have
A[i,j]+A[i+1,j+1]≤A[i,j+1]+A[i+1,j].
(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: Use part (a).)
37215332432363413212273091532103168
c. Let f(i) be the index of the column containing the leftmost minimum element of row i. Prove that f(1)≤f(2)≤⋯≤f(m) for any m×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×n Monge array A:
Construct a submatrix A′ of A consisting of the even-numbered rows of A. Recursively determine the leftmost minimum for each row in A′. Then compute the leftmost minimum in the odd-numbered rows of A.
Explain how to compute the leftmost minimum in the odd-numbered rows of A (given that the leftmost minimum of the even-numbered rows is known) in 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).
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]+A[k,j+1]≤A[i,j+1]+A[i+1,j]≤A[i,j+1]+A[k,j],
where i<k.
Let's prove it by induction. The base case of k=i+1 is given. As for the inductive step, we assume it holds for k=i+n and we want to prove it for k+1=i+n+1. If we add the given to the assumption, we get
A[i,j]+A[k,j+1]A[k,j]+A[k+1,j+1]⇒A[i,j]+A[k,j+1]+A[k,j]+A[k+1,j+1]⇒A[i,j]+A[k+1,j+1]≤A[i,j+1]+A[k,j]≤A[k,j+1]+A[k+1,j]≤A[i,j+1]+A[k,j]+A[k,j+1]+A[k+1,j]≤A[i,j+1]+A[k+1,j](assumption)(given)
b.
37215332432363413212473091532103168
c. Let ai and bj be the leftmost minimal elements on rows a and b and let's assume that i>j. Then we have
A[j,a]+A[i,b]≤A[i,a]+A[j,b].
But
A[j,a]≥A[i,a]A[i,b]≥A[j,b](ai is minimal)(bj is minimal)
Which implies that
A[j,a]+A[i,b]A[j,a]+A[i,b]≥A[i,a]+A[j,b]=A[i,a]+A[j,b]
Which in turn implies that either:
A[j,b]<A[i,b]A[j,b]=A[i,b]⇒A[i,a]>A[j,a]⇒ai is not minimal⇒bj is not the leftmost minimal
d. If μi is the index of the i-th row's leftmost minimum, then we have
μi−1≤μi≤μi+1.
For i=2k+1, k≥0, finding μi takes μi+1−μi−1+1 steps at most, since we only need to compare with those numbers. Thus
T(m,n)=i=0∑m/2−1(μ2i+2−μ2i+1)=i=0∑m/2−1μ2i+2−i=0∑m/2−1μ2i+m/2=i=1∑m/2μ2i−i=0∑m/2−1μ2i+m/2=μm−μ0+m/2=n+m/2=O(m+n).
e. The divide time is O(1), the conquer part is T(m/2) and the merge part is O(m+n). Thus,
T(m)=T(m/2)+cn+dm=cn+dm+cn+dm/2+cn+dm/4+⋯=i=0∑lgm−1cn+i=0∑lgm−12idm=cnlgm+dmi=0∑lgm−1<cnlgm+2dm=O(nlgm+m).