Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 7 : The Gap Greedy Algorithm By azam sadeghian.

Similar presentations


Presentation on theme: "Chapter 7 : The Gap Greedy Algorithm By azam sadeghian."— Presentation transcript:

1 Chapter 7 : The Gap Greedy Algorithm By azam sadeghian

2 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

3 7.1 A sufficient condition for “spannerhood” When 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.

4 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 that 1. angle (pq, rs) ≤ θ, 2. |rs| ≤ |pq|/ cos θ, and 3. |pr| ≤ w|rs| or |qs| ≤ w|rs|. Then, the graph G is a t-spanner for S.

5 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| in the 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 G contains 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 will consider the case only when |pr| ≤ w|rs|. (The case when |qs| ≤ w|rs| can be treated by a symmetric argument.) Since the premises of Lemma 6.4.1 from the previous chapter are satisfied, it follows from that lemma that |pr| < |pq|, |sq| < |pq|, and t |pr| + |rs| + t |sq| ≤ t |pq Hence, by the induction hypothesis, there are t-spanner paths in G from p to r, and from s to q. Consider the path in G that starts in p, follows the t-spanner path to r, then takes the edge from r to s, and finally follows the t-spanner path from s to q. The length of this path is bounded from above by t |pr| + |rs| + t |sq|, which, by (7.1), is less than or equal to t |pq|. Hence, G contains a t-spanner path from p to q.

6 7.2 The gap-greedy algorithm The 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.

7 Algorithm GapGreedy(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). 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) ∈ E do if angle (pq, rs) ≤ θ then add := add ∧ (|pr| > w|rs|) ∧ (|qs| > w|rs|) endif endfor; if add = true then E := E ∪ {(p, q)} endif endfor; return the graph G = (S,E)

8 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.

9 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 n proof 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).

10 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 C 1,C 2,..., C 2π/θ. For each i with 1 ≤ i ≤ 2π/θ, define E i := {(p, q) ∈ E : q − p ∈ C i }. Since E i ⊆ E for 1 ≤ i ≤ 2π/θ, it is clear that E i satisfies the strong w-gap property. Furthermore, Theorem 6.1.2 implies that no two distinct edges of E i share a source, and no two distinct edges of E i share a sink. Since the sets E i, 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.

11 7.3 Toward an efficient implementation A direct implementation of algorithm GapGreedy has running time (n 3 ). One of the obstacles in designing an o(n 2 )–time implementation of this algorithm is the fact that all pairs of points are considered. Next version running time is O(n log 2 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 = (p 1, p 2 ) and q = (q 1, q 2 ) will be denoted by |pq| ∞, i.e., |pq| ∞ = max(|p 1 − q 1 |, |p 2 − q 2 |). so | pq| ∞ ≤ |pq| ≤ √ 2|pq| ∞.

12 Modifications Modification 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.

13 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|.

14 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 C p := C + p := {x + p : x ∈ C} and l C,p := l C + 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)

15 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 ∈ C p.

16 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 ∈ C p. 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|.

17 Now we are ready to present the modified version of algorithm GapGreedy. For each cone C of C κ, this modified algorithm computes a set E C 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 E C 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 E C. Lemma 7.1.1 implies that, having added this edge, one may discard from further consideration for addition to E C, 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 E C later during the algorithm. Similarly, after having added the edge (r, s) to E C, each point q that is “close” to s should not occur as the sink of any edge that is added to E C afterward. That is, the addition of edge (r, s) to E C causes certain points to become forbidden as a source or a sink.

18 After having added the edge (r, s) to E C, 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 E C, 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 E C ), (iii) p is not forbidden (yet) as a source, and (iv) q is not forbidden (yet) as a sink.

19 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 C κ do for each r ∈ S and s ∈ S do dist (r, s) := δ C (r, s) endfor; E C := ∅ ; 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; E C := E C ∪ {(r, s)}; for each p ∈ S such that |pr| ∞ ≤ (w/√2)|rs| do for each q ∈ S do dist (p, q) :=∞ endfor endfor; for each q ∈ S such that |qs| ∞ ≤ (w/√2)|rs| do for each p ∈ S do dist (p, q) :=∞ endfor endfor endwhile endfor; return the graph G = (S,E), where E :=U C E C

20 Lemma 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 E C 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 E C, 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.

21 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.

22 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 E C. We may assume without loss of generality that (r, s) was added to E C 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.

23 The modified gap-greedy algorithm: For each cone C, set E C := ∅ 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 E C, 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 E C 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 E C satisfies the strong gap property.

