Top Banner
Chapter 7 : The Gap Greedy Algorithm By azam sadeghian
48

Chapter 7 : The Gap Greedy Algorithm By azam sadeghian

Feb 22, 2016

Download

Documents

tehya

Chapter 7 : The Gap Greedy Algorithm By azam sadeghian. Topics : 7.1 A sufficient condition for “ spannerhood ” 7.2 The gap-greedy algorithm 7.3 Toward an efficient implementation 7.4 An efficient implementation of the gap-greedy algorithm 7.5 Generalization to higher dimensions. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

Slide 1

Chapter 7 :

The Gap Greedy Algorithm

By azam sadeghianTopics:7.1 A sufficient condition for spannerhood7.2 The gap-greedy algorithm7.3 Toward an efficient implementation7.4 An efficient implementation of the gap-greedy algorithm7.5 Generalization to higher dimensions

7.1 A sufficient condition for spannerhoodWhen does a directed graph G have a small stretch factor? Assume that for any two distinct points p and q of a point set S, there is an edge (r, s) in G such that (i) the vectors pq and rs have approximately the same direction, (ii) |rs| is not much larger than |pq|, and (iii) at least one of the distances |pr| and |qs| is small (relative to the length of (r, s)). Then G has a small stretch factor.We will use the notation angle (pq, rs) for the angle between the directed edges (p, q) and (r, s); see Section 5.3.Lemma 7.1.1. Let , w, and t be real numbers such that 0 < < /4, 0 w < (cos sin )/2, and t 1/(cos sin 2w). Let S be a set of n points in the plane, and let G = (S,E) be a directed graph, such that the following holds: For any two distinct points p and q of S, there is an edge (r, s) E, such that1. angle (pq, rs) ,2. |rs| |pq|/ cos , and3. |pr| w|rs| or |qs| w|rs|.Then, the graph G is a t-spanner for S.proof Let p and q be any two points of S. We will show that G contains a (directed)t-spanner path from p to q. The proof is by induction on the rank of the distance |pq| inthe sorted sequence of distances determined by all ordered pairs of points. If |pq| = 0,then p = q and G clearly contains a t-spanner path from p to q. Assume that |pq| > 0.Furthermore, assume that for any two points x and y of S with |xy| < |pq|, the graph Gcontains a t-spanner path from x to y.Let (r, s) be any edge of E for which all three premises of this lemma hold. We willconsider the case only when |pr| w|rs|. (The case when |qs| w|rs| can be treatedby a symmetric argument.) Since the premises of Lemma 6.4.1 from the previous chapterare satisfied, it follows from that lemma that |pr| < |pq|, |sq| < |pq|, andt |pr| + |rs| + t |sq| t |pqHence, by the induction hypothesis, there are t-spanner paths in G from p to r, and froms to q. Consider the path in G that starts in p, follows the t-spanner path to r, then takesthe edge from r to s, and finally follows the t-spanner path from s to q. The length of thispath is bounded from above by t |pr| + |rs| + t |sq|, which, by (7.1), is less than or equalto t |pq|. Hence, G contains a t-spanner path from p to q.7.2 The gap-greedy algorithmThe gap-greedy algorithm: The algorithm starts with an empty set E of edges, and considers all ordered pairs of distinct points in nondecreasing order of their distances. Let p and q form the current pair of points. The algorithm adds the edge (p, q) to E if it does not violate the strong gap property. That is, the decision whether or not edge (p, q) is added to E is based on Lemma 7.1.1: Edge (p, q) is added if and only if there is no edge (r, s) in the current edge set E such that (i) (p, q) and (r, s) have approximately the same direction, and (ii) at least one of the distances |pr| and |qs| is small. If there is such an edge (r, s), then Lemma 7.1.1 implies that we do not need to add the edge (p, q) in order to get a graph with a small stretch factor.Algorithm GapGreedy(S, ,w)Comment: This algorithm takes as input a set S of n points in the plane, and two realnumbers and w such that 0 < < /4 and 0 w < (cos sin )/2. The algorithmreturns a directed t-spanner G = (S,E), for t = 1/(cos sin 2w).sort the ordered pairs of distinct points in non-decreasing order of their distances and store them in a list L;E := ;for each ordered pair (p, q) L ( consider pairs in sorted order )do add := true;for each edge (r, s) Edo if angle (pq, rs) then add := add (|pr| > w|rs|) (|qs| > w|rs|)endifendfor;if add = true then E := E {(p, q)} endifendfor;return the graph G = (S,E)

