• No results found

5.4 Combinatorial Algorithm

5.4.3 Data Structure

The following observation motivates a fast way to construct R↓. For every point

a ∈ A, let List(a) be the collection of points v ∈ A ∪ B \ {a} such that Γ(a, v) is a

nonempty rectangle not containing a point of A ∪ B \ {a, v}. Observe that b ∈ B is such that Γ(a, b) ∈ Rif and only if b ∈ List(a) ∩ B.

The points in List(a) form a staircase-shape as shown in Figure 5-11. They are therefore easy to construct by visiting all the points in A ∪ B \ {a} from bottom to top and remembering the leftmost visited one that is to the right of a.

a

Figure 5-11: Staircase shape of List(a).

We now show a fast way to test if a rectangle in R↓ is added to the greedy

c.f.i. family K. Consider the moment when a rectangle R = Γ(a, b) is processed in the construction of K. Let L = Γ(a0, b) be the last rectangle added to K before R is

considered having the same top right corner as R, this is tr(L) = b. This rectangle may not exist, for instance in the case where R is the first rectangle considered having b as a corner. If L exists, we call it the left-witness of R, and we denote it as L = LW(R).

If L = LW(R) = Γ(a0, b) exists, let T = Γ(a0, b0) be the first rectangle in K added after L with same bottom left corner as L, this is bl(T ) = a0. The rectangle T may not exist, for instance, if L is already the last rectangle with corner a0. If T exists we call it the top-witness of R, and we denote it as T = TW(R).

Lemma 5.4.4. The rectangle R = Γ(a, b) ∈ Ris not added to K if and only if

both rectangles L = LW(R) and T = TW(R) exist and the rectangle T has corner intersection with R.

Proof. Sufficiency is direct, since the existence of a rectangle T ∈ K having corner

intersection with R implies the latter rectangle is not added to K.

To prove necessity, suppose that R is not added to K. The rectangle R blames this to a rectangle blame(R) = Γ(c, d) which is the first rectangle in K having corner intersection with R. By condition C1 of Lemma 5.4.1, Γ(c, b) is a rectangle with right-top corner b, that is added to K before R is considered. This means that the left witness L = LW(R) = Γ(a0, b) exists (since it is the last rectangle added to K with

the previous property). For the next part of the proof, see Figure 5-12 for reference. Assume for sake of contradiction that the top witness T = TW(R) does not exist or that T has no corner intersection with R. This is equivalent to saying that there

R00 a00 b00 R a b a0 L b0 p T Z R a b a0 L b0 T

Figure 5-12: On the left, the situation if T has no corner intersection with R. On the right, the situation imposed by Lemma 5.4.4.

is no rectangle with bottom-left corner a0 having corner intersection with R (if there is one, then T must also have corner-intersection with R).

Recall that R was not added to K. This means that R must contain a bottom-

right corner of a previous rectangle in K in its topological interior int(R). Among

all the possible such bottom-right corners, let p = (px, py) be the one having larger

x-coordinate, and, in case of ties, select the one with larger y-coordinate. Let R00 = Γ(a00, b00) ∈ K be the rectangle having p as its bottom-right corner (i.e. p = (b00x, a00y)).

Note that py = a00y must be strictly smaller than a

0

y. Indeed, if py > a0y, then p

would be in the interior of L, contradicting the fact that L is in K, and if py = a0y then

R00 and L would have the same bottom-left corner a0, contradicting our assumption for T . Also, we must have that a0x < a00x since otherwise the point a0 would be inside the rectangle R00, contradicting its minimality. See the left of Figure 5-12.

Let U = Γ(a00, b) ∈ R. This rectangle is inclusion-wise minimal since otherwise,

it would contain a point in A ∪ B \ {a00, b}, contradicting the minimality of R or R00. The discussion of the previous paragraph implies that U appears after L in right-top order and has the same top-right corner b. We claim that U is also in K. This would contradict the definition of L as left-witness and conclude the proof of the lemma.

Suppose that the claim does not hold. Then, U must contain the bottom-right corner q of a previous rectangle in K in its interior. The point q must be in int(U ) \ (int(L) ∪ int(R00)) as otherwise, L or R00 would not be in K. This implies that q is in the region Z = [b00x, bx) × (a00y, a

0

y] (the dark area Z in the left of Figure 5-12). But

then q is a bottom-right corner of a rectangle in K, contained in int(R) and having either higher x-coordinate than p, or having equal x-coordinate, but strictly larger

y-coordinate. This contradicts the definition of p.

The previous lemma states that in order to test if a rectangle R is added to K we only need to check if its top witness (provided it exists) has corner-intersection with R or not. This, together with the observation at the beginning of this section, motivates Algorithm 15 to construct R↓ and K efficiently. This algorithm returns the

entire lists K and K = R↓\ K. It also returns for every point v ∈ A ∪ B, two lists

K(v) and K(v) containing the rectangles in K and K respectively, having corner v. All these lists are given in right-top order. Furthermore, every rectangle in K receives two pointers to its left and top witnesses. In the description of Algorithm 15, last(·) is a pointer to the last element of the corresponding list.

Algorithm 15 Data structure construction.

Require: Two subsets A and B in [n]2, in rook representation.

Ensure: The associated collections K(·), K(·) and the function LW and TW.

1: Initialize empty list K and K.

2: Initialize empty lists K(v), K(v), for all v ∈ A ∪ B.

3: for each element a ∈ A, from left to right do 4: List(a) ← ∅

5: for each element v ∈ A ∪ B, with vy > ax, from bottom to top do 6: if (vx < ax) or (vx > last(List(a))x) then

7: continue to next element.

8: else Add v at the end of List(a).

9: end if

10: end for

11: for each element b ∈ List(a) in the order they were included do

12: if b ∈ B then

13: Let R = Γ(a, b) and L = Γ(a0, b) ← last(K(b)).

14: if L is NULL then

15: Add R to K, K(a) and K(b).

16: else

17: Let T = Γ(a0, b0) be the next rectangle in K(a0) after L.

18: if T is NULL or T has no corner-intersection with R then

19: Add R to K, K(a) and K(b).

20: else . T has corner intersection with R

21: Add R to K, K(a) and K(b).

22: Set LW(R) ← L, TW(R) ← T . 23: end if 24: end if 25: end if 26: end for 27: end for

Since we only manipulate pointers and perform comparisons between points in the plane, we get the following corollary.

Lemma 5.4.5. Given two subsets A and B in [n]2 in rook representation, with n =

|A ∪ B|, Algorithm 15 runs in O(n2)-time. Therefore, the first step of the refinement

of Algorithm 14 runs in O(n2)-time.