 # (Faster) Multi-Sided Boundary Labelling

A 1-bend boundary labelling problem consists of an axis-aligned rectangle B, n points (called sites) in the interior, and n points (called ports) on the labels along the boundary of B. The goal is to find a set of n axis-aligned curves (called leaders), each having at most one bend and connecting one site to one port, such that the leaders are pairwise disjoint. A 1-bend boundary labelling problem is k-sided (1≤ k≤ 4) if the ports appear on k different sides of B. Kindermann et al. ["Multi-Sided Boundary Labeling", Algorithmica, 76(1): 225-258, 2016] showed that the 1-bend three-sided and four-sided boundary labelling problems can be solved in O(n^4) and O(n^9) time, respectively. Bose et al. [SWAT, 12:1-12:14, 2018] improved the latter running time to O(n^6) by reducing the problem to computing maximum independent set in an outerstring graph. In this paper, we improve both previous results by giving new algorithms with running times O(n^3log n) and O(n^5) to solve the 1-bend three-sided and four-sided boundary labelling problems, respectively.

## Authors

##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1 Introduction

Map labelling is a well-known problem in cartography with applications in educational diagrams, system manuals and scientific visualization. Traditional map labelling that places the labels on the map such that each label is incident to its corresponding feature, creates overlap between labels if the features are densely located on the map. This motivated the use of leaders [15, 9]: line segments that connect features to their labels. As a formal investigation of this approach, Bekos et al.  introduced boundary labelling: all the labels are required to be placed on the boundary of the map and to be connected to their features using leaders. The point where a leader touches the label is called a port. Their work initiated a line of research in developing labelling algorithms with different labelling aesthetics, such as minimizing leader crossings, number of bends per leader and sum of leader lengths [1, 2, 4, 5].

In this paper, we study the -bend -sided boundary labelling problem. The input is an axis-aligned rectangle and a set of points (called sites) in the interior of . In addition, the input contains a set of points on the boundary of representing the ports on consecutive sides of for some . The objective is to decide whether each site can be connected to a unique port using an axis-aligned leader with at most bend such that the leaders are disjoint and each leader lies entirely in the interior of , except the endpoint that is attached to a port. Figure 1(a) illustrates a labelling for a 1-bend -sided boundary labelling instance. If such a solution exists, then we call it a feasible solution and say that the problem is solvable. Notice that not every instance of the boundary labelling problem is solvable; see Figure 1(b). Figure 1: (a) An 1-bend four-sided boundary labelling problem with w=4,x=3,y=1 and z=2, (b) an instance of the 1-bend two-sided boundary labelling problem with no planar solution with 1-bend leaders, and (c) a partitioned solution. (d) The sequence of empty rectangles.

#### Related work.

The boundary labelling problem was first formulated by Bekos et al.  who solved the 1-bend one-sided and 1-bend two-sided models (when the ports lie on two opposite sides of ) in time. They also gave an -time algorithm for the 2-bend four-sided boundary labelling problem (i.e., when each leader can have at most 2 bends).

Kindermann et al.  examined -sided boundary labelling, where the ports appear on adjacent sides. For the 1-bend two-sided boundary labelling problem, they gave an -time algorithm. For 1-bend three- and four-sided models of the problem, they gave - and -time algorithms, respectively. If a boundary labelling instance admits an affirmative solution, then it is desirable to seek for a labelling that optimizes a labelling aesthetic, such as minimizing the sum of the leader lengths or minimizing the number of bends per leader. For minimizing the sum of leader lengths, Bekos et al.  gave an exact -time algorithm for the 1-bend one-sided and 1-bend (opposite) two-sided models; their algorithm for 1-bend one-sided model was later improved to an -time algorithm by Benkert et al. .

Kindermann et al.  gave an -time dynamic programming algorithm for the 1-bend (adjacent) two-sided model. Bose et al.  (see  for the full version) improved this result by giving an -time dynamic programming algorithm. They also showed that the 1-bend three- and four-sided problems (for the sum of the leader length minimization) can be reduced to the maximum independent set problem on outerstring graphs. The idea is to, for each site, obtain leaders by connecting the site to every port. Consider each leader as an outerstring (i.e., a polygonal curve that has one endpoint attached to the boundary of an enclosing rectangle). This forms an outerstring graph. Then, by an appropriate weight assignment for edges, the boundary labelling problem is equivalent to the maximum-weight independent set problem on this outerstring graph. Since we have outerstrings (where is the number of sites) and maximum-weight independent set can be solved in time on outerstring graphs (here, is the complexity of geometrically representing the input graph) , they obtain an -time algorithm for the three- and four-sided boundary labelling problem. However, it is not obvious whether this approach can be used to obtain a faster algorithm for the decision version, where we do not require leader length minimization.

