1 Introduction

A finite convexity space is a pair \((V,\mathcal {C})\) consisting of a finite set V and a family \(\mathcal {C}\) of subsets of V such that \(\emptyset \in \mathcal {C}\), \(V\in \mathcal {C}\), and \(\mathcal {C}\) is closed under intersection. Members of \(\mathcal {C}\) are called convex sets.

Let \(\mathscr {P}\) be a collection of paths of a graph G, and let \(I_{\mathscr {P}}:2^{V(G)}\rightarrow 2^{V(G)}\) be a function (called interval function) such that

$$\begin{aligned} I_{\mathscr {P}}(S) = S\,\cup \,\{z\not \in S\mid \exists \ u,v\in S \ \text{ such } \text{ that } \ z \ \text{ lies } \text{ in } \text{ an } \ uv\text{-path } \ P\in \mathscr {P}\}. \end{aligned}$$

Distinct choices of \(\mathscr {P}\) lead to interval functions of quite different behavior. Such functions, in turn, are naturally associated with special convexity spaces (the so-called path convexities). For instance, if \(\mathscr {P}\) contains precisely all the shortest paths in a graph then the corresponding interval function is naturally associated with the well-known geodesic convexity ; if \(\mathscr {P}\) is the collection of induced paths then the corresponding interval function is associated with the monophonic convexity ; and there are many other examples in the literature.

In this work we propose a general path convexity framework, of which most path convexities in the literature can be viewed as particular cases. Some benefits of the proposed framework are the systematization of the algorithmic study of related problems and the possibility of defining new path convexities not yet investigated.

Our contributions are concentrated mainly in Sect. 3, where we describe in detail our framework. The idea is to control the length of the paths in \(\mathscr {P}\), as well as the types of chords allowed to exist in such paths. Such control can be done by means of four matrices that specify, for each pair (uv) of vertices, the minimum/maximum length and minimum/maximum chord length in all uv-paths of \(\mathscr {P}\). We prove hardness results for the more general approach, where the matrices are part of the input of the related computational problems. We also describe some polynomial cases by restricting the usage of such matrices, including linear-time methods for bounded treewidth graphs. In addition, we show how to define most existing path convexities in the literature within the proposed framework. In Sect. 4 we provide examples of new interesting convexities and discuss future algorithmic developments.

2 Preliminaries

In this section we first provide all the necessary background. Next, we briefly review the main path convexities in the literature and list six fundamental computational problems in graph convexity that will be considered in this work. Finally, we prove two useful propositions.

All graphs are finite, simple, nonempty, and connected. Let G denote a graph with n vertices and m edges. The length of a path P in G, denoted by |P|, is its number of edges. A path P in G with endpoints u and v is an uv-path. An uv-path P in G is shortest if there is no uv-path \(P'\) in G such that \(|P'|<|P|\). If an uv-path P is shortest then |P| is the distance between u and v in G, and we write \(|P|={ d ist}_G(u,v)\). A chord of length \(l\ge 2\) in a path \(P=(v_0,v_1,\ldots ,v_{|P|})\) is an edge \(v_iv_j\in E(G)\) such that \(i,j\in \{0,\ldots ,|P|\}\) and \(|i-j|=l\ge 2\).

Let \(\mathscr {P}\) be a collection of paths of a graph G, and let \(I_{\mathscr {P}}:2^{V(G)}\rightarrow 2^{V(G)}\) be the interval function associated with \(\mathscr {P}\), i.e.,

$$\begin{aligned} I_{\mathscr {P}}(S) = S\,\cup \,\{z\not \in S\mid \exists \ u,v\in S \ \text{ such } \text{ that } \ z \ \text{ lies } \text{ in } \text{ an } \ uv\text{-path } \ P\in \mathscr {P}\}. \end{aligned}$$
(1)

Define \(\mathcal {C}_{\mathscr {P}}\) as the family of subsets of V(G) such that \(S\in \mathcal {C}_{\mathscr {P}}\) if and only if \(I_{\mathscr {P}}(S)=S\). Then it is easy to see that \((V(G),\mathcal {C}_{\mathscr {P}})\) is a finite convexity space, whose convex sets are precisely the fixed points of \(I_{\mathscr {P}}\).