Lemma 7.2.1. Let and w be real numbers such that 0 < < /4 and 0 w < (cos sin )/2, and let S be a set of n points in the plane. The graph G = (S,E) that is returned by algorithm GapGreedy(S, ,w) is a t-spanner for S, for t = 1/(cos sin 2w).Proof : It is sufficient to show that the set E satisfies the three conditions of Lemma7.1.1, since this implies that the graph G is a t-spanner for S. Let p and q be any two distinct points of S. If (p, q) is an edge of E, then the three conditions of Lemma 7.1.1 hold with r = p and s = q. Assume that (p, q) is not an edge of E. Consider the iteration of the outer for-loop during which the pair (p, q) was inspected. The algorithm did not add (p, q) to E because this set contained an edge (r, s), such that (i) angle (pq, rs) , and (ii) at least one of |pr| and |qs| is less than or equal to w|rs|. Since (r, s) was contained in E at the moment when the algorithm inspected the pair (p, q), we have |rs| |pq|. In particular, |rs| |pq|/ cos . Therefore, the three conditions of Lemma 7.1.1 are satisfied.Lemma 7.2.2. Let and w be real numbers such that 0 < < /4 and 0 w < (cos sin )/2, and let S be a set of n points in the plane.1. Algorithm GapGreedy(S, ,w) computes a graph in which each vertex has degree at most 22/.2. If w > 0, then the weight of this graph is less than 2/(1 + 2/w) * wt(MST(S)) log nproof Consider any two distinct edges (p, q) and (r, s) in the graph G = (S,E) that is constructed by algorithm GapGreedy(S, ,w), and assume that angle (pq, rs) . We may assume without loss of generality that (r, s) was added to E before (p, q). It follows from the algorithm that |rs| |pq|, |pr| > w|rs|, and |qs| > w|rs|. Hence, the strong w-gap property holds for the edges (p, q) and (r, s).Consider a collection C of 2/ cones of angle that have their apex at the origin and that cover the plane. Number the cones of C as C1,C2, . . . , C2/. For each i with 1 i 2/, define Ei := {(p, q) E : q p Ci}.Since Ei E for 1 i 2/, it is clear that Ei satisfies the strong w-gap property. Furthermore, Theorem 6.1.2 implies that no two distinct edges of Ei share a source, and no two distinct edges of Ei share a sink. Since the sets Ei, 1 i 2/, partition E, it follows that each point p of S has indegree and outdegree at most 2/ in G; that is, the degree of p in G is less than or equal to 22/. Also, if w > 0, then Theorem 6.1.2 implies that the weight of E is less than 2/(1 + 2/w) * wt(MST(S)) log n.7.3 Toward an efficient implementationA direct implementation of algorithm GapGreedy has running time (n3). One of the obstacles in designing an o(n2)time implementation of this algorithm is the fact that all pairs of points are considered. Next version running time is O(n log2 n).Throughout this section, we fix a real number with 0 < < /4. Let = 2/], and let C be a collection of cones of angle that have their apex at the origin and that cover the plane. As always, we denote the Euclidean distance between the points p and q by |pq|. The L-distance between p = (p1, p2) and q = (q1, q2) will be denoted by |pq|, i.e., |pq| = max(|p1 q1|, |p2 q2|).so | pq| |pq| 2|pq|.