Other models for boundary labelling such as labelling with sliding ports , dynamic boundary labelling , boundary labelling with octilinear leaders , many-to-one boundary labelling [13, 12] and boundary labelling in the presence of obstacles  has also been studied. Moreover, see [4, 5] for results on bend minimization. Throughout the paper, we consider 1-bend leaders, which are also known as -leaders .

#### Our results.

In this paper, we give algorithms with running times and for the 1-bend three-sided and four-sided boundary labelling problems, which improves the previously best known algorithms by nearly a linear factor.

The fastest known algorithm for the three-sided model was Kindermann et al.’s  -time algorithm that reduced the problem into two-sided boundary labelling problems. While we also use their partitioning technique, our improvement comes from a dynamic programming approach that carefully decomposes three-sided problems into various simple shapes that are not necessarily rectangular. We prove that such a decomposition can be computed fast using suitable data-structures. The crux of our approach is to show new properties of simpler types of problems and then using them as building blocks to solve the main labelling problem.

For the four-sided model, the fastest known algorithm was the -time algorithm of Bose et al.  that reduced the problem into the maximum independent set problem in an outerstring graph. We show that Kindermann et al.’s  observation on partitioning two-sided boundary labelling problems using a -monotone curve can be used to find a fast solution for the four-sided model. Such an approach was previously taken by Bose et al. , but it already took time for the 2-sided model, and they eventually settled with an -time algorithm for the four-sided model. With the four sides involved, designing a decomposition with a few different types of shapes of low complexity becomes challenging. Our improvement results from a systematic decomposition that generates a small number of subproblems at the expense of using a larger size dynamic programming table, resulting in an -time algorithm.

## 2 Preliminaries

In this section, we give some notation and preliminaries that will be used in the rest of the paper. For a point in the plane, we denote the - and -coordinates of by and , respectively. Consider the input rectangle and let denote the corners of that are named in clockwise order such that is the top-right corner of . Let and denote the top, bottom, left and right sides of , respectively. We refer to a port as a top port (resp., bottom, left and right port), if it lies on (resp., and ). Similarly, we call a leader a top leader (resp., bottom, left and right leader), if it is connected to a top port (resp., bottom, left and right port).

Let be the number of ports on the top, right, bottom and left side of ; notice that . We denote these ports as and in clockwise order. See Figure 1(a) for an example. We assume that the sites are in general position; i.e., the number of sites and ports on every horizontal (similarly, vertical) line that properly intersects is at most one. For the rest of the paper, whenever we say a rectangle, we mean an axis-aligned rectangle.

For a point inside , consider the rectangle that is spanned by and , where . Each rectangle contains only two types of ports; e.g., contains only top and right ports. A feasible solution for a solvable instance of a boundary labelling problem is called partitioned, if there exists a point such that for each rectangle , there exists an axis-aligned -monotone polygonal curve from to that separates the two types of leaders in . That is, every pair of sites in that lie on different sides of are connected to ports that lie on different (but adjacent) sides of . See Figure 1(c). We refer to the polygonal curve as the -separating curve. Kindermann et al.  observed that if an instance of a boundary labelling problem admits a feasible solution, then it must admit a partitioned solution.

###### Lemma 2.1 (Kindermann et al. ).

If there exists a feasible solution for the 1-bend four-sided boundary labelling problem, then there also exists a partitioned solution for the problem.

Consider a two-sided problem where the ports are on and . Assume that the problem has a feasible solution, and let be an -separating curve. Let (resp., ) be the polygonal regions above (resp., below ) that is bounded by and (resp., by and ). Now, let (resp., ) be the -separating curve that minimizes the area of (resp., ). Given and , we construct a sequence of rectangles as follows (see Figure 1(d)).

• Each rectangle is a maximal rectangle between and .

• The bottom-left corner of is . Since is maximal, it is uniquely determined.