Proposition 1

(van de Vel 1993) \((V(G),\mathcal {C}_{\mathscr {P}})\) is a finite convexity space.

In order to ease the notation, we omit the subscript \({\mathscr {P}}\) whenever it is clear from the context.

2.1 Path convexities in the literature

By varying the choice of the collection \(\mathscr {P}\), interval functions of different behavior can be defined using Eq. (1). The convexity spaces associated with such functions are called path convexities.

In Table 1 we list the main path convexities that appear in the literature. In the table, each convexity is defined by the collection of paths \(\mathscr {P}\) considered.

Table 1 Some path convexities studied in the literature

It is important to note that although most of the graph convexities so far studied are based on paths. There are graph convexities that are not based on paths such as the And/or-convexity, a graph convexity based on processes, and deadlock models, see Lima et al. (2018). Our focus in this work is only on path convexities.

2.2 Computational problems

In this work we focus on six computational problems that are usually studied in the field of convexity in graphs. The list, of course, is not complete and other important problems could also be considered.

We need some additional definitions. Let \(S\subseteq V(G)\). If \(I(S) = V(G)\) then S is an interval set. The convex hull H(S) of S is the smallest convex set containing S. Write \(I^0(S)=S\) and define \(I^{i+1}(S)=I(I^i(S))\) for \(i\ge 0\). Note that \(I(S)=I^1(S)\) and there exists an index i for which \(H(S)=I^i(S)\). If \(H(S) = V(G)\) then S is a hull set. The convexity number c(G) of G is the size of a maximum convex set \(S\ne V(G)\). The interval number i(G) of G is the size of a smallest interval set of G. The hull number h(G) of G is the size of a smallest hull set of G. Now we are in position to state the six problems dealt with in this work:

Convex Set - CS

Input: A graph G and a set \(S\subseteq V(G)\).

Question: Is S convex?

Interval Determination - ID

Input: A graph G, a set \(S\subseteq V(G)\), and a vertex \(z\in V(G)\).

Question: Does z belong to I(S)?

Convex Hull Determination - CHD

Input: A graph G, a set \(S\subseteq V(G)\), and a vertex \(z\in V(G)\).

Question: Does z belong to H(S)?

Convexity Number - CN

Input: A graph G and a positive integer r.

Question: Is \(c(G)\ge r\)?

Interval Number - IN

Input: A graph G and a positive integer r.

Question: Is \(i(G)\le r\)?

Hull Number - HN

Input: A graph G and a positive integer r.

Question: Is \(h(G)\le r\)?

2.3 Existing complexity results

The table below shows the complexity of the six problems listed in the preceding subsection for some convexity spaces. All the entries of the table correspond to results found in the literature, or to trivial results (indicated by ‘[t]’).

Table 2 Problems versus convexities: complexity results

2.4 Two useful facts

The next two propositions are useful, which say that if Interval Determination or Convex Set can be solved in polynomial time for some convexity space then some other problems listed in Sect. 2.2 can also be solved in polynomial time, for the same convexity space.

Proposition 2

Let \((V(G),\mathcal {C})\) be any convexity space. If Interval Determination can be solved in polynomial time for \((V(G),\mathcal {C})\) then Convex Set and Convex Hull Determination can also be solved respectively, in polynomial time for \((V(G),\mathcal {C})\).

Proof

Let \(S\subseteq V(G)\). Since Interval Determination is in \(\mathrm {P}\) for \((V(G),\mathcal {C})\), I(S) can be computed in polynomial time. Let i be the smallest index such \(I^{i+1}(S) = I^{i}(S)\). Note that determining such an index i as well as \(I^{i}(S)\) can also be done in polynomial time, since \(i=O(n)\). Therefore:

  • If \(I(S) = S\) then S is a convex set, otherwise S is not convex.

  • If \(z\in I^i(S)\) then \(z\in H(S)\), otherwise \(z\not \in H(S)\).

By the above observations, the problems Convex Set and Convex Hull Determination can be solved in polynomial time for \((V(G),\mathcal {C})\). \(\square \)