ModificationsModification 1: We replace the condition angle(pq, rs) by q p and s r are contained in the same cone of C.Modification 2: after algorithm GapGreedy has added an edge (r, s) to the graph, it does not add any edge (p, q) that has approximately the same direction as (r, s), and for which p is close to r or q is close to s. Consider this condition for the points p and r. p is close to r = p is contained in a circle that is centered at r and that has radius w|rs|., we modify the notion of p being close to r, in the following way.In algorithm GapGreedy, we replace the inequality |pr| > w|rs| by |pr| > (w/2)|rs|, and the inequality |qs| > w|rs| by |qs| > (w/2)|rs|. That is, for the points p and r (and for the points q and s), we switch from the Euclidean metric to the L-metric. Observe that all points p for which |pr| (w/ 2)|rs| are contained in the axes-parallel square that is centered at r and that has sides of length 2(w/ 2)|rs|. Using range trees, we can find these points p efficiently. A similar remark holds for the points q and s.Modification 3: Algorithm GapGreedy considers all pairs of points in nondecreasing order of their Euclidean distances. If (r, s) is an edge of the current graph, and (p, q) is the current pair to be tested for inclusion, then we know that |rs| |pq|. By Lemma 7.1.1 however, it suffices that |rs| |pq|/ cos , that is, |rs| can be slightly larger than |pq|.

Our third modification is as follows. Instead of considering all pairs of points in nondecreasing order of their distances, we consider them in nondecreasing order of their approximate distances, to be defined below. As we will see later, this avoids having to explicitly consider all pairs of points.The approximate distances that we will use are based on the cones of C . For each cone C C , let C be a fixed ray that emanates from the origin and that is contained in C. For example, we can think of C as being the bisector of cone C. Recall the notation Cp := C + p := {x + p : x C} and lC,p := lC + p introduced in Section 4.1. For any cone C C , and any two points p and q in the plane, we define (refer to Figure 7.1)

Observe that C is not a metric; in particular, it is not a symmetric function. The following lemma states that C(p, q) is a good approximation for the Euclidean distance between p and q, if q Cp.

Lemma 7.3.1. Let C be a cone of C , and let p and q be two distinct points in the plane, such that q Cp. Then |pq| cos C(p, q) |pq|.proof Let be the angle between C,p and (p, q); see Figure 7.1. Then, 0 and cos = C(p, q)/|pq|. Hence, C(p, q) = |pq| cos |pq| cos and C(p, q) = |pq| cos |pq|.Now we are ready to present the modified version of algorithm GapGreedy. For each cone C of C , this modified algorithm computes a set EC of edges (p, q) such that q p C. The union of these sets will be the edge set of our final spanner.Consider a cone C of C . The algorithm initializes EC to the empty set. Then it computes two distinct points r and s for which C(r, s) is minimum, and adds the edge (r, s) to EC. Lemma 7.1.1 implies that, having added this edge, one may discard from further consideration for addition to EC, all edges (p, q) for which (i) q p C, and (ii) the distance between p and r is small. That is, after having added (r, s), each point p that is close to r should not occur as the source of any edge that is added to EC later during the algorithm. Similarly, after having added the edge (r, s) to EC, each point q that is close to s should not occur as the sink of any edge that is added to EC afterward. That is, the addition of edge (r, s) to EC causes certain points to become forbidden as a source or a sink.After having added the edge (r, s) to EC, the algorithm computes two distinct points r and s such that r is not forbidden as a source, s is not forbidden as a sink, and C(r , s ) is minimum. It adds the edge (r, s ) to EC, and makes the appropriate points forbidden as a source or forbidden as a sink. The algorithm repeats this, as long as there are nonforbidden points having a finite C-distance.The algorithm uses variables dist to keep track of the points that are forbidden as source or sink vertices. Initially, dist(r, s) = C(r, s), for any two points r and s in S. If an edge (r, s) is added to EC, then the algorithm finds all points p that are close to r, and, for each such p, assigns dist(p, q) :=, for all q S. Similarly, the algorithm finds all points q that are close to s, and, for each such q, assigns dist(p, q) :=, for all p S.Interpretation of the dist-variables: If p = q, then dist (p, q) is finite if and only if, (i) dist (p, q) = C(p, q), (ii) q p C (i.e., (p, q) may still be included in the edge set EC), (iii) p is not forbidden (yet) as a source, and (iv) q is not forbidden (yet) as a sink.Algorithm ModGapGreedy(S, ,w)