• Let . We know that the top and right sides of are determined by a pair of leaders and , respectively. Let be the rightmost point on the top side of , and let be the topmost point on the right side of . Then the rectangle is the maximal empty rectangle whose bottom-left corner is and that is bounded by and .

We say that an instance of the problem is balanced if it contains the same number of sites and ports. We next show the following result that will be useful in the following sections.

###### Lemma 2.2.

Let be a 1-bend one-sided boundary labelling problem with a constraint that the leftmost and rightmost ports on must be connected to a pair of points , respectively. Let be the rightmost or bottommost site of the problem excluding and . If has a feasible solution satisfying the given constraint, then it also has a solution with connects to the first port (while walking from to along the boundary) that decomposes the problem into two balanced subproblems.

###### Proof.

First, assume that is the bottommost point (see Figure 2(a)–(b)). Assume for a contradiction that connecting to would not give a feasible solution, whereas there is another port such that connecting to would yield a feasible solution.

Note that lies to the left of . Let be the leader of . We swap the leaders of and . Such a swap may introduce crossings in the rectangular region to the right side of . However, after the swap both sides of the leader of in are balanced one-sided problems (see Figure 2(c)). Such a solution with crossings to a 1-sided boundary labelling problem can always be made planar by local swaps . The proof for the case when is the rightmost point is the same. Figure 2(e)–(h) illustrate such a scenario. ∎ Figure 2: An illustration in supporting the proof of Lemma 2.2.

## 3 Three-Sided Boundary Labelling

In this section, we give an -time algorithm for the three-sided boundary labelling problem. We assume that the ports are located on and . Kindermann et al.  gave an -time algorithm for this problem as follows. Consider the grid induced by a horizontal and a vertical line through every port and site. For each node of this grid, they partition the three-sided problem into an -shaped two-sided and a -shaped two-sided problem (Figure 3(a)–(b)). They showed that the three-sided problem is solvable if and only if there exists a grid node whose two two-sided problems both are solvable.

### 3.1 Algorithm Overview

We also start by considering every grid node , but we employ a dynamic programming approach that expresses the resulting two-sided subproblems by and a port. We show that the two-sided subproblems can have different types. This gives us different tables, each of size . We show that the running time to fill all the entries is . For a grid node , let be the projection of onto . The point splits the ports on into two sets: those to the left of and those to the right of it. This means that the line segment can be extended to an axis-aligned curve with two bends that splits the problem into two balanced - and -shaped two-sided subproblems; see Figure 3. Kindermann et al.  observed that such a balanced partition is unique. Hence if there exists a balanced partition by extending to a 2-bend curve, then there must be a unique position where the number of sites to the left of the curve matches the number of ports to the left of .

In the following, we describe the details of solving the - and -shaped two-sided problems. W.l.o.g., we assume that the two-sided problem contains the top-left corner of . While decomposing an -shaped problem, we will reduce it either into a smaller -shaped problem or a rectangular two-sided problem. Decomposition of -shaped problem is more involved. Figure 3: (a)–(b) An L- and a Γ-shaped problem. (c)–(d) Encoding of the L-shaped problems. The site q that determines the boundary of the L-shape can be recovered from the encoding.

### 3.2 Solving an L-Shaped Problem

We denote an -shaped subproblem with a grid node and a port , where lies either on or . If is a port on (i.e., for some ), then we denote the subproblem by in which the bottom side is determined by a horizontal line through (e.g., see Figure 3(c)). Here, the last parameter denotes whether the port belongs to or . Initially, we assume a dummy port located at and so our goal is to compute . On the other hand, if for some (i.e., it is a port on ), then we define the problem as (see Figure 3(d))). Here, the goal is to compute , where is a dummy port at .

To decompose , we find the rightmost site of the subproblem in time (Figure 4(a)). We first do some preprocessing, and then consider two cases depending on whether lies to the left or right side of the vertical line through .

For the preprocessing, we keep the sites and ports in a range counting data structure that supports counting query . Second, for each horizontal slab determined by a pair of horizontal grid lines (passing through sites and ports), we keep the points inside the slab in a sorted array , which takes time. We now use these data structures to find . We first compute the sites and ports in the rectangle determined by the diagonal , and then find the number of points needed in time. Finally, we find a site (that balances the number of sites and points) in time by a binary search in the array for the slab determined by the horizontal grid lines through and . If lies to the right of the vertical line through , then is the desired point . Otherwise, lies to the left of the vertical line through , and we can find by searching in the array for the slab determined by the horizontal grid lines through and . We will frequently search for such a unique site throughout the paper and so we will use a similar preprocessing.

