• No results found

A drawing algorithm for bitonic st-orderings

3.2 Straight-line drawings

3.2.3 A drawing algorithm for bitonic st-orderings

In the following, we describe how to adapt the algorithm from the previous section to bitonic st-orderings by borrowing some ideas from Harel and Sar-das [53]. They first describe a linear-time algorithm to compute a biconnected canonical ordering as defined in Definition 3.4. Then a modification of the al-gorithm of de Fraysseix, Pach and Pollack [33, 34] is used to obtain a planar straight-line layout. The key observation is that when installing a vertex vk that has at least two neighbors on the contour Ck−1, one can proceed as in the original algorithm we presented earlier (Algorithm 5).

The only problematic case is the one in which a vertex vkhas only one neigh-bor on Ck−1, say wi. Recall that Harel and Sardas [53] introduced the property

3.2 Straight-line drawings

wm

vk

w1

Gk−1

wi+1

wi

(a)

wm

vk

w1

Gk−1

wi+1

wi

(b)

Figure 3.11. (a) A vertex vk with only one predecessor wi has right support. Vertices in grey have not been drawn yet. (b) The result of using wi+1as a second neighbor on Ck−1 in the layout algorithm by setting wl= wi and wr= wi+1.

of having left, right and legal support for these vertices (see Definition 3.3).

Their solution to the problem is as follows: If vk has left support at its only neighbor wi, then one may use wi−1, the predecessor of wion Ck−1, as a second neighbor for vkand proceed as in the original algorithm by pretending that the edge (vk, wi−1) exists. However, this is only possible, because the property of having left support guarantees that all edges that have to be attached to wi later, follow (vk, wi) clockwise in the embedding. Roughly speaking, all edges to be attached later appear to the right of vk, so vkis placed to the left of wi to keep wiaccessible from above. Similarly, when vkhas right support, every edge incident to wi that is not yet present will be attached from the left. Therefore, in case of right support, we may use wi+1 as a second neighbor for vk. An example for having right support is given in Figure 3.11.

We already argued that the bitonic st-ordering has similar properties. With the following lemma, we gain the discussed property of having left and right support for bitonic st-orderings.

ILemma 3.14. Let G = (V, E) be a connected planar graph embedded in the plane with a corresponding bitonic st-ordering π. Moreover, let vk be the k-th vertex in π and Gk the subgraph induced by v1, . . . , vk. For every 1 < k ≤ |V | the following holds:

1. Gk and G − Gk are connected, 2. vk is in the outer face of Gk−1,

3. For every vertex v ∈ Vk, the neighbors of v that are not in Gk appear consecutively in the embedding around v.

Proof. The first and second statement hold for every st-ordering with s and t on the outer face. For the third statement assume to the contrary, that for some 1 < k ≤ |V | the neighbors of a vertex v with π(v) ≤ k that are in G−Gkdo not

wm

vk vk0

w1

Gk−1

(a)

wm= vR

vL= w1

wm−1

vk0 vk

w2

Gk−1

(b)

Figure 3.12. (a) The problem of having no legal support at the boundary of the contour Ck−1= {w1, . . . , wm}. The vertex to place has left support at w1 or right support at wm. (b) Two artificial vertices vL, vR, one at the beginning and one at the end of Ck−1= {vL= w1, . . . , wm= vR} may serve as a second neighbor of vk in Gk−1.

appear consecutively in the embedding around v. Then v has two successors wa, wc ∈ S(v) with π(wa) > k and π(wc) > k. Assume that wa precedes wc in S(v), that is a < c. Since all vertices in S(v) appear consecutively in the embedding, there exists then a third successor wb between wa and wc in S(v) that by our assumption is in Gk, that is, π(wb) ≤ k holds. Notice that S(v) is of the form S(v) = {. . . , wa, . . . , wb, . . . , wc, . . .} and π(wa) > π(wb) < π(wc) holds, which contradicts that S(v) is bitonic with respect to π.

It is not difficult to see that due to the third statement, we can use the idea of Harel and Sardas to deal with the case in which a vertex has only a single predecessor. When placing such a vertex, say vk, whose only predecessor is u, then we can assume that vk is not preceded and followed in S(u) by vertices with a label greater than k. Therefore, the concept of having left and right support translates to bitonic st-orderings in the following sense: vk has left support (at u) if no vertex preceding vk in S(u) exists with a label greater than k. And in a symmetric manner, vkhas right support, if there is no vertex following vk in S(u) with a label greater than k.