Comment: This algorithm takes as input a set S of n points in the plane, and two real numbers and w such that 0 < < /4 and 0 w < (cos sin )/2. The algorithm returns a directed t-spanner G = (S,E), for t = 1/(cos sin 2w).for each cone C of Cdo for each r S and s S do dist (r, s) := C(r, s) endfor;EC := ;while there are distinct points r and s such that dist (r, s) < do choose r and s (r = s) such that dist (r, s) is minimum;EC := EC {(r, s)};for each p S such that |pr| (w/2)|rs|do for each q S do dist (p, q) := endforendfor;for each q S such that |qs| (w/2)|rs|do for each p S do dist (p, q) := endforendforendwhileendfor;return the graph G = (S,E), where E :=U C ECLemma 7.3.2. Let and w be real numbers such that 0 < < /4 and 0 w < (cos sin )/2, and let S be a set of n points in the plane. The graph G = (S,E) that is returned by algorithm ModGapGreedy(S, ,w) is a t-spanner for S, for t = 1/(cos sin 2w). proof : Let p and q be two distinct points of S. If (p, q) E, then the three conditions of Lemma 7.1.1 hold. So assume that (p, q) is not contained in E. Let C be the cone of C such that q p C. Consider the iteration of the outer for-loop during which the edge set EC is constructed. At the start of this iteration, dist(p, q) is initialized to C(p, q), which is finite. Since (p, q) is not added to EC, the value of dist(p, q) changes to during one of the iterations of the while-loop. Let (r, s) be the edge that is added to EC during the iteration in which dist(p, q) is set to. At the start of this iteration, we have (i) dist(r, s) dist(p, q) < , (ii) dist(r, s) = C(r, s) and (iii) dist(p, q) = C(p, q). Moreover, we have |pr| (w/2)|rs| or |qs| (w/2)|rs|.We consider these two cases separately.Case 1: |pr| (w/ 2)|rs|.In this case, we have |pr| 2|pr| w|rs|. Since s r and q p are both contained in C, we have angle (pq, rs) . By Lemma 7.3.1, we have |rs| C(r, s)/ cos and C(p, q) |pq|. Since C(r, s) C(p, q), we conclude that |rs| |pq|/ cos . Hence, the three conditions of Lemma 7.1.1 hold for the points p and q.Case 2: |qs| (w/ 2)|rs|.It follows in the same way as in Case 1 that |qs| w|rs|, angle(qp, sr) and |rs| |pq|/ cos . Hence also in this case, the three conditions of Lemma 7.1.1 hold for the points p and q.We have shown that for any two distinct points p and q of S, the three conditions of Lemma 7.1.1 are satisfied. Therefore, the graph G is a t-spanner for S.Lemma 7.3.3. Let and w be real numbers such that 0 < < /4 and 0 w < (cos sin )/2, and let S be a set of n points in the plane.1. Algorithm ModGapGreedy(S, ,w) computes a graph in which each vertex has degree at most 22/.2. If w > 0, then the weight of this graph is less than 2/(1 + 2 2/w) log n times the weight of a minimum spanning tree of S.proof Consider an arbitrary cone C of C . Consider any two distinct edges (p, q) and (r, s) of EC. We may assume without loss of generality that (r, s) was added to EC before (p, q). We have |pr| > (w/2)|rs|and |qs| > (w/2)|rs|. This immediately implies that |pr| |pr| > (w/ 2)|rs| (w/2) min(|pq|, |rs|)and|qs| |qs| > (w/2)|rs| (w/2) min(|pq|, |rs|),that is, the strong (w/2)-gap property holds.The modified gap-greedy algorithm: For each cone C, set EC := and dist(r, s) := C(r, s) for all r S and s S. Repeatedly choose two distinct points r and s for which dist(r, s) is minimum (and finite). Add (r, s) to EC, and set dist(p, q) := for (i) all p that are close to r, and all q S, and (ii) all q that are close to s, and all p S. The region of closeness for r (resp. s) is the square centered at r (resp. s) and having sides of length 2(w/ 2)|rs|. The algorithm adds edges to EC in nondecreasing order of their C-distances, which is in approximately nondecreasing order of their Euclidean distances. By Lemma 7.1.1, the resulting graph has a small stretch factor. Moreover, each set EC satisfies the strong gap property.7.4 An efficient implementation of the gap-greedy algorithmIn this section, we show how to implement algorithm ModGapGreedy such that its running time is bounded by O(n log2 n).The main ingredients: The first ingredient is a data structure based on range trees that implicitly stores all finite dist-values, together with the minimum value among them. The second ingredient consists of two standard range trees that are used to find those points p and q for which |pr| (w/2)|rs|and |qs| (w/2)|rs|, respectively.The cone C is the intersection of two halfplanes h1 and h2 D1 and D2 be the lines through the origin that are orthogonal to h1 and h2, L be the line that contains the ray lC. lC,p to be the ray lC translated to emanate from point p.