Let \(S\subseteq V(G)\). If S is not convex then an augmenting set of S is any set \(S'\) such that \(S\subset S'\subseteq H(S)\) (where the symbol \(\subset \) stands for proper inclusion).

Proposition 3

Let \((V(G),\mathcal {C})\) be a convexity space. If there is a polynomial-time certification algorithm to solve Convex Set for \((V(G),\mathcal {C})\) that outputs an augmenting set when the problem has a negative answer then Convex Hull Determination can also be solved in polynomial time for \((V(G),\mathcal {C})\).

Proof

Let \(S\subseteq V(G)\) and \(z\in V(G)\). Since Convex Set can be solved in polynomial time for \((V(G),\mathcal {C})\), we can apply a convexity test to S in polynomial time. If the test succeeds then S is a convex set and, consequently, the convex hull of S is S itself; otherwise, the test fails and there exists a set \(S_1\) (a certificate outputted by the test) that can be used to augment the original set S. Recall that S is properly contained in \(S_1\).

In order to establish the convex hull of S, we are going to apply the convexity test algorithm successively, always obtaining a set \(S_{i+1}\) that augments \(S_i\), until it cannot be augmented anymore. Let j be the smallest index such that \(S_j\) results in a convex set. Observe that \(j\le |V(G)\setminus S|\), since at least one vertex is added in each iteration. Moreover, each convexity test can be done in polynomial time. Thus, the entire process still remains polynomial.

If a vertex \(z\in V(G)\) is such that \(z\in S_j\) then \(z\in H(S)\). Therefore, Convex Hull Determination is in \(\mathrm {P}\) for \((V(G),\mathcal {C})\). \(\square \)

Note that Propositions 2 and 3 can be used to fill some entries of Table 2. For example, since Interval Determination is in \(\mathrm {P}\) for the geodesic convexity, by Proposition 2 the problems Convex Set and Convex Hull Determination are also in \(\mathrm {P}\) for such convexity. The same applies to the \(P_3\)- and \(P^*_3\)- convexities. On the other hand, Proposition 3 implies that Convex Hull Determination is in \(\mathrm {P}\) for the monophonic convexity.

3 A general framework for path convexities

In this section, we propose a general framework for the study of path convexities.

From now on, we assume that every n-vertex graph G has vertices labeled \(1,2,\ldots ,n\). A length matrix is a symmetric \(n\times n\) matrix M such that each entry M(ij), for \(i,j\in V(G)\), is a natural number; in addition, all diagonal entries of M are zero.

Let ABCD be four \(n \times n\) length matrices. Suppose that \(\mathscr {P}\) is the family of paths of G such that an ij-path P of G is a member of \(\mathscr {P}\) if and only if:

  1. (1)

    \(|P|\ge A(i,j)\);

  2. (2)

    \(|P|\le B(i,j)\);

  3. (3)

    all the chords in P are of length at least C(ij);

  4. (4)

    all the chords in P are of length at most D(ij).

Let \(I_{\mathscr {P}}:2^{V(G)}\rightarrow 2^{V(G)}\) be the interval function associated with \(\mathscr {P}\), and let \(\mathcal {C}_{\mathscr {P}}\) be the family of subsets of V(G) such that \(S\in \mathcal {C}_{\mathscr {P}}\) if and only if \(I_{\mathscr {P}}(S)=S\). Since \(\mathscr {P}\) is a particular collection of paths of G, by Proposition 1, we have that \((V(G),\mathcal {C}_{\mathscr {P}})\) is a finite convexity space, equipped with interval function \(I_{\mathscr {P}}\). Let us say that such a convexity space defines a matrix path convexity.

Again, we omit the subscript \(\mathscr {P}\) when it is clear from the context.

Say that an ij-path P satisfies matrices ABCD if all the conditions (1) to (4) above are satisfied by P.

3.1 Putting the matrices as part of the input

In the six problems listed in Sect. 2.2, the graph G is always part of the input; however, the rule that determines which collection of paths of G must be considered is not part of the input. More general versions of such problems are possible when the desired convexity space, expressed as a graph G together with a set of four length matrices, is part of the input. For example, consider the following version of Convex Set:

Matrix Convex Set

Input: A graph G, four \(n\times n\) length matrices ABCD, and \(S\subseteq V(G)\).

