1 Introduction

A straight-line drawing \(\varGamma \) of a graph G is a mapping of each vertex to a distinct point on the plane and of each edge to a straight-line segment between the vertices. A path \(P=\{p_0,p_1,\ldots ,p_n\}\) is monotone if there exists a line l such that the projections of the vertices of P on l appear on l in the same order as on P. A straight-line drawing \(\varGamma \) of a graph G is monotone, if a monotone path connects every pair of vertices.

Monotone graph drawing has gained the recent attention of researchers and several interesting results have appeared. Given a planar fixed embedding of a planar graph G, a planar monotone drawing of G can be constructed, but at the cost of some bends on some edgesĀ [2]. In the variable embedding setting, we can construct a planar monotone drawing of any planar graph without any bendsĀ [8].

One way to find a monotone drawing of a graph is to simply find a monotone drawing of one of its spanning trees. For that reason, the problem of finding monotone drawings of trees has been the subject of several recent papers, starting from the work by Angelini et al.Ā [1] which introduced monotone graph drawings. Angelini et al.Ā [1] provided two algorithms that used ideas from number theory and more specifically Stern-Brocot treesĀ [3, 11],Ā [4, Sect.Ā 4.5]. The first algorithm used a grid of size \(O(n^{1.6}) \times O(n^{1.6})\) (BFS-based algorithm) while the second one used a grid of size \(O(n) \times O(n^2)\) (DFS-based algorithm). Later, Kindermann et al.Ā [9] provided an algorithm based on Farey sequence (seeĀ [4, Sect.Ā 4.5]) that used a grid of size \(O(n^{1.5}) \times O(n^{1.5})\). He and HeĀ [7] gave an algorithm based on Farey sequence and reduced the required grid size to \(O(n^{1.205}) \times O(n^{1.205})\), which was the first result that used less than \(O(n^3)\) area. Recently, He and HeĀ [5] firstly reduced the grid size for a monotone tree drawing to \(O(n \log (n)) \times O(n \log (n))\) and, in a sequel paper, to \(O(n) \times O(n)\)Ā [6]. Their monotone tree drawing uses a grid of size at most \(12n \times 12n\) which turns out to be asymptotically optimal as there exist trees which require at least \({n\over 12} \times {n \over 12}\) areaĀ [6].

Our Contribution: We provide a simple algorithm that given any n-vertex tree T, outputs a monotone drawing of T on a grid of size \(n \times n\). Example drawings of our algorithm appear at Figs.Ā 1, 2, 3, 4 and 5. Our algorithm does not employ number theory techniques but a rather simple weighting method and some simple facts from geometry that can be more analytically expressed. Due to space limitation, some proofs appear in the arXiv version of the paper [10].

Fig. 1.
figure 1

3-layer full binary tree (15 nodes).

Fig. 2.
figure 2

2-layer full ternary tree (13 nodes).

Fig. 3.
figure 3

Tree used in [5, 6].

Fig. 4.
figure 4

3-layer full binary tree plus path (29 nodes).

Fig. 5.
figure 5

2-layer full ternary tree plus path (25 nodes).

2 Definitions and Preliminaries

Let \(\varGamma \) be a drawing of a graph G and (u,Ā v) be an edge from vertex u to vertex v in G. The slope of edge (u,Ā v), denoted by slope(u,Ā v), is the angle spanned by a counter-clockwise rotation that brings a horizontal half-line starting at u and directed towards increasing x-coordinates to coincide with the half-line starting at u and passing through v. We consider slopes that are equivalent modulo \(2\pi \) as the same slope. Observe that \(slope(u,v)=slope(v,u) - \pi \).

Let T be a tree rooted at a node r. Denote by \(T_u\) the subtree of T rooted at a node u. By \(|T_u|\) we denote the number of vertices of \(T_u\). In the rest of the paper, we assume that all tree edges are directed away from the root.

In order to simplify the description of our algorithm, we extend the definition of slope-disjoint tree drawings given by Angelini et al.Ā [1]. More specifically, a tree drawing \(\varGamma \) of a rooted tree T is called a non-strictly slope-disjoint drawing if the following conditions hold:

  1. 1.

    For every node \(u \in T\), there exist two angles \(a_1(u)\) and \(a_2(u)\), with \(0 \varvec{\le } a_1(u)<a_2(u)\varvec{\le } \pi \) such that for every edge e that is either in \(T_u\) or enters u from its parent, it holds that \(a_1(u)<slope(e)<a_2(u)\).

  2. 2.

    For every two nodes \(u, v \in T\) such that v is a child of u, it holds that \(a_1(u) \varvec{\le } a_1(v) < a_2(v) \varvec{\le } a_2(u)\).

  3. 3.

    For every two nodes \(u_1, u_2\) with the same parent, it holds that either \(a_1(u_1)< a_2(u_1) \varvec{\le } a_1(u_2) < a_2(u_2)\) or \(a_1(u_2)< a_2(u_2) \varvec{\le } a_1(u_1) < a_2(u_1)\).