Content of data structuresthe standard (orthogonal) coordinate axes as p1 and p2 for each point p

. For each i {1, 2}, pi is the signed Euclidean distance between the origin and the orthogonal projection of p onto Di

p3 is the signed Euclidean distance between the origin and the orthogonal projection of p onto L.

More notations C = {x R2 : xi 0, i = 1, 2}.for any p R2 Cp = {x R2 : xi pi, i = 1, 2}. Cp = {x R2 : xi pI , i = 1, 2}.

We assume for simplicity that the p1-,p2-, p1-, p2-, and p3-coordinates are distinct.

7.4.1 The main data structureLet S be a set of n points in the plane, and let C be any cone of C . The main data structure for finding minimal finite dist-value, use two operations:ForbidSource(p): sets dist(p, q) to for all q S.ForbidSink(q): sets dist(p, q) to f or all p S.This data structure has the form of a 3-layered range tree T; it depends on the cone.

The mindist-structure T : We use a 2-layered range tree, based on the p1- and p2-coordinates, to partition the set {(r, s) : r S, s S, r s, C(r, s) < } into O(n log n) subsets. Each subset is a Cartesian product of the form A B, for two sets A and B that can be separated by a line orthogonal to L. Since A is to the left of B, we have min{C(a, b) : a A, b B} = C(r, s), where r is the point of A for which r3 is maximum and s is the point of B for which s3 is minimum. We add a third layer to the range tree, storing the sets A and B sorted by their p3-coordinates.The layer 1 and 2 tree

Layer 1There is a balanced binary search treestoring the points of S at its leaves in nondecreasing order of their p1-coordinates. Internal nodes of this tree contain information to guide searches For any node v of the layer 1 tree, Sv1 is the subset of S that is stored in the subtree of v.Each node v of the layer 1 tree contains a pointer to the root of a balanced binary search tree, called a layer 2 tree

Layer 2storing the points of Sv1 in nondecreasing order of their p2-coordinates. internal nodes contain information to guide searches.Each node u of any layer 2 tree contains pointers to data structures of third layer

u2 (u) : a node in layer 2u1: a node of layer 1 that hast pointer to root of u2For each i {1, 2}, we denote by xui the maximal pi-coordinate that is stored in the left subtree of node ui .xu : The point with coordinates xu1 and xu2 (These coordinates are with respect to the axes D1 and D2. In general, xu is not an element of S.)Su3 : subset of {p Su2 : pi xui, i = 1, 2} Su3 Cxu S+u3 : subset of {p Su2 : pi xui, i = 1, 2} S+u3 Cxu

(During the algorithm, Su3 and S+u3 will be the subsets of Su2 (Cxu ) and Su2 Cxu consisting of those points that are not forbidden as a source and a sink, respectively)The third layerNode u of the layer 2 tree contains pointers to:1. a list storing the points of Su3, sorted in nondecreasing order of their p3-coordinates2. a list storing the points of S+u3, sorted in nondecreasing order of their p3-coordinates3. a variable 3(u) whose value is 3(u) = min{C(p, q) : p Su3, q S+u3 } If Su3 or S+u3 is empty, then 3(u)=.4., in case, 3(u) < , a pair (p, q) of points such that p Su3, q S+u3 and 3(u) =C(p, q).Hence, the minimal C-value is equal to the minimal 3-value.