Question: Is S convex under the matrix path convexity ruled by ABCD?

All the remaining problems listed in Sect. 2.2 can be restated analogously.

The next theorems say that such “matrix problems” are all hard. However, we shall see that restrictions on the matrices ABCD lead to interesting cases. In this regard, some types of length matrices are of special interest. For a graph G, the distance matrix of G is the length matrix \(M_{ d ist}\) with entries \(M_{ d ist}(i,j)={ d ist}_G(i,j)\), for \(i,j\in V(G)\). For a positive integer constant k, the \((n-k)\)-matrix and the k-matrix are the length matrices \(M_{n-k}\) and \(M_k\) with off-diagonal entries all equal to, respectively, \(n-k\) and k.

Theorem 1

Matrix Convex Set is Co-NP-complete.

Proof

A certificate for a negative answer to Matrix Convex Set is a triple ijz (with \(i,j\in S\) and \(z\not \in S\)) and an ij-path P in G containing z such that P satisfies A to D. Such a certificate can be clearly checked in polynomial time. Therefore, Matrix Convex Set is in \(\mathrm {CoNP}\).

To prove that Matrix Convex Set is Co-NP-complete, we show a reduction from the following NP-complete problem (Haas and Hoffmann 2006): given three distinct vertices ijz in a graph H, decide whether there is a chordless ij-path passing through z.

Let G be the graph obtained from H by replacing each edge (sz) incident to z by an sz-path containing \(n-1\) internal vertices of degree two, where \(n=|V(H)|\). In other words, G is a subdivision of H obtained by subdividing each edge incident to z using \(n-1\) vertices. Set A and B as the length matrices with off-diagonal entries all equal to, respectively, 2n and \(3n-3\). Also, set \(C=D=M_1\) (the k-matrix for \(k=1\)). Finally, set \(S=\{i,j\}\). Note that the collection of paths \(\mathscr {P}\) defined by ABCD contains the chordless paths with length at least 2n and at most \(3n-3\).

Suppose that there is a chordless ij-path \(P_H\) in H passing through z. Write \(P_H=(s_0=i,s_1,\ldots ,s_{h-1},s_h=z,s_{h+1},\ldots ,s_l=j)\). Then there is a chordless ij-path \(P_G\) in G obtained from \(P_H\) by subdividing edges \((s_{h-1},z)\) and \((z,s_{h+1})\) using \(n-1\) vertices of degree two for each edge. Note that \(|P_G|=(l-2)+2n\). Since \(2\le l\le n-1\), we have \(2n\le |P_G|\le 3n-3\). Therefore, \(P_G\) satisfies ABCD, and its existence implies that S is not convex.