24 7.4 An efficient implementation of the gap-greedy algorithm In this section, we show how to implement algorithm ModGapGreedy such that its running time is bounded by O(n log 2 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.

25 The cone C is the intersection of two halfplanes h 1 and h 2 D 1 and D 2 be the lines through the origin that are orthogonal to h 1 and h 2, L be the line that contains the ray l C. l C,p to be the ray l C translated to emanate from point p.

26 Content of data structures 1. the standard (orthogonal) coordinate axes as p 1 and p 2 for each point p 2.. For each i ∈ {1, 2}, p’ i is the signed Euclidean distance between the origin and the orthogonal projection of p onto D i 3. p’ 3 is the signed Euclidean distance between the origin and the orthogonal projection of p onto L.

27 More notations C = {x ∈ R 2 : xi≥ 0, i = 1, 2}. for any p ∈ R 2 C p = {x ∈ R2 : x’i≥ p’ i, i = 1, 2}. −C p = {x ∈ R 2 : x’ i ≤ p’ I, i = 1, 2}. We assume for simplicity that the p 1 -,p 2 -, p’ 1 -, p’ 2 -, and p’ 3 -coordinates are distinct.

28 7.4.1 The main data structure Let 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.

29

30 The mindist-structure T : We use a 2-layered range tree, based on the p’ 1 - and p’ 2 -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 r’ 3 is maximum and s is the point of B for which s’ 3 is minimum. We add a third layer to the range tree, storing the sets A and B sorted by their p’ 3 -coordinates.

31 The layer 1 and 2 tree Layer 1 There is a balanced binary search tree storing the points of S at its leaves in nondecreasing order of their p’ 1 -coordinates. Internal nodes of this tree contain information to guide searches For any node v of the layer 1 tree, S v1 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 2 storing the points of S v1 in nondecreasing order of their p’ 2 -coordinates. internal nodes contain information to guide searches. Each node u of any layer 2 tree contains pointers to data structures of third layer

32 u 2 (u) : a node in layer 2 u 1: a node of layer 1 that hast pointer to root of u 2 For each i ∈ {1, 2}, we denote by x’ ui the maximal p’ i -coordinate that is stored in the left subtree of node ui. x u : The point with coordinates x’ u1 and x’ u2 (These coordinates are with respect to the axes D 1 and D 2. In general, x u is not an element of S.) S − u3 : subset of {p ∈ S u2 : p’ i ≤ x’ ui, i = 1, 2} S − u3 € −C xu S + u3 : subset of {p ∈ S u2 : p’ i ≥ x’ ui, i = 1, 2} S + u3 € C xu (During the algorithm, S − u3 and S + u3 will be the subsets of S u2 ∩ (−C xu ) and S u2 ∩ C xu consisting of those points that are not forbidden as a source and a sink, respectively)

33 The third layer Node u of the layer 2 tree contains pointers to: 1. a list storing the points of S − u3, sorted in nondecreasing order of their p’ 3 -coordinates 2. a list storing the points of S + u3, sorted in nondecreasing order of their p’ 3 -coordinates 3. a variable η 3 (u) whose value is η 3 (u) = min{δ C (p, q) : p ∈ S − u3, q ∈ S + u3 } If S − u3 or S + u3 is empty, then η 3 (u)=∞. 4., in case, η 3 (u) < ∞, a pair (p, q) of points such that p ∈ S − u3, q ∈ S + u3 and η 3 (u) =δ C (p, q). Hence, the minimal δ C -value is equal to the minimal η 3 -value.

34 Additional information stored in the nodes of layer 1 and layer 2 trees We 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.

35 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 S − u3 and 2. 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 log 2 n) and can be built in O(n log 2 n) time.

36 The operations ForbidSource and ForbidSink Making a point forbidden as a source or a sink: If a point p is deleted from a list S − u3, then it will not “contribute” anymore to the value η 3 (u). Therefore, deleting p from all lists S − u3 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.

37 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 S − u3 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 S − u3. For each such list S − u3, carry out Steps 2 and 3. Step 2: Delete p from S − u3. 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 S−u3, then we are done. Otherwise, if p was the only element in S − u3, then set η 3 (u) :=∞. Finally, if p was the maximal, but not the only element in S − u3, then let r be the new maximal element of S − u3. In this case, set η 3 (u) := δ C (r, q) = q’ 3 − r‘ 3, 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 l v be the leaf of this layer 2 tree in which the search ends. (Observe that η 2 (l v )=∞.) Then, starting at l v, 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).