Additional information stored in the nodes of layer 1 and layer 2 treesWe store with each node u of any layer 2 tree a variable 2(u),

In case 2(u) < , we also store with node u a corresponding pair of points that realizes 2(u).

For each node v of any layer 1 tree save a variable 1(v).

In case 1(v) < , we also store with node v a pair of points that realizes 1(v).Observe that the value 1(v), where v is the root of the layer 1 tree, is equal to the minimum of 3(u), where u ranges over all nodes of all layer 2 trees.

The dictionary

In order to speed up searching during the algorithm, we store all points of S in a dictionary, for example, a balanced binary search tree, where we can use any ordering of the points. Hence, we can in O(log n) time, search for an arbitrary point of S in this dictionary With each point p in the dictionary, we store the following:1. a list of pointers to all occurrences of p in the lists Su3 and2. a list of pointers to all occurrences of p in the lists S+u3.

Lemma 7.4.2. The mindist-structure T , together with the dictionary and its lists of pointers, has size O(n log2 n) and can be built in O(n log2 n) time.The operations ForbidSource and ForbidSink

Making a point forbidden as a source or a sink: If a point p is deleted from a list Su3, then it will not contribute anymore to the value 3(u). Therefore, deleting p from all lists Su3 in which it occurs corresponds to making p forbidden as a source (i.e., setting dist(p, q) to for all q S). Similarly, deleting a point q from all lists S+u3 in which it occurs corresponds to making q forbidden as a sink.Algorithm ForbidSource(T,p)Comment: This algorithm takes as input a point p of S. It makes p forbidden as a source, by deleting p from all lists Su3 in which it occurs. After these deletions, the algorithm updates the mindist-structure T .Step 1: Search for p in the dictionary, and follow the pointers to the positions of all occurrences of p in the lists Su3. For each such list Su3, carry out Steps 2 and 3.Step 2: Delete p from Su3. If the list S+u3 is empty, then we are done; otherwise, let q be the minimal element of S+u3. Go to Step 3.Step 3: If p was not the maximal element of Su3, then we are done. Otherwise, if p was the only element in Su3, then set 3(u) :=. Finally, if p was the maximal, but not the only element in Su3 , then let r be the new maximal element of Su3. In this case, set 3(u) := C(r, q) = q3 r3, and store the pair (r, q) with node u.Step 4: At this moment, all layer 3 lists and all 3-variables have been updated correctly.In this final step, the rest of the data structure is updated. Search for p in the layer 1 tree. For each node v on the search path, search for p in the layer 2 tree of v. Let lv be the leaf of this layer 2 tree in which the search ends. (Observe that 2(lv)=.) Then, starting at lv , walk back to the root of the layer 2 tree of v, and for each node u on the path, recompute the value of 2(u) using (7.2), and update the pair of points realizing 2(u).Having done this for all nodes v, all 2-variables have the correct values. The 1- variables are updated in a similar fashion: Let l be the leaf of the layer 1 tree that stores p. Then, starting at l , walk back to the root of the layer 1 tree, and for each node v on the path, recompute 1(v) using (7.3), and update the pair of points realizing 1(v).Lemma 7.4.3. The following two claims hold.1. Given a point p of S, algorithm ForbidSource(T,p) deletes p from all lists Su3 in which it occurs, and updates the entire mindist-structure, in O(log2 n) time.2. Given a point q of S, algorithm ForbidSink(T, q) deletes q from all lists S+u3 in which it occurs, and updates the entire mindist-structure, in O(log2 n) time.7.4.2 The final algorithmFor current cone C :1. The mindist-structure T , consisting of the 3-layered data structure, together with the dictionary and its lists of pointers.2. A 2-dimensional range tree ,denoted by RTsource, storing a subset of S according to their standard coordinates p1 and p2. A point of S is contained in this range tree if and only if it has not been forbidden as a source.3. A 2-dimensional range tree, denoted by RTsink, storing a subset of S according to their standard coordinates p1 and p2. A point of S is contained in this range tree if and only if it has not been forbidden as a sink.the range trees RTsource and RTsink can be used to find, for any two given points r and s, all points p and q such that |pr| (w/2)|rs| and |qs| (w/2)|rs|, respectively;.Algorithm FastGapGreedy(S, ,w)Comment: This algorithm takes as input a set S of n points in the plane, and two real numbers and w such that 0 < < /4 and 0 w < (cos sin )/2. The algorithm returns a directed t-spanner G = (S,E), for t = 1/(cos sin 2w).for each cone C of Cdo store the points of S in the mindist-structure T , such thatfor each node u of each layer 2 tree, the layer 3 lists Su3 and S+u3 store the sets {p Su2 : pi xui, i = 1, 2} and {p Su2 : pi xui, i = 1, 2}, respectively;store the points of S in the 2-dimensional range tree RTsource;store the points of S in the 2-dimensional range tree RTsink;EC := ; := 1-value stored with the root of the layer 1 tree of T ;while < do let (r, s) be the pair such that = C(r, s);EC := EC {(r, s)};for each p RTsource such that |pr| (w/2)|rs|do Delete(RTsource, p);ForbidSource(T,p)endfor;for each q RTsink such that |qs| (w/2)|rs|do Delete(RTsink, q);ForbidSink(T, q)endfor; := 1-value stored with the root of the layer 1 tree of Tendwhileendfor;return the graph G = (S,E), where E := UC ECLemma 7.4.4. Let C C , and consider the iteration of the outer for-loop of algorithm FastGapGreedy(S, ,w) during which the edge set EC is constructed. At the start of any iteration of the while-loop, we have = min{C(p, q) : p RTsource, q RTsink, p = q}.proof : First observe that < . Since the value of each i-variable, 1 i 3, is Either or C(p, q) for some p RTsource and q RTsink, it is clear that min{C(p, q) : p RTsource, q RTsink, p = q}. (7.4)If at least one of RTsource and RTsink is empty, then =. Hence, both these range trees are nonempty. Let r RTsource and s RTsink be two distinct points such thatC(r, s) = min{C(p, q) : p RTsource, q RTsink, p = q}.We will show that there is a node u in some layer 2 tree of T such that 3(u) = C(r, s).Since 3(u), this will imply that min{C(p, q) : p RTsource, q RTsink, p = q}and, therefore, complete the proof of the lemma.Let u1 be the lowest common ancestor of the leaves storing r and s in the layer 1 tree of T . Similarly, let u2 be the lowest common ancestor of the leaves storing r and s in the layer 2 tree that is attached to node u1. We will prove that 3(u2) = C(r, s). Let u := u2, and consider the point xu R2 as defined in the description of the layer 2 trees of T . (The nodes u1 and u2 defined in that description are exactly the nodes that we defined in the preceding paragraph.) Since < , inequality (7.4) implies that C(r, s) < and, hence, s Cr . Therefore, s1 r1 and s2 r2, that is, both in the layer 1 tree and in the layer 2 tree pointed to by u1, the leaf storing r is to the left of the leaf storing s. Then,the definitions of xu1 and xu2 immediately imply that r1 xu1 s1 and r2 xu2 s2.(See also Exercise 7.6.) Since r RTsource and s RTsink, the points r and s are contained in the lists Su3 and S+u3 , respectively. But then, since all points of Su3 are stored in Rtsource,all points of S+u3 are stored in RTsink, and C(r, s) is minimum, r and s must be the maximal and minimal elements in their lists, respectively. Then, the definition of 3(u) implies that 3(u) = C(r, s). Hence the result.Clim: ModGapGreedy and FastGapGreedy compute the same graph(S,E). we run both algorithms in parallel, and show that during each iteration of their while-loops, they add the same edge to E.Let C be a cone of C , and consider the corresponding outer for-loops of both algorithms. Immediately before the while-loops of both algorithms, we have, {dist(r, s) : r S, s S, r s, dist(r, s) < }= {C(r, s) : r RTsource, s RTsink, r = s, C(r, s) < }. Assume it holds at the start of a specific iteration of both the algorithms.Algorithm ModGapGreedy takes a pair (r, s) for which dist(r, s) is a minimal element in the set on the left-hand side of (7.5). By Lemma 7.4.4, algorithm FastGapGreedy takes a pair (r, s) for which C(r, s) is a minimal element in the set on the right-hand side of (7.5). Hence, we have dist(r,s) = C(r, s).may exist several minimal elements. In that case, we force algorithm ModGapGreedy to choose the pair that is chosen by algorithm FastGapGreedy. So Both algorithms add the edge (r, s) to their edge sets EC. Then ModGapGreedy updates certain dist-values, while FastGapGreedy updates the structures T , Rtsource, and RTsink. By comparing the algorithms, so after each iteration we have:{dist(r, s) : r S, s S, r s, dist(r, s) < }= {C(r, s) : r RTsource, s RTsink, r = s, C(r, s) < }. . This proves that algorithms ModGapGreedy and FastGapGreedy, indeed, compute the same edge set E.Finally, let us analyze the running time of algorithm FastGapGreedy(S, ,w). Consider a fixed cone C of C . the mindist-structure T has size O(n log2 n), and can be built in O(n log2 n) time. the range trees RTsource and Rtsink have size O(n log n), and can be built in O(n log n) time. a point can be deleted from a range tree in O(log2 n) time.Hence, the total time spent for all these queries and deletions in the range trees for each C is O(n log2 n).Since there are such cones, the total running time of the algorithm is O(n log2 n).Theorem 7.4.5. Let and w be real numbers such that 0 < < /4 and 0 w < (cos sin )/2, and let S be a set of n points in the plane. In O((1/)n log2 n) time and using O(n log2 n + (1/)n) space, algorithm FastGapGreedy(S, ,w) computes a t-spanner for S, such that