The idea behind the original definition of slope-disjoint tree drawings is that all edges in the subtree \(T_u\) as well as the edge entering u from its parent will have slopes that strictly fall within the angle range \(\left( a_1(u), a_2(u)\right) \) defined for vertex u. \(\left( a_1(u), a_2(u)\right) \) is called the angle range of u with \(a_1(u)\) and \(a_2(u)\) being its boundaries. In our extended definition, we allow for angle ranges of adjacent vertices (parent-child relationship) or sibling vertices (children of the same parent) to share angle range boundaries. Note that replacing the ā€œ\(\le \)ā€ symbols in our definition by the ā€œ<ā€ symbol gives us the original definition of Angelini et al.Ā [1] for the slope disjoint tree drawings.

Lemma 1

Every non-strictly slope-disjoint drawing of a tree T is also a slope-disjoint drawing.

Theorem 1

Ā [1] Every slope-disjoint drawing of a tree is monotone.

Theorem 2

Every non-strictly slope-disjoint drawing of a tree is monotone.

Based on geometry, we now prove that it is always possible to identify points on a grid that satisfy several properties with respect to their location.

Lemma 2

[See Fig.Ā 6]. Consider two angles \(\theta _1\), \(\theta _2\) with \(0 \le \theta _1 < \theta _2 \le \frac{\pi }{4}\), and let \(d=\lceil \frac{1}{\theta _2-\theta _1}\rceil \). Then, edge e connecting the origin (0,Ā 0) to point \(p=(d, \lfloor tan(\theta _1)d +1\rfloor )\) satisfies \(\theta _1< slope(e) < \theta _2\).

Fig. 6.
figure 6

Geometric representation of LemmaĀ 2.

Fig. 7.
figure 7

Point, slopes angular sectors used in LemmaĀ 3.

Lemma 3

[See Fig.Ā 7]. Consider angles \(\theta _1\), \(\theta _2\) with \(0 \le \theta _1 < \theta _2 \le \frac{\pi }{2}\) and let \(d=\lceil \frac{1}{\theta _2-\theta _1}\rceil \). Then, a grid point p such that the edge e that connects the origin (0,Ā 0) to p satisfies \(\theta _1< slope(e) < \theta _2\), can be identified as follows:

figure a

Moreover, if \(p=(x,y)\) is the identified point, it also holds that:

$$\begin{aligned} \max (x, y) {\left\{ \begin{array}{ll} \le \frac{\pi }{2}\frac{1}{\theta _2-\theta _1} &{} \text { if } \theta _2-\theta _1 > arctan(\frac{1}{2}) \\ < \frac{1}{\theta _2 - \theta _1} + 1 &{} \text { if } arctan(\frac{1}{2}) \ge \theta _2-\theta _1 \end{array}\right. } \end{aligned}$$

3 Monotone Tree Drawing on an \(n \times n\) Grid

Our tree drawing algorithm will produce a non-strictly slope-disjoint tree drawing which, by TheoremĀ 2, is monotone. We make the assumption that the given tree is rooted, otherwise, it can be rooted at any arbitrary node. In order to describe a non-strictly slope-disjoint tree drawing, we need to identify for each vertex u of the tree a grid point to draw u as well as to assign to it two angles \(a_1(u)\), \(a_2(u)\), with \(a_2(u) > a_1(u)\). For every tree vertex, the identified grid point and the two angles should be such that the three properties of the non-strictly slope-disjoint drawing are satisfied.

The basic idea behind our algorithm is to split in a balanced way the angle range \(\left( a_1(u), a_2(u)\right) \) of vertex u to its children based on the size of the subtrees rooted at them. The following lemma formalizes this idea.

Lemma 4

Let u be a node of the rooted tree T such that we already have assigned values for \(a_1(u)\) and \(a_2(u)\), with \(a_1(u) < a_2(u)\). Let \(u_1, u_2, \ldots , u_m,~m\ge 1\), be the children of u in T. Then, the following assignment of \(a_1\), \(a_2\) for the children of u satisfies Property-2 and Property-3 of the non-strictly slope disjoint drawing:

figure b

Observation 1

If a vertex u has only one child, say \(u_1\), then the angle assignment strategy of LemmaĀ 4 assigns \(a_1(u_1)=a_1(u)\) and \(a_2(u_1)=a_2(u)\), which means that the child ā€œinheritsā€ the angle-range of its parent.

AlgorithmĀ 1 describes our monotone tree drawing algorithm. It consists of three steps: Procedure AssignAngles which assigns angle-ranges to the vertices of the tree according to LemmaĀ 4, Procedure DrawVertices which assigns each tree vertex to a grid point according to LemmaĀ 3 and Procedure BalancedTreeMonotoneDraw which assigns the root to point (0,Ā 0) with angle-range \(\left( 0,\frac{\pi }{2} \right) \) and initiates the drawing of the tree.

figure c

Lemma 5

The drawing produced by AlgorithmĀ 1 is monotone.

Proof

The angle-range assignment satisfies Property-2 and Property-3 of the non-strictly slope disjoint drawing as proved in LemmaĀ 4. In addition, the assignment of the vertices to grid points satisfies Property-1 of the non-strictly slope disjoint drawing as proved in LemmaĀ 3. Thus, the produced drawing by AlgorithmĀ 1 is non-strictly slope disjoint and, by TheoremĀ 2, it is monotone. Ā Ā Ā \(\square \)

It remains to establish a bound on the grid size required by AlgorithmĀ 1. Our proof will use induction on the number of tree vertices having more than one child. The following lemma will be used as the basis of our induction.

Lemma 6

Let T be an n-vertex rooted tree in which all vertices have at most one child, i.e., T is a path rooted at one of its endpoints. Then, AlgorithmĀ 1 draws T in the diagonal of an \(n \times n\) grid.

Lemma 7

Let T be a rooted tree in which \(k>0\) of its vertices have at least two children. Let u be a vertex with at least two children and, moreover, every other vertex in \(T_u\) has at most one child. Let \(T^\prime \) be the tree derived by replacing (in T) the subtree \(T_u\) by a path of length \(|T_u|\). Then, the size of the grid which AlgorithmĀ 1 uses in the worst case for the drawing of T is smaller or equal to the size of the grid it uses in the worst case for the drawing of \(T^\prime \).

Proof

Let u be a vertex as the one stated in the lemma, i.e., in \(T_u\), u is the only vertex having at least two children. Let \(u_1, u_2, \ldots u_m, ~m \ge 2\), be the children of u, and let \(T_{u_i}\) be the subtree rooted at \(u_i\). Note that each \(T_{u_i}\) is a path. From ObservationĀ 1, we recall that for each node in \(T_{u_i}\), the assigned values for \(a_1\) and \(a_2\) by AlgorithmĀ 1 will be the same as \(a_1(u_i)\) and \(a_2(u_i)\). Let \(\phi (u) = a_2(u) - a_1(u)\). We consider two subcases based on whether \(arctan(\frac{1}{2}) \ge \phi (u)\) or not.

Ā 

Case-1: \(arctan(\frac{1}{2}) \ge \phi (u)\).:

Since AlgorithmĀ 1 performs its angle-range assignment based on LemmaĀ 4, for each child of u we have that \(\phi (u_i)=a_2(u_i) - a_1(u_i) = \frac{|T_{u_i}|}{|T_u|-1}\phi (u)\). Observe that it also holds that \(\phi (u_i) \le arctan(\frac{1}{2})\). A node in \(T_{u_i}\) is drawn, based on LemmaĀ 3 where \(\theta _1 \leftarrow a_1(u_i)\) and \(\theta _2 \leftarrow a_2(u_i)\), in a grid of length at most \(\frac{1}{\theta _2 (u_i) - \theta _1 (u_i)}+1\) if its parent is considered to be drawn at the origin. So, the length of the total grid that is used for the drawing of path \(T_{u_i}\) is at most: \(|T_{u_i}|(\frac{1}{\theta _2 (u_i) - \theta _1 (u_i)}+1)\) \(=|T_{u_i}| \frac{1}{\frac{|T_{u_i}|}{|T_u|-1}\phi (u)}+|T_{u_i}|\) \(=\frac{|T_u|-1}{\phi (u)} + |T_{u_i}|\) \(\le \frac{|T_u|-1}{\phi (u)} + |T_u|-1\) \(=(|T_u|-1)(\frac{1}{\phi (u)} + 1)\). The last term is the maximum grid length dictated by LemmaĀ 3 for the drawing of a path of size \(|T_{u}|\) with \(\theta _1 \leftarrow a_1(u)\) and \(\theta _2 \leftarrow a_2(u)\). Note also that in AlgorithmĀ 1 the largest grid devoted to any of \(T_{u_i}, 1\le i \le m\), determines the grid size of the drawing of \(T_u\) since the subtrees rooted at children of u are drawn completely inside non-overlapping (but possibly touching) angular sectors. The above statement holds because all the grids that will be used for the subtrees have the same origin (u) and all angular sectors lies in the first quadrant since AlgorithmĀ 1 assigns root with angle-range \(\left( 0, \frac{\pi }{2}\right) \). So, the grid size that is used in the worst case for the drawing of \(T_u\) by AlgorithmĀ 1 is smaller or equal to that used by it in the worst case for the drawing of a path of length \(|T_u|\). Thus, the size of the grid which AlgorithmĀ 1 uses in the worst case for the drawing of T is smaller or equal to the size of the grid it uses in the worst case for the drawing of \(T^\prime \).

Case-2: \(\phi (u) > arctan(\frac{1}{2})\).:

Let \(\phi (u_i)=a_2(u_i) - a_1(u_i), 1 \le i \le m\). We consider two subcases based on whether \(arctan(\frac{1}{2}) \ge \phi (u_i)\) or not. Ā 

Case-2a: \(arctan(\frac{1}{2}) \ge \phi (u_i)\).:

A node in \(T_{u_i}\) is drawn, based on LemmaĀ 3 where \(\theta _1 (u_1) \leftarrow a_1(u_i)\) and \(\theta _2 (u_i) \leftarrow a_2(u_i)\), in a grid of length at most \(\frac{1}{\phi (u_i)} + 1 < \frac{\pi }{2}\frac{1}{\phi (u_i)}\), assuming that its parent is drawn at the origin. The last inequality holds for \(\phi (u_i) \le \frac{\pi - 2}{2}\), and so it also holds for \(\phi (u_i) \le arctan(\frac{1}{2}) < \frac{\pi -2}{2}\). So, the maximum length of the total grid that is used for the drawing of path \(T_{u_i}\) is at most: \(|T_{u_i}|\frac{\pi }{2}\frac{1}{\phi (u_i)}= |T_{u_i}|\frac{\pi }{2} \frac{1}{\frac{|T_{u_i}|}{|T_u|-1}\phi (u)}= \frac{\pi }{2}\frac{|T_u|-1}{\phi (u)}\).

Case-2b: \(\phi (u_i) > arctan(\frac{1}{2})\).:

A node in \(T_{u_i}\) is drawn, based on LemmaĀ 3 where \(\theta _1 (u_i) \leftarrow a_1(u_i)\) and \(\theta _2 (u_i) \leftarrow a_2(u_i)\), in a grid of length at most \(\frac{\pi }{2}*\frac{1}{\phi (u_i)}\), assuming that its parent is drawn at the origin. So, the maximum length of the total grid that is used for the drawing of path \(T_{u_i}\) is: \(|T_{u_i}|\frac{\pi }{2}\frac{1}{\phi (u_i)}= |T_{u_i}|\frac{\pi }{2} \frac{1}{\frac{|T_{u_i}|}{|T_u|-1}\phi (u)}= \frac{\pi }{2}\frac{|T_u|-1}{\phi (u)}\).

Ā  The last term in both subcases is the maximum grid length dictated by LemmaĀ 3 for the drawing of a path of size \(|T_{u}|\) with \(\theta _1 \leftarrow a_1(u)\) and \(\theta _2 \leftarrow a_2(u)\) where \(\phi (u) > arctan(\frac{1}{2})\). So, the drawing of \(T_u\) uses in the worst case a grid length that is smaller or equal to that used in the worst case for the drawing of a path of length \(|T_u|\), when both drawings are done by AlgorithmĀ 1. Thus, AlgorithmĀ 1 uses in the worst case for the drawing of T a grid of size smaller or equal to the one used in the worst case for the drawing of \(T^\prime \).Ā Ā Ā \(\square \)

Ā 

Theorem 3

Given a rooted Tree T, AlgorithmĀ 1 produces a monotone grid drawing using a grid of size at most \(n \times n\).

Proof

The monotonicity of the drawing follows directly from LemmaĀ 5. By repeatedly applying LemmaĀ 7, we get that in the worst case the drawing of T uses a grid length that is smaller or equal to the one used in the worst case for the drawing of a path of length |T|, when both drawings are done by AlgorithmĀ 1. By LemmaĀ 6, we get that the used grid is of size at most \(n \times n\). Ā Ā Ā \(\square \)