Conversely, suppose that S is not convex. Then there is a chordless ij-path \(P_G\) of length at least 2n passing through some vertex of G lying outside S. But, by the construction of G, all the ij-paths of length at least 2n must necessarily pass through z. Let \(P_{hz}\) be the subpath of \(P_G\) with length n that starts at a vertex h and ends at z. Similarly, let \(P_{zh'}\) be the subpath of \(P_G\) with length n that starts at z and ends at a vertex \(h'\). By replacing \(P_{hz}\) and \(P_{zh'}\) by edges (hz) and \((z,h')\), we obtain a chordless ij-path in H passing through z. This completes the proof. \(\square \)

Theorem 2

Matrix Interval Determination is NP-complete.

Proof

A certificate for a positive answer to Matrix Interval Determination is a pair ij (with \(i,j\in S\)) and an ij-path P in G containing z (recall that z is part of the input) such that P satisfies ABCD. Moreover, this certificate can be checked in polynomial time. Therefore, Matrix Interval Determination is in \(\mathrm {NP}\).

To prove that Matrix Interval Determination is NP-complete, recall from Table 2 that Interval Determination is NP-complete for the monophonic convexity. If \(A=M_2\), \(B=M_{n-1}\), and \(C=D=M_1\), the collection of paths \(\mathscr {P}\) associated with such matrices is precisely the collection of induced paths of G. Then Interval Determination for the monophonic convexity is a restriction of Matrix Interval Determination, i.e., the former problem is NP-complete. \(\square \)

Theorem 3

Matrix Convex Hull Determination is NP-complete.

Proof

A certificate for a positive answer to Matrix Convex Hull Determination is formed by a sequence of paths \(P_1,P_2,\ldots ,P_r\) such that \(r\le n-1\), \(z\in V(P_r)\), and each \(P_k\) is an \(i_kj_k\)-path satisfying matrices ABCD with \(i_k,j_k \in S\cup V(P_1)\cup \cdots \cup V(P_{k-1})\). It is easy to see that such a certificate can be checked in polynomial time. Therefore, Matrix Convex Hull Determination is in \(\mathrm {NP}\).

For the hardness proof, we use the same reduction described in Theorem 1. Again, if there is a chordless ij-path \(P_H=(i,\ldots ,h,z,h',\ldots ,j)\) in H then there is a chordless ij-path \(P_G\) in G obtained from \(P_H\) by subdividing edges (hz) and \((z,h')\), as explained in the proof of Theorem 1, such that \(P_G\) satisfies ABCD. Therefore, \(z\in I(S)\subseteq H(S)\).

Conversely, suppose that \(z\in H(S)\). Then there is a sequence of paths \(P_1\), \(P_2\), \(\ldots \), \(P_r\) such that \(z\in V(P_r)\) and, for \(1\le k\le r\), \(P_k\) is an \(i_kj_k\)-path satisfying matrices ABCD, where \(i_k,j_k \in S\cup V(P_1)\cup \cdots \cup V(P_{k-1})\).

Note that \(i_1,j_1\in S\). Thus, \(\{i_1,j_1\}=\{i,j\}\). In addition, \(|P_1|\ge 2n\). But, by the construction of G, all the ij-paths of length at least 2n must necessarily pass through z. Hence, \(z\in V(P_1)\). The rest of the proof follows as in the proof of Theorem 1: let \(P_{hz}\) (resp., \(P_{z h'}\)) be the subpath of \(P_1\) with length n starting at some h (resp., at z) and ending at z (resp., at some \(h'\)). Replacing \(P_{hz}\) and \(P_{zh'}\) by edges (hz) and \((z,h')\) produces a chordless ij-path in H passing through z. \(\square \)

Theorem 4

1. Matrix Convexity Number is NP-hard.

2. Matrix Interval Number is NP-complete.

3. Matrix Hull Number is NP-complete.

Proof

We first prove that both Matrix Interval Number and Matrix Hull Number are in \(\mathrm {NP}\).

A certificate for a positive answer to Matrix Interval Number consists of a set \(S\subseteq V(G)\) of size at most r, and a collection of paths \(\{P_z\mid z\in V(G)\setminus S\}\) such that for each path \(P_z\) there exist \(i_z,j_z\in S\) for which \(P_z\) is an \(i_zj_z\)-path containing z and satisfying ABCD. Since the number of paths in the collection is O(n), Matrix Interval Number is in \(\mathrm {NP}\).

A certificate for a positive answer to Matrix Hull Number consists of a set S of size at most r and a sequence of paths \(P_1,P_2,\ldots ,P_s\) such that:

  1. (a)

    \(s\le n-1\);

  2. (b)

    \(V(G)\setminus S\subseteq V(P_1)\cup \cdots \cup V(P_s)\);

  3. (c)

    for \(1\le k\le s\), \(P_k\) is an \(i_kj_k\)-path satisfying matrices ABCD,

with \(i_k,j_k \in S\cup V(P_1)\cup \cdots \cup V(P_{k-1})\).

Since such a certificate can be checked in polynomial time, Matrix Hull Number is in \(\mathrm {NP}\).

Now we describe the hardness proof for the three problems. As in Theorem 2, we use a proof by restriction. Recall from Table 2 that Convexity Number, Interval Number, and Hull Number are all NP-complete for the geodesic convexity. If \(A=B=M_{ d ist}\) and \(C=D=M_1\), the collection of paths \(\mathscr {P}\) associated with such matrices is precisely the collection of shortest paths of G. This means that Convexity Number, Interval Number, and Hull Number for the geodesic convexity are, respectively, restrictions of Matrix Convexity Number, Matrix Interval Number, and Matrix Hull Number. Hence, the theorem follows. \(\square \)

3.2 Constant matrices: the (abcd)-path convexity

In this section, we study the case in which there are constants abcd such that \(A=M_a\), \(B=M_b\), \(C=M_c\), and \(D=M_d\). In this scenario we can assume that the matrices are not part of the input, because length restrictions are known in advance. This gives rise to “constant matrix versions” of the problems studied in the preceding subsection. For example, consider the following problems:

(abcd)-Convex Set

Input: A graph G and a set \(S\subseteq V(G)\).

Question: Is S convex under the matrix path convexity ruled by ABCD?

Equivalently: Is S convex under the path convexity defined by the collection \(\mathscr {P}(a,b,c,d)\) of paths of G whose length is at least a and at most b, and whose chords have length at least c and at most d?

(abcd)-Interval Determination

Input: A graph G, a set \(S\subseteq V(G)\), and a vertex \(z\in V(G)\).

Question: Does z belong to I(S), where I is the interval function associated with the collection \(\mathscr {P}(a,b,c,d)\) of paths of G?

The remaining matrix problems can be restated analogously.

The path convexity for which the path/chord length restrictions are ruled by four constants abcd as explained above is called (abcd)-path convexity.

Theorem 5

(abcd)-Interval Determination is in \(\mathrm {P}\).

Proof

Note that for a constant \(\ell \) there are \(O(n^{\ell +1})\) paths of length \(\ell \) in G. Thus there are \(O(\sum _{\ell =a}^{b} n^{\ell +1})\) paths in G with length at least a and at most b. Now, for each pair (ij) of distinct vertices in S, there are \(O(\sum _{\ell =a}^{b} n^{\ell -1})\) ij-paths with length at least a and at most b, because i and j are the fixed endpoints of each such path. But S contains \(O(|S|^2)\) pairs of distinct vertices. This amounts to checking \(O(|S|^2 \sum _{\ell =a}^{b} n^{\ell -1})\) paths. Since a path of length \(\ell \) can have at most \(O(\ell ^2)\) chords, we can select all the ij-paths in \(\mathscr {P}(a,b,c,d)\) with \(i,j\in S\) in \(O(|S|^2 \sum _{\ell =a}^{b} \ell ^2 n^{\ell -1})\) time. Finally, checking whether z belongs to one of such paths can be done in O(1) time per path, because the lenght of each path is bounded by b. This gives a naïve polynomial-time brute-force algorithm to check whether \(z\in I(S)\). \(\square \)

By Proposition 2, we have:

Corollary 1

(abcd)-Convex Set and (abcd)-Convex Hull Determination are in \(\mathrm {P}\). \(\square \)

As for the other three problems, (abcd)-Convexity/Interval/Hull Number, we remark that the special cases

$$\begin{aligned} (a=2,b=2,c=1,d=2) \text{ and } (a=2,b=2,c=1,d=1) \end{aligned}$$

correspond precisely to the \(P_3\)- and \(P^*_3\)- convexities, as indicated in Table 1. For both convexities, all the three problems are NP-complete (see Table 2).

3.3 (abcd)-path convexity and bounded treewidth graphs

In this section, we investigate the complexity of the six (abcd)-path convexity problems in Sect. 3.2 when applied to bounded treewidth graphs. As we shall see, linear-time methods will be possible in this case.

Let G be a graph, T a tree, and \(V=(V_t)_{t \in T}\) a family of vertex sets \(V_t\subseteq V(G)\) indexed by the vertices t of T. The pair (TV) is called a tree-decomposition of G if it satisfies the following three conditions (Diestel 2005):

[(T1)] \(V(G)=\bigcup _{t\in T} V_t\);

[(T2)] for every \(e\in E(G)\) there exists \(t\in T\) such that both ends of e lie in \(V_t\);

[(T3)] if \(V_{t_i}\) and \(V_{t_j}\) both contain a vertex v then \(v\in V_{t_k}\) for all vertices \(t_k\) in the path between \(t_i\) and \(t_j\).

The width of (TV) is the number \(\max \{|V_t|-1 \mid t\in T\}\), and the treewidth tw(G) of G is the minimum width of any tree-decomposition of G.

Graphs of treewidth at most k are called partial k-trees. Some graph classes with bounded treewidth include: forests (treewidth 1); pseudoforests, cacti, series-parallel graphs, and outerplanar graphs (treewidth at most 2); Halin graphs and Apollonian networks (treewidth at most 3) (Bodlaender 1998; Brandstädt et al. 1999). Control flow graphs arising in the compilation of structured programs also have bounded treewidth (at most 6) (Thorup 1998).

In 1990, Courcelle (1990) stated that for any graph G with treewidth bounded by a constant k and for any graph property \(\varPi \) that can be formulated in \(\hbox {CMSOL}_2\) (Counting Monadic Second-Order Logic where quantification over sets of vertices or edges and predicates testing the size of sets modulo constants are allowed), there is a linear-time algorithm that decides if G satisfies \(\varPi \) (Courcelle 1990, 1997; Courcelle and Mosbah 1993; Courcelle and Engelfriet 2011). This result has been extended a number of times (Arnborg et al. 1991; Borie et al. 1992; Courcelle et al. 2000; Hliněnỳ et al. 2008). In particular, Arnborg et al. (1991) study optimization problems over sets definable in Counting Monadic Second-Order Logic.

By Courcelle’s meta-theorems based on \(\hbox {CMSOL}_2\) (Courcelle 1990, 1997; Courcelle and Mosbah 1993), obtaining linear-time methods to solve the six problems of Sect. 3.2 on bounded treewidth graphs amounts to showing that the related properties are expressible in \(\hbox {CMSOL}_2\).

Theorem 6

(abcd)-Interval Determination is solvable in linear time on bounded treewidth graphs.

Proof

It is enough to show that the property “\(z\in I(S)\)” is \(\hbox {CMSOL}_2\)-expressible. Given G, S, and z, we construct \(\varphi (G,S,z,a,b,c,d)\) such that \(z \in I(S) \Leftrightarrow \varphi (G,S,z,a,b,c,d)\) as follows:

$$\begin{aligned} (~z \in S~)~{\vee }&(~\exists ~ u,v,P \nonumber \\&(~u,v \in S~{\wedge \nonumber }\\&~~P \text{ is } \text{ an } uv\text{-path } ~{\wedge } ~~z \text{ is } \text{ in } P~{\wedge } \nonumber \\&~~Card(P) \ge a~{\wedge } ~~Card(P) \le b~{\wedge } \nonumber \\&~~\forall P' ( \ (~P'\subseteq P~\wedge \ Card(P')\ge 2~\wedge \nonumber \\&{~~~~~~~~~~}\exists ~ u',v' (P' \hbox { is an }u'v'\hbox {-path}~\wedge ~adj(u',v')))\nonumber \\&{~~~~~~~~}~\Rightarrow (Card(P')\ge c \ \ {\wedge } \ \ Card(P')\le d) \ ) \ )) \end{aligned}$$
(2)