#### Case 1 (p lies to the right side of the vertical line through x).

We connect to the “right” port: after connecting, the resulting subproblems are balanced; i.e., the number of sites in each resulting subproblem is the same as the number of ports of that subproblem. There might be several ports that are right in this sense, but one can apply Lemma 2.2 (assuming dummy leaders as boundary constraints) to show that the subproblem has a feasible solution if and only if there exists a feasible solution connecting either to the bottommost or to the rightmost port that satisfies the balanced condition. Once we find and the appropriate port for , there are three possible scenarios as illustrated in Figure 4. We can decompose the subproblem using the following recursive formula (depending on whether is connected to or ):

 T({x,ℓi},left)={T({x,ℓj},left)∧T′e.g., see Figure~{}???(a)--???(b), or T({x,tj},top)∧T({y,ℓi},left)e.g., % see Figure~{}???(c)

Here, is an -shaped one-sided problem and is a rectangular one-sided problem. There always exists a solution for the balanced rectangular one-sided problem , and thus can be considered as true. Since is balanced, we can show that there always exists a solution for , as follows. First assume that the vertical line through does not pass through a port (see Figure 5(a)). Let be the rightmost port in , and let be the set of points inside the rectangle determined by diagonal . Scale down the rectangle horizontally and translate the rectangle inside the vertical slab determined by the vertical lines through and . There always exists a solution for the balanced rectangular one-sided problem , we can translate the points back to their original position extending the leaders as necessary. The case when the vertical line through passes through a port can be processed in the same way, by first connecting to the topmost point of , and then choosing the port immediately to the left of as . We thus have the following recurrence formula.

 T({x,ℓi},left)={T({x,ℓj},left) if ℓj exists, e.g., see Figure~{}???(a)--% ???(b), orT({y,ℓi},left) if tj exists, e.g., see Figure~{}% ???(c)

We now show how to find the point and then decompose . The table is of size . We will show that each subproblem can be solved by a constant number of table look-ups, and these entries can be found in time. Hence, the overall computation takes time. Figure 4: The decomposition of an L-shaped problem when b=ℓi. Figure 5: (a) Reducing T({x,tj},top) to a rectangular one-sided problem, and (b) finding the port c for p when c=tj for some j. (c) Precomputation of the two-sided problems.

We now show how to find the “right” port for . First, assume that is a port on (see Figure 4(a)–(b)). We need another -time preprocessing as follows. Define a table , where is a site, and is a port on . At the entry , we store the port such that is the smallest index for which the rectangle defined by , the horizontal lines through and the vertical line through contains exactly sites. We set to 0 when no such port exists. The table has size and we can fill each entry of the table in time; hence, we can fill out the entire in time. Observe that the port for is stored in .

Consider now the case when is a port on (see Figure 4(c)). We again rely on an -time preprocessing. For every site and a vertical grid line (passing through a port or a site) to the left of , we keep a sorted array of size . Each element of the array corresponds to a rectangle bounded by the horizontal line through , , and another vertical grid line through a port to the left of . The rectangles are sorted based on the difference between the sites and ports and then by the -coordinate of . Consequently, to find , we can look for the number of sites in the rectangle determined by the diagonal (see Figure 5(b)), and then binary search for that number in the precomputed array for .

#### Case 2 (p lies to the left side of the vertical line through x).

Let be the intersection of the vertical line through and the leader connecting and (see Figure 5(c)). Since is the rightmost point, it suffices to solve the rectangular two-sided problem determined by the rectangle with diagonal (shown in falling pattern). We will determine whether a solution exists in time based on some precomputed information, as follows.

For each vertical grid line, we will precompute the topmost horizontal grid line such that the two-sided problem (shown in orange) determined by these lines, and has a feasible solution. If lies above , then the two-sided problem is solvable (as the remaining region determines a balanced one-sided problem); otherwise, it is not solvable. We will use the known -time algorithm  to check the feasibility of a two-sided problem, which looks for a “partitioned” solution. However, we do not necessarily require our two-sided problem to be partitioned.

We now show that the precomputation takes time. For every vertical grid line , we first compute a sorted array of horizontal grid lines such that the two-sided problem determined by and each element of is balanced. This takes time for and time for all vertical grid lines. For each , we then do a binary search on to find the topmost grid line such that the corresponding two-sided problem has a feasible solution. Since computing a solution to the two-sided problem takes time , can be found in time for , and in time for all the vertical grid lines.

#### Remark.

While decomposing -shapes, we always find the rightmost point . If the -coordinate of is larger than that of , then the subproblems and are also -shaped. Otherwise, the problem reduces to a rectangular one-sided or two-sided problem. Hence a -shape problem does not appear during the decomposition of -shaped problems.

### 3.3 Solving a Γ-Shaped Problem

Consider the -shaped problem containing the top-left corner ; see e.g. Figure 6(a). Let be the projection of onto , and let be the other bend of the shape. In the following, we refer to the rectangle with diagonal as the forbidden region.

Kindermann et al. [11, Lemma 8] observed that there must exist an axis-aligned -monotone curve that connects to such that the sites above are connected to top ports and the sites below are connected to left ports. We extend to along the vertical line (e.g., see Figure 6(b)). Since no leader will enter the forbidden region, we can now consider as a separating curve for a two-sided problem determined by the rectangle with diagonal . For any partitioned solution, we can compute a sequence of maximal empty rectangles, as we discussed in Section 2, such that the lower-right corner of coincides with . To decompose the problem, consider the first rectangle in this sequence. The rectangle can either cover the forbidden region entirely or partially in three different ways; see Figure 6(b). Since the separating curve through the grid point (Figure 6(a)) determines a partition, the leaders of the -shape must not enter into the forbidden region. Therefore, it suffices to consider an empty rectangle that entirely covers the forbidden region. Figure 6: (a) A Γ-shaped problem. (b)–(c) Three possibilities for the empty rectangle R1, and a sequence of maximal rectangles corresponding to the separating curve. (d) Rectangle R1 decomposes the problem into two one-sided subproblems and a smaller two-sided subproblem. (e)–(j) All possible cases for the two leaders determining the top and left sides of R1.

Since is maximal, the top or left side of must contain a site (e.g., see Figure 6(c)); because otherwise, the leaders that determines the top and left side of will cross. Assume w.l.o.g. that the top side of contains a site that is connected to a port . Notice that cannot be a left port because it contradicts the existence of the curve . Moreover, the left side of either contains a site or it is aligned with a leader that connects a port to a site . The bottom row in Figure 6 shows all possible scenarios; notice that cannot be connected to a top port, again because of having . This decomposes the problem into three subproblems (see Figure 6(d)). Two one-sided subproblems and , and a smaller two-sided subproblem. is bounded by the leader connecting to , the left side of , and . The subproblem is bounded by the leader connecting to , , the curve determined by , and the top side of .

The smaller two-sided subproblem is bounded by , the leaders incident to and , and the boundary of . We solve such two-sided problems by finding a sequence of maximal empty rectangles as described in Section 2. The idea is inspired by Bose et al.’s  approach to solve a two-sided problem using a compact encoding for the table. Since we do not optimize the sum of leader lengths, our approach is much simpler.

#### Decomposing two-sided subproblems.

To decompose the two-sided subproblems, we use the following observation.

###### Lemma 3.1 (Bose et al. ).

If a two-sided boundary labelling problem with sites on and has a feasible solution, then there exists a partitioned solution where every maximal empty rectangle contains a site either on its top or on its left side.

We first describe how to represent the two-sided problems. If the maximal empty rectangle contains a site on its top side (Figure 6(g)), then we represent the problem with the ports and the -coordinate of the left side of , i.e., and -coordinate of . Otherwise, we use the ports and the -coordinate of the top side of .

Formally, define a table (resp., ), where and are two ports and denotes the -coordinate (resp., -coordinate) of the site to which the port (resp., ) is connected (see Figure 7). Given (similarly, ), we can completely determine the problem boundary, as follows. Note that by definition the left side of (the rectangle that defined the subproblem, shown in pink) has the -coordinate . Hence the site of lies on the top side of (by Lemma 3.1). We can thus perform a binary search to find this site. Once we have the two sites (and so the two incident leaders), we can find the lower right corner for the next candidate rectangle as defined in Section 2. Figure 7: An illustration for solving the two-sided subproblems arising in a Γ-shaped problem.

We now show how to compute ; the other is symmetric. After we determine the lower right corner for the next subsequent rectangle, we look for all candidate maximal empty rectangles with lower right corner . Consider now one such candidate rectangle (shown in orange in Figure 7), and let and be the ports defining its left and top sides, respectively. This now decomposes into three subproblems; namely, two one-sided subproblems defined by and , and a two-sided subproblem. By Lemma 3.1, contains a site on its top or left side. If the top side of contains a site, then we look-up the entry ; otherwise, we look-up the entry . We hence have the following recurrence relation.

 Tx(ℓi,tj,z)=⎧⎪ ⎪ ⎪⎨⎪ ⎪ ⎪⎩Tx(ℓi′,tj′,z)∧T1∧T2if the top side of R′ contains a site% ,e.g., see Figure~{}???(left) and Figure~{}???(right)Ty(ℓi′,tj′,z)∧T1∧T2if the% top side of R′ does not contain a site,e.g., see Figure~{}???(middle).

Here, and are one-sided problems, bounded by two leaders and a maximum empty rectangle. In the following, we discuss how to solve these problems.

#### Solving one-sided problems.

If , where , is a balanced rectangular one-sided problem (Figure 8(d)–(e)), then it has a feasible solution . If is -shaped and bounded by one side of the maximum empty rectangle (Figure 8(f)), then it can be reduced to a rectangular one-sided problem, as described in Section 3.2. Otherwise, the boundary of contains two sides of the maximal empty rectangle (Figure 8(a)–(b)), or one side of the maximal empty rectangle and two vertical segments of the two leaders (Figure 8(c)). In such a case, we can decide whether it has a feasible solution in time, as follows.

Let be the bottom-left corner of the empty rectangle and the bend point of the leader of (Figure 8(a)–(c)), respectively. Let be the number of sites in the open rectangle determined by the diagonal . Let be a port such that there are ports between and (including ). If the -coordinate of is not larger than that of (or , if is below ), then we can decompose the problem into two subproblems such that both of them have a feasible solution. One of these subproblems is a rectangular one-sided problem (shown in pink), and the other is an -shaped one-sided problem (shown in green). Both of them are balanced. The existence of a solution is immediate from  for the rectangular case. The existence of a solution for the -shaped case is by the reduction to a one-sided rectangular problem (Section 3.2). If the -coordinate of is larger than that of (or that of , if is below ), then there does not exist a solution with leaders not intersecting the empty rectangle (or the leader of ). Figure 8: An illustration for solving the one-sided subproblems arising in a Γ-shaped problem.

Note that the table and are of size and each subproblem can be solved by examining a set of candidate rectangles. Bose et al.  observed that the number of such candidate rectangles is , and while searching for candidate rectangles, no rectangle appears more than once. Thus the total number of table look ups is bounded by . Furthermore, all these rectangles can be precomputed in time . Hence, the overall time to solve a -shaped problem is . The following theorem summarizes the result of this section.

###### Theorem 3.1.

Given a 1-bend three-sided boundary labelling problem with sites and ports, one can find a feasible solution (if exists) in time.

## 4 Four-Sided Boundary Labelling

In this section, we give an -time dynamic programming algorithm for the four-sided boundary labelling.

### 4.1 Algorithm Overview

Our dynamic programming solution will search for a set of maximal empty rectangles corresponding to the -separating curve, as described in Section 2. The intuition is to represent a problem using at most two given leaders. For example, in Figure 9(a) the first empty rectangle is , with the top and right sides of determined by the leaders of and , respectively. The problem will have a feasible solution with these given leaders if and only if the subproblems and (shown in falling and rising patterns, respectively) have feasible solutions. Since the subproblems must be balanced, given the two leaders adjacent to (see Figure 9(a)), we can determine the boundary of the problem. We will use this idea to encode the subproblems.

It may initially appear that to precisely describe a subproblem, one should need some additional information along with the two given leaders. For example, the dashed boundary in Figure 9(b). However, such information can be derived from the given leaders. Here, the top-right corner of (hence, the dashed line) can be recovered using the -coordinate of the bottommost point of the leader of , and the -coordinate of the leftmost point of the leader of . We will try all possible choices for the first empty rectangle . In a general step, we will continue searching for the subsequent empty rectangle. For example, consider the subproblem in Figure 9(b). For a subsequent empty rectangle, we will decompose the problem into at most three new subproblems (Figure 9(c)). Each of these new subproblems can be represented using at most two leaders.

### 4.2 Solving Subproblems

We will distinguish the subproblems depending on whether they contain the top-right corner of the rectangle or not. We first outline the case when a subproblem contains . Figure 10: Recovering the boundary (red) from the leaders when Ri contains a site on its top side.

#### A subproblem contains c1.

We denote a subproblem that contains by . Here, are the two ports on the opposite sides of the separating curve, and and are their corresponding sites. Given , we can completely determine the boundary of the subproblem, as follows. Let and be a pair of points on the leaders of and , respectively, with the minimum Euclidean distance. Then, the rectangle with diagonal determines the boundary of the subproblem. Figure 10 illustrates the cases (up to the horizontal or vertical reflection of the sites), where the maximal empty rectangle contains a site on its top side. The recovered boundary is shown in red. On the other hand, Figure 11 illustrates the cases when does not contain any site on its top or right side. If there are several choices for , then we take the one with the smallest -coordinate (or, symmetrically smallest -coordinate) as illustrated in Figure 11(d). Figure 11: Recovering the boundary (red) when Ri does not contain sites on its top or right side.

We now show how to decompose subproblems containing . Since we are searching for a partitioned solution, the decomposition must contain at least one such subproblem. Let be the empty rectangle associated with (Figure 12(a)). First assume the case when is on and is on . Let be the pair of points with the minimum Euclidean distance between the leaders of and . Let be the rectangle with diagonal . Note that we can choose the bottom left corner of as the bottom left corner of the subsequent empty rectangle . There are choices for the top-right corner of . Thus trying all these subproblems would take time to fill the table entry corresponding to .

Instead of searching for directly, we first extend vertically (Figure 12(b)) and then horizontally (Figure 12(c)). Thus the subsequent rectangle in our approach will have choices for the top boundary. The leader that determines the top boundary will partition the problem into two subproblems: one is a problem that includes , and the other problem is either a one-sided or a two-sided subproblem depending on the position of . For example, in Figure 12(b), .

Note that sometimes can be extended only in one direction. For example, in Figure 12(c), we have , and is a vertical line bounded by the leaders, as shown in red. In this case we extend horizontally and we have choices for its right boundary. The leader that determines the right boundary (i.e, the one connecting to ) will partition the problem into two subproblems: one is a problem that includes , and the other problem is either a one-sided or a two-sided subproblem depending on the position of . For example, in Figure 12(c), .

#### A subproblem excludes c1.

We first show that these problems must be either one-sided or two-sided. Let be the subproblem that includes . Let be a subproblem that excludes and lies above the separating curve. Then the only available sides of for are and . Symmetrically, only and are available for . If (where ) is a one-sided problem, then we can process the problem in the same ways as described in Section 3.

Consider now the case of two-sided problems, and assume w.l.o.g. that is a two-sided problem. Note that contains the top-left corner of . Since we are searching for a partitioned solution (recall Lemma 2.1), there must be a -monotone axis-aligned separating curve connecting the bottom-right and the top-left corners of . Hence, there must exist a sequence of empty rectangles associated with it. Therefore, we can continue decomposing the problem in the same way as we did for the problems that include .

### 4.3 Time Complexity

We maintain the points and ports in an orthogonal range counting data structure (with -time preprocessing) such that given an axis-aligned rectangle, one can report the number of ports and points interior to the rectangle in time .

The encoding of the form allows us to use a dynamic programming table of size . Computing each entry requires examining candidates for an empty rectangle. Each candidate rectangle divides the problem into at most two new subproblems. If the new subproblems are not balanced, then the candidate rectangle would not give a feasible solution. Otherwise, the new subproblems are balanced. For the two-sided problems we perform table look-up, while the feasibility of the one-sided problems can be decided in time. Once we complete the dynamic programming, we get a set of ports mapped to sites and a set of one-sided problems that are feasible, for which the solution needs to be constructed. Since there can be such one-sided problems, and each can be solved in time (either by the algorithm of , or by a reduction to the rectangular one-sided case), the total time required is .

We can use the range counting data structure to check whether a subproblem is balanced in time . We can precompute the candidate rectangles for every grid point in time. Since each table look-up takes time, filling an entry of the dynamic programming table would take time for all the candidate rectangles corresponding to that entry. Hence, the overall running time of the algorithm is . The following theorem summarizes the main result of this section.

###### Theorem 4.1.

Given a 1-bend four-sided boundary labelling problem with sites and ports, one can find a feasible labelling (if exists) in time.

## 5 Conclusion

In this paper, we gave algorithms with running times and for the 1-bend three- and four-sided boundary labelling problems, improving the previous algorithms of Kindermann et al.  and Bose et al. . The main direction for future work is to improve the running time of our algorithms. Another direction is to study the fine-grained complexity of the problem; e.g., can we find a non-trivial lower bound on the running time? Even a quadratic lower bound is not known. Note that Bose et al.’s algorithm  minimizes the sum of leader lengths, but ours do not. It would also be interesting to seek faster algorithms that minimize the sum of leader lengths.

## References

•  Michael A. Bekos, Sabine Cornelsen, Martin Fink, Seok-Hee Hong, Michael Kaufmann, Martin Nöllenburg, Ignaz Rutter, and Antonios Symvonis. Many-to-one boundary labeling with backbones. J. Graph Algorithms Appl., 19(3):779–816, 2015.
•  Michael A. Bekos, Michael Kaufmann, Martin Nöllenburg, and Antonios Symvonis. Boundary labeling with octilinear leaders. Algorithmica, 57(3):436–461, 2010.
•  Michael A. Bekos, Michael Kaufmann, Antonios Symvonis, and Alexander Wolff. Boundary labeling: Models and efficient algorithms for rectangular maps. Comput. Geom., 36(3):215–236, 2007.
•  Marc Benkert, Herman J. Haverkort, Moritz Kroll, and Martin Nöllenburg. Algorithms for multi-criteria boundary labeling. J. Graph Algorithms Appl., 13(3):289–317, 2009.
•  Prosenjit Bose, Paz Carmi, J. Mark Keil, Saeed Mehrabi, and Debajyoti Mondal. Boundary labeling for rectangular diagrams. In 16th Scandinavian Symposium and Workshops on Algorithm Theory (SWAT 2018), June 18-20, 2018, Malmö, Sweden, pages 12:1–12:14, 2018.
•  Prosenjit Bose, Paz Carmi, J. Mark Keil, Saeed Mehrabi, and Debajyoti Mondal. Boundary labeling for rectangular diagrams. CoRR, abs/1803.10812, 2018.
•  Mark de Berg, Otfried Cheong, Marc van Kreveld, and Mark Overmars. Computational Geometry: Algorithms and Applications. Springer, Berlin Heidelberg, 2008.
•  Martin Fink and Subhash Suri. Boundary labeling with obstacles. In Proceedings of the 28th Canadian Conference on Computational Geometry (CCCG), pages 86–92, 2016.
•  Herbert Freeman and Sean Marrinan amd Hitesh Chitalia. Automated labeling of soil survey maps. In ASPRS-ACSM Annual Convention, Baltimore, volume 1, pages 51–59, 1996.
•  J. Mark Keil, Joseph S. B. Mitchell, Dinabandhu Pradhan, and Martin Vatshelle. An algorithm for the maximum weight independent set problem on outerstring graphs. Comput. Geom., 60:19–25, 2017.
•  Philipp Kindermann, Benjamin Niedermann, Ignaz Rutter, Marcus Schaefer, André Schulz, and Alexander Wolff. Multi-sided boundary labeling. Algorithmica, 76(1):225–258, 2016.
•  Chun-Cheng Lin. Crossing-free many-to-one boundary labeling with hyperleaders. In IEEE Pacific Visualization Symposium PacificVis 2010, Taipei, Taiwan, March 2-5, 2010, pages 185–192, 2010.
•  Chun-Cheng Lin, Hao-Jen Kao, and Hsu-Chun Yen. Many-to-one boundary labeling. J. Graph Algorithms Appl., 12(3):319–356, 2008.
•  Martin Nöllenburg, Valentin Polishchuk, and Mikko Sysikaski. Dynamic one-sided boundary labeling. In 18th ACM SIGSPATIAL International Symposium on Advances in Geographic Information Systems (GIS), pages 310–319, 2010.
•  Steven Zoraster. Practical results using simulated annealing for point feature label placement. Cartography and GIS, 24(4):228–238, 1997.