38 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 S − u3 in which it occurs, and updates the entire mindist-structure, in O(log 2 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(log 2 n) time.

39 7.4.2 The final algorithm For 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 RT source, storing a subset of S according to their standard coordinates p 1 and p 2. 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 RT sink, storing a subset of S according to their standard coordinates p 1 and p 2. 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 RT source and RT sink 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;.

40 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 C κ do store the points of S in the mindist- structure T, such that for each node u of each layer 2 tree, the layer 3 lists S − u3 and S + u3 store the sets {p ∈ S u2 : p’ i ≤ x’ ui, i = 1, 2} and {p ∈ S u2 : p’ i ≥ x’ ui, i = 1, 2}, respectively; store the points of S in the 2-dimensional range tree RT source ; store the points of S in the 2-dimensional range tree RT sink ; E C := ∅ ; η := η 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); E C := E C ∪ {(r, s)}; for each p ∈ RT source such that |pr| ∞ ≤ (w/√2)|rs| do Delete(RT source, p); ForbidSource(T,p) endfor; for each q ∈ RTsink such that |qs| ∞ ≤ (w/√2)|rs| do Delete(RT sink, q); ForbidSink(T, q) endfor; η := η 1 -value stored with the root of the layer 1 tree of T endwhile endfor; return the graph G = (S,E), where E := U C E C

41 Lemma 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 E C is constructed. At the start of any iteration of the while-loop, we have η = min{δ C (p, q) : p ∈ RT source, q ∈ RT sink, 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 ∈ RT source and q ∈ RT sink, it is clear that η ≥ min{δ C (p, q) : p ∈ RT source, q ∈ RT sink, p = q}. (7.4) If at least one of RT source and RT sink is empty, then η =∞. Hence, both these range trees are nonempty. Let r ∈ RT source and s ∈ RT sink be two distinct points such that δ C (r, s) = min{δ C (p, q) : p ∈ RT source, q ∈ RT sink, 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 ∈ RT source, q ∈ RT sink, p = q} and, therefore, complete the proof of the lemma.

42 Let u 1 be the lowest common ancestor of the leaves storing r and s in the layer 1 tree of T. Similarly, let u 2 be the lowest common ancestor of the leaves storing r and s in the layer 2 tree that is attached to node u 1. We will prove that η 3 (u 2 ) = δ C (r, s). Let u := u 2, and consider the point x u ∈ R 2 as defined in the description of the layer 2 trees of T. (The nodes u 1 and u 2 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 ∈ C r. Therefore, s’ 1 ≥ r’ 1 and s’ 2 ≥ r’ 2, 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 x’ u1 and x’ u2 immediately imply that r’ 1 ≤ x’ u1 ≤ s’ 1 and r’ 2 ≤ x’ u2 ≤ s’ 2.(See also Exercise 7.6.) Since r ∈ RT source and s ∈ RT sink, the points r and s are contained in the lists S − u3 and S + u3, respectively. But then, since all points of S − u3 are stored in Rt source,all points of S+u3 are stored in RT sink, 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.

43 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 ∈ RT source, s ∈ RT sink, 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’’).

44 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 E C. Then ModGapGreedy updates certain dist-values, while FastGapGreedy updates the structures T, Rt source, and RT sink. 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 ∈ RT source, s ∈ RT sink, 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 log 2 n), and can be built in O(n log 2 n) time. the range trees RT source and Rt sink 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(log 2 n) time.  Hence, the total time spent for all these queries and deletions in the range trees for each C is O(n log 2 n).  Since there are κ such cones, the total running time of the algorithm is O(κn log 2 n).

45 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 log 2 n) time and using O(n log 2 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π/θ], and 3. If w > 0, the weight of the spanner is less than [2π/θ](1 + 2√2/w) log n times the weight of a minimum spanning tree of S.

46 7.5 Generalization to higher dimensions indicate 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 R d. 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/θ d−1 ). Let C be a cone in C κ.. Let D 1,D 2,..., D d be the lines through the origin that are orthogonal to the hyperplanes bounding these halfspaces. Furthermore, let D d+1 be the line through l C. For any point p in R d, we write the coordinates of p with respect to the standard (orthogonal) coordinate axes as p 1, p 2,..., p d. For each i with 1 ≤ i ≤ d + 1, we denote by p’ i the coordinate of p with respect to the line D i. Using these coordinates, we can write the translated cone C p as C p = {x ∈ R d : x’ i ≥ p’ i, i = 1, 2,..., d}.

47 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 RT source and RT sink, 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).

48 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/θd−1)n logd n) time and usingO( n logd n + (1/θd−1)n) space, algorithm FastGapGreedyDDim(S, θ,w) computes a t-spanner for S, such that 1. t = 1/(cos θ − sin θ − 2w), 2. each vertex in the spanner has degree O(1/θd−1), and 3. the weight of this graph is O((1/θd−1)(1 + 1/w) log n) times the weight of a minimum spanning tree of S.


Download ppt "Chapter 7 : The Gap Greedy Algorithm By azam sadeghian."

Similar presentations


Ads by Google