1. t = 1/(cos sin 2w),2. each vertex in the spanner has degree at most 2[2/], and3. If w > 0, the weight of the spanner is less than [2/](1 + 22/w) log n times the weight of a minimum spanning tree of S.7.5 Generalization to higher dimensionsindicate how algorithm FastGapGreedy(S, ,w) can be generalized to the higher dimensional case?Let d 2 be an integer constant, and let S be a set of n points in Rd . We choose two arbitrary real numbers and w such that 0 < < /4 and 0 w < (cos sin )/2. Observe that Lemma 7.1.1 remains valid. Let = d be as in (5.3), and let C be the -frame of Theorem 5.2.8. Recall that = O(1/d1).Let C be a cone in C.. Let D1,D2, . . . , Dd be the lines through the origin that are orthogonal to the hyperplanes bounding these halfspaces. Furthermore, let Dd+1 be the line through lC. For any point p in Rd , we write the coordinates of p with respect to the standard (orthogonal) coordinate axes as p1, p2, . . . , pd . For each i with 1 i d + 1, we denote by pi the coordinate of p with respect to the line Di . Using these coordinates, we can write the translated cone Cp as Cp = {x Rd : xi pi, i = 1, 2, . . . , d}.The approximate distance function C generalizes to

The mindist-structure T becomes a (d + 1)-layered data structure. The algorithmuses two d-dimensional range trees RTsource and RTsink, each storing a subset of S according to their standard coordinates p1, p2, . . . , pd . The output of algorithm FastGapGreedyDDim(S, ,w) consists of a directed t-spanner G = (S,E), for t = 1/(cos sin 2w).

Theorem 7.5.1. Let and w be real numbers such that 0 < < /4 and 0 w < (cos sin )/2, and let S be a set of n points in Rd. In O((1/d1)n logd n) time and usingO(n logd n + (1/d1)n) space, algorithm FastGapGreedyDDim(S, ,w) computes a t-spanner for S, such that1. t = 1/(cos sin 2w),2. each vertex in the spanner has degree O(1/d1), and3. the weight of this graph is O((1/d1)(1 + 1/w) log n) times the weight of a minimum spanning tree of S.