However, one problem arises: The approach by Harel and Sardas requires a vertex with only one neighbor on Ck−1 to have legal support, not just left or right support. A quick look at Definition3.3reveals that there is only a differ-ence at the boundary of the contour. More specifically, if the only predecessor of vk is w1 (or wm), then vk must have right support (or left support, respec-tively). This is, however, not necessarily the case in a bitonic st-ordering, where it may happen for example that vk has right support at wm. Let us assume for a moment that we have to cope with this case in which vkhas right support at wm. Hence, the edge (vk, wm) must have a slope of +1, thus, we are forced to choose wl = wm, whereas for wr we are then not able to find an appropriate vertex on Ck−1. See Figure 3.12a for an illustration of the problem of lacking legal support.

3.2 Straight-line drawings

procedure getLeftRightBitonic(vk, Ck−1= {w1, . . . , wm}) begin

l ← min{i | (wi, vk) ∈ E};

r ← max{i | (wi, vk) ∈ E};

// one predecessor case if l = r then

vp← preceding vertex of vk in S(wr);

if vp= nil or π(vp) ≤ k then l ← l − 1;

vs← following vertex of vk in S(wr);

if vs= nil or π(vs) ≤ k then r ← r + 1;

end

return (l, r) end

Algorithm 7: Computation of wland wr for vk with the one-predecessor case.

To overcome this problem and without limiting the applicability of our bitonic st-ordering, we make a small modification to the algorithm. We add two dummy vertices vLand vRthat take the roles of v1 and v2 in the original algo-rithm with the property that vLis always the first, and vRalways the last vertex in every contour, that is, for every 1 ≤ k ≤ n, Ck = {vL = w1, . . . , wm = vR} holds. Notice that vL and vR are isolated vertices, thus, there exists no vk whose only predecessor is vL or vR, and that has left or right support. Hence, we are always able to find a second neighbor on Ck−1 for vk as depicted in Figure 3.12b.

Now we put these ideas together by describing how to modify Algorithm5 from the previous section. We start by placing vL, v1 and vR at (0, 0), (1, 1) and (2, 0), respectively. In every step 2 ≤ k ≤ n, we proceed exactly as in Algorithm5, only the subroutine for determining wland wr has to be adjusted according to the idea of Harel and Sardas. The procedure displayed in Algo-rithm7 takes care of this additional case in which vk has only one neighbor on Ck−1. However, notice that if vkhas left and right support at wi, then wl= wi−1 and wr= wi+1is chosen. A complete example is shown in Figure3.13, in which the drawing for a small graph with seven vertices is created step by step.

Now it is not hard to see that only minor modifications are necessary to get Algorithm5to work with a bitonic st-ordering instead of a canonical ordering.

Besides the changes for the initial phase of Algorithm 5 such that vL, vR, v1 are placed accordingly, some minor corrections to the range of the loops have to be made. See Algorithm 8 for the detailed changes that are necessary. The missing parts in Algorithm 8should be replaced with the corresponding parts from Algorithm 5.

v1= s

Figure 3.13. (a) Example graph consisting of seven vertices with a bitonic st-ordering.

(b)-(h) Steps during the construction of the drawing. (c) v2 is supported by vR and serves in the next step (d) as supporting vertex for v3. (f) v5uses v1 as support.

We may conclude that Algorithm8enables us to use the idea of de Fraysseix et al., while the algorithm itself is driven by a bitonic st-ordering instead of a canonical one. Let us summarize this by stating the following theorem:

ITheorem 3.15. Given a plane graph G = (V, E) and a corresponding bitonic st-ordering π for G. A planar straight-line drawing for G of size (2|V | − 2) × (|V | − 1) can be obtained from π in time O(|V |).

Proof. We already argued the runtime, it remains to bound the area. Notice that the input consists besides the vertices of G of two additional vertices vL, vR. By Theorem 3.13, the drawing has then a size of 2|V | × |V |. However, vL and vR are dummy vertices and have to be removed anyway. Moreover, every other vertex is located above them. Hence, their removal yields a slightly smaller drawing of size (2|V | − 2) × (|V | − 1).