In the above formula, paths are regarded as subsets of edges. Using this approach, the subformula“P is an uv-path” can be expressed in \(\hbox {CMSOL}_2\) (see Courcelle 1997). Note that a chord is expressed as an \(u'v'\)-subpath \(P'\) of P with length at least c and at most d such that \(u'\) is adjacent to \(v'\). \(\square \)

Corollary 2

  (abcd)-Convex Set can be solved in linear time on bounded treewidth graphs.

Proof

The property “S is convex” is equivalent to “there is no z such that \(z\not \in S\) and \(z\in I(S)\)”. By Theorem 6, “\(z\in I(S)\)” is \(\hbox {CMSOL}_2\)-expressible. Thus the result easily follows. \(\square \)

Corollary 3

(abcd)-Convex Hull Determination can be solved in linear time on bounded treewidth graphs.

Proof

The property “\(z\in H(S)\)” is equivalent to “there exists \(S_1\) such that: (a) \(S_1\) is convex, (b) \(S\subseteq S_1\), (c) \(z\in S_1\), and (d) there is no \(S_2\) such that \(S_2\) is convex, \(S\subseteq S_2\), and \(S_2\) is properly contained in \(S_1\)”. By Corollary 2, we can use \(\hbox {CMSOL}_2\) to say that the sets \(S_1\) and \(S_2\) are convex. Thus the result follows. \(\square \)

For the remaining three problems ((abcd)-Convexity/Interval/Hull Number), we consider their optimization versions (maximization in the case of Convexity Number, and minimization in the case of Interval/Hull Number). Note that the properties “S is a convex set distinct from V(G)”, “S is an interval set”, and “S is a hull set” can be expressed in \(\hbox {CMSOL}_2\). Therefore the optimization versions (“find an optimal set satisfying the required property”) are \(\hbox {LinCMSOL}_2\) problems (Arnborg et al. 1991; Courcelle 1992), to which the following result applies:

Theorem 7

(Arnborg et al. 1991; Courcelle 1992) Let k be a positive constant, and \(\varPi \) be a LinCMSOL\(_2\) problem. Then \(\varPi \) can be solved in linear time on graphs of treewidth bounded by k (if the tree-decomposition is given with the input graph).

Therefore:

Corollary 4

The optimization versions of (abcd)-Convexity Number, (abcd)-Interval Number, and (abcd)-Hull Number can be solved in linear time on bounded treewidth graphs (if the tree-decomposition is given with the input graph).

3.4 Particular cases of the (abcd)-path convexity

In this section we show that, by extending the meaning of the parameters abcd, some path convexities in the literature can be viewed as particular cases of the (abcd)-path convexity. In Table 3 below, the symbol ‘\(\sigma \)’ (resp.,‘\(\ell \)’) means that the length of the shortest (resp., longest) path between each pair of distinct vertices must be considered. The symbol ‘\(\infty \)’ stands for no length restriction. For a constant k, the symbol ‘\(k\mid \sigma \)’ means that, for each pair (ij) of distinct vertices, the minimum value between k and the length of the shortest ij-path must be considered.

Table 3 Path convexities as particular cases of the (abcd)-path convexity

4 Concluding remarks

In this work we described a matrix path convexity framework, where, by means of four input matrices, we can specify the types of paths that must be considered for each pair of vertices of the input graph, “customizing” the path convexity to be dealt with. Since this general approach results in the hardness of the related computational problems (at least the more studied ones), we also investigate the case of constant matrices. The latter case leads to the study of the (abcd)-path convexity, where the rule that defines the convexity is not part of the input. If a, b, c, and d are positive constants then, in such convexity, the problems of computing the interval of a set, deciding whether a set is convex, and computing the convex hull of a set, are all solvable in polynomial time. In addition, all the “(abcd)-versions” of the six problems listed in Sect. 2.2 are solvable in linear time if the input graph has bounded treewidth. We have also shown that, by extending the meaning of the parameters abcd, most path convexities considered in the literature can be viewed as particular cases of the (abcd)-path convexity. In this regard, other interesting convexities, not yet considered in the literature up to the authors’ knowledge, can be defined by choosing other values for the tuple (abcd). Tables 4 and 5 describe such convexities. The symbol ‘\(\hbox {n}^-\;\)’ means that paths with length one less than the number of vertices of the input graph must be considered.

Table 4 Some new convexities proposed in this work
Table 5 Convexities from Table 4 described according the (abcd)-path convexity framework

Let \(\mathbb {K}=\{k \mid \sigma \}_{k\in \mathbb {N}^*}\) and \(\varSigma =\mathbb {N}^*\cup \{\sigma ,\infty ,\ell ,\mathrm {n}^-\}\cup \mathbb {K}\), and consider the domain of tuples \((a,b,c,d)\in \varSigma ^4\) (considering, of course, only meaningful cases). Such domain can be used to systematize algorithmic studies in path convexity in some ways. One example is to find complexity dichotomies (complete classifications of the complexity of a fixed computational problem \(\varPi \)). For example, if \(\varPi =\) Interval Determination, \(c=1\), and \(d\in \{1,2\}\), which values of (abcd) imply tractability (hardness) of \(\varPi \) under the (abcd)-path convexity? From Tables 2 and 3 we know that the cases \((\sigma ,\sigma ,1,1)\), (2, 2, 1, 1), and (2, 2, 1, 2) are in P, while \((2,\infty ,1,1)\) and \((2,\infty ,1,2)\) are NP-complete.