1 Introduction

Undirected graphs with edges labelled positively (by a + ) and negatively (by a −), called signed graphs, in many applications serve as a very simple model of relationships between a group of people, e.g., in a social network. Sign labels can express in a simplified way mutual relations, like staying in a relationship, family bonds or conflicts, by classifying them either as friendship (+ edge), hostility (− edge) or ambivalence (no edge). In particular, much effort has been put into properly understanding and representing the structure of the network, balancing it or naturally partitioning into clusters [1, 3, 6, 1518, 21]. One of the problems is to visualize the model graph properly, i.e., in such a way that positive relations tend to make vertices be placed close to each other, while negative relations imply large distances between vertices.

In their recent work, Kermarrec and Thraves [14] formalized this problem as follows: Consider the metric space \({{\mathbb {R}}}^{l}\) with the Euclidean metric denoted by d. Given a signed graph G, is it possible to embed the vertices of G in \({{\mathbb {R}}}^{l}\) so that for any positive edge uu 1 and negative edge uu 2 it holds that d(u, u 1) < d(u, u 2)? This question has a natural interpretation: we would like to place a group of people so that every person is placed closer to his friends than to his enemies.

The work of Kermarrec and Thraves [14] concentrated on showing a number of examples and counterexamples for embeddability into spaces of small dimensions (1 and 2) and a deeper study of the 1-dimensional case. Interestingly enough, the case of the Euclidean line has an equivalent formulation in the language of pure combinatorics: Given a signed graph G, is it possible to order the vertices of G so that for any positive edge uw there is no negative edge uv with v laying between u and w? The authors made algorithmic use of this combinatorial insight: Providing the given signed graph is complete (i.e., every pair of vertices is adjacent via a positive or negative edge) they show a polynomial-time algorithm that computes an embedding into a line or reports that no such embedding exists.

Kermarrec and Thraves also posed a number of open problems in the area, including the question of the complexity of determining the embeddability of an arbitrary (not necessarily complete) graph into the Euclidean line.

Our Results

We focus on the problem of embedding a signed graph into a line. The reformulation of the 1-dimensional case of Kermarrec and Thraves turns out to be an interesting combinatorial problem, which allows classical methods of analysis and shows interesting links with the class of proper interval graphs.

We begin with refining the result of Kermarrec and Thraves for the case of complete graphs. We prove that a complete signed graph is embeddable into a line if and only if the graph formed by the positive edges is a proper interval graph. Using this theorem one can immediately transfer all the results from the well-studied area of proper interval graphs into our setting. Most importantly, as recognition of proper interval graphs can be performed in linear-time [4], we obtain a simpler algorithm for determining the embeddability of a complete graph into a line, with a linear runtime.

We next analyse the general case. We resolve the open problem posed in [14] negatively: it is NP-complete to resolve whether a given signed graph can be embedded into a line. This hardness result also answers other questions of Kermarrec and Thraves [14]. For example, we infer that it is NP-hard to decide the smallest dimension of a Euclidean space in which the graph can be embedded, as such an algorithm could be used to test embeddability into a line.

Furthermore, we are able to show a lower bound on the time complexity of resolving embeddability into a line, under a plausible complexity assumption. We prove that obtaining an algorithm running in subexponential time (in terms of the total number of vertices and edges of the input graph) would contradict the Exponential Time Hypothesis [11] (see Section 2 for an exact statement). We complete the picture of the complexity of the problem by showing a dynamic programming algorithm that runs in O (2n) time, Footnote 1 matching the aforementioned lower bound up to a constant in the base of the exponent (n denotes the number of vertices of the input graph).

Organisation of the Paper

In Section 2 we recall widely known notions and facts that are of further use, and provide the details of the combinatorial reformulation of the problem by Kermarrec and Thraves [14]. Section 3 is devoted to refinements in the analysis of the case of the complete signed graphs, while Section 4 describes upper and lower bounds for the complexity of the general case. Finally, in Section 5 we gather conclusions and ideas for further work.

2 Preliminaries

Basic Definitions

For a finite set V, by an ordering of V we mean a bijection π : V → {1, 2, …, |V|}. We sometimes treat an ordering π as a linear order on V and for u, vV we write u π v to denote π(u)≤π(v). A lexicographic ordering imposed by π on pairs of elements from V is an ordering \(\pi ^{\prime }\) of V×V defined as follows: \((a, b)\leq _{\pi ^{\prime }} (c, d)\) if and only if a < π c, or a = c and b π d. If π is an ordering of vertices of a directed graph G, then we say that π is a topological ordering if and only if for every (v, w) ∈ E(G) we have that v π w. A directed graph admits a topological ordering of vertices if and only if it is acyclic.

In a graph G = (V, E) the neighbourhood of a vertex v, denoted N(v), is the set of all its neighbours, i.e., {w : vwE}. The closed neighbourhood of v is defined as \(N[v]=N(v)\cup \{v\}\).

A signed graph is a triple G = (V, E +, E ), where \(E^{+}, E^{-}\subseteq \binom {V}{2}\) and \(E^{+}\cap E^{-}=\emptyset \). We view a signed graph as an undirected simple graph with two possible labels on the edges: positive (+ ) and negative (−). We call the edges from E + positive, while those from E negative. The graph G +=(V, E +) is called the positive part of G, and G =(V, E ) — the negative part. A signed graph is called complete if \(E^{+}\cup E^{-}=\binom {V}{2}\), i.e., every pair of vertices is adjacent via a positive or negative edge.

Proper Interval Graphs

Let G = (V, E) be an undirected graph, \({{\mathcal {I}}}\) be a family of size |V| of intervals on real line with nonempty interiors and pairwise different endpoints and \(\iota :V\to {{\mathcal {I}}}\) be any bijection. We say that \({{\mathcal {I}}}\) is an interval model for G if for every v, wV, vw, vwE is equivalent to \(\iota (v)\cap \iota (w)\neq \emptyset \). \({{\mathcal {I}}}\) is a proper interval model if, additionally, none of the intervals is entirely contained in any other. Graphs having an interval model are called interval graphs, while if a proper interval model exists as well, we call them proper interval graphs.

Looges and Olariu showed the following combinatorial characterization of proper interval graphs. An ordering π of the vertex set of a graph G = (V, E) is called an umbrella ordering if whenever π(v 1) < π(v 2) < π(v 3), then v 1 v 3E implies v 1 v 2E and v 2 v 3E.

Theorem 2.1 ([19])

A graph G is a proper interval graph if and only if G admits an umbrella ordering.

Exponential Time Hypothesis

[11]: The Exponential Time Hypothesis (ETH for short) asserts that there exists a constant C > 0 such that no algorithm solving the 3-CNF-SAT problem in O(2Cn) exists, where n denotes the number of variables in the input formula.

Combinatorial Problem Statement

In [14], Kermarrec and Thraves work with the metric definition of the problem: Given a signed graph G = (V, E +, E ) a feasible embedding of G in the Euclidean space \({{\mathbb {R}}}^{l}\) is such a function \(f:V\to {{\mathbb {R}}}^{l}\) that for all u 1, u 2, u, if u 1 uE + and u 2 uE , then d(f(u 1), f(u)) < d(f(u 2), f(u)) (recall that d stands for the Euclidean distance in \({{\mathbb {R}}}^{l}\)). However, for the 1-dimensional case they have in essence proved the following result:

Theorem 2.2 (Lemmata 3 and 4 of [14], rephrased)

A signed graph G = (V, E + , E ) has a feasible embedding in a line iff there is an ordering π of V such that for every u ∈ V:

  • (i) there are no u 1 < π u 2 < π u such that u 1 u ∈ E + and u 2 u ∈ E ;

  • (ii) there are no u 1 > π u 2 > π u such that u 1 u ∈ E + and u 2 u ∈ E .

We will jointly call conditions (i) and (ii)the condition imposed on u. Somewhat abusing the notation, the ordering π will also be called an embedding of G into the line. Therefore, from now on we are working with the following combinatorial problem that is equivalent to the version considered by Kermarrec and Thraves:

figure a

3 The Complete Signed Graph Case

In their work, Kermarrec and Thraves [14] announced a polynomial-time algorithm solving the Line Cluster Embedding problem in the case where the input signed graph is complete. Their line of reasoning was essentially as follows: if a signed graph can be embedded into a line, then its positive part has to be chordal. However, for a connected chordal graph with at least 4 vertices that actually is embeddable into a line, every perfect elimination ordering of the graph is a feasible solution. Therefore, having checked that the graph is chordal and computed a perfect elimination ordering of every connected component, we can simply verify whether the obtained ordering is a correct line embedding.

We refine the approach of Kermarrec and Thraves by showing the following simple observation (see also Fig. 1 for an illustration).

Fig. 1
figure 1

A picture proof of Lemma 3.1. The first row presents forbidden situations in a feasible embedding of G into a line, whereas the second row presents forbidden situations in an umbrella ordering

Lemma 3.1

For a signed complete graph G = (V, E + , E ), an ordering π of V is a feasible embedding of G into a line if and only if π is an umbrella ordering of the positive part of G.

Proof

If π is not a feasible embedding of G into a line, then there exists u 1, u 2, uV such that u 1 uE +, u 2 uE , and u 2 lies between u 1 and u in the ordering π. Consequently, u 1 u is an edge of the positive part, but u 2 u is not, hence π is not an umbrella ordering of G +.

In the other direction, if π is not an umbrella ordering of G +, then there exist v 1 < π v 2 < π v 3 such that v 1 v 2E + but v 1 v 3E + or v 3 v 2E +. As G is a complete graph, v 1 v 3E or v 3 v 2E . In the first case, we have a violation of condition (ii) imposed on v 1, and in the second case we have a violation of condition (i) imposed on v 3. Consequently, π is not a feasible embedding of G into a line.

Corollary 3.2

A complete signed graph G = (V, E + , E ) is embeddible in \({{\mathbb {R}}}^{1}\) if and only if G + =(V, E + ) is a proper interval graph.

Recall that proper interval graphs are a subclass of chordal graphs; therefore, the result nicely fits into the picture of Kermarrec and Thraves. Moreover, the theory of proper interval graphs is well-studied, so many results from that area can be immediately translated to our setting. For instance, many NP-complete problems become solvable in polynomial time on proper interval graphs (e.g., [2, 10, 13, 20]), and the linear-time algorithm of Corneil et al. [4] for recognizing proper interval graphs immediately solves the Line Cluster Embedding problem in linear time in case of a complete signed graph.

Corollary 3.3

Assuming the input graph is complete and given as the set of positive edges, Line Cluster Embedding can be solved in O(|V|+|E + |) time complexity. Moreover, the algorithm can produce a feasible ordering of the vertices in the same time, if such an ordering exists.

4 The General Case

4.1 NP-Completeness of the General Case

In [14] Kermarrec and Thraves asked whether the Line Cluster Embedding problem is also polynomial-time solvable in the case where the input is not restricted to complete graphs. In this section we show that this is unlikely: in fact, the problem becomes NP-complete.

In the proof we use an auxiliary problem, called Acyclic Partition.

figure b

Acyclic Partition has been introduced and proven to be NP-complete by Eppstein and Mumford [7] and, independently, by Guillemot et al. [9]. In both these papers it was used as a pivot problem for proving NP-completeness of other problems. For the sake of completeness we would like to revisit the NP-hardness proof, because we need explicit bounds on the size of the directed graph obtained in the reduction for further applications. We begin with an instance of the Set Splitting problem, which is known to be NP-complete [8].

figure c

Lemma 4.1

There exists a polynomial-time algorithm that given an instance \(({{\mathcal {F}}}, U)\) of Set Splitting outputs an equivalent instance G = (V, A) of Acyclic Partition, for which \(|V|=|U|+{\sum }_{F\in {{\mathcal {F}}}} |F|\) and \(|A|=3{\sum }_{F\in {{\mathcal {F}}}} |F|\).

Proof

We construct the directed graph D = (V, A) as follows. For every set \(F\in {{\mathcal {F}}}\) and every uF we build a vertex \({c_{u}^{F}}\) and connect all the vertices corresponding to the same set F into a directed cycle in any order. For every element uU we build a vertex d u and for every vertex of the form \({c_{u}^{F}}\) we introduce two arcs: \((d_{u}, {c_{u}^{F}})\) and \(({c_{u}^{F}}, d_{u})\). This concludes the construction; it is easy to verify the claimed sizes of V and A.

Let us formally prove that the instances are equivalent. Let X be any solution to the \(({{\mathcal {F}}}, U)\) instance of Set Splitting. Let \(V_{1}=\{d_{u}:u\in X\}\cup \{{c_{u}^{F}}:u\in U\setminus X\}\) and \(V_{2}=\{d_{u}:u\in U\setminus X\}\cup \{{c_{u}^{F}}:u\in X\}\). As X splits every set \(F\in {{\mathcal {F}}}\), none of the cycles formed by vertices \({c_{u}^{F}}\) for fixed F is entirely contained in either V 1 or V 2. Also, for every element u the vertex d u becomes isolated in the corresponding graph D[V i ], as all his neighbours belong to V 3−i . Therefore, both D[V 1] and D[V 2] are collections of isolated vertices and directed paths and (V 1, V 2) is a solution to the Acyclic Partition instance.

In the other direction, let (V 1, V 2) be a solution to the instance of Acyclic Partition. Let \(X=\{u:d_{u}\in V_{1}\}\subseteq U\); we claim that X is a solution to the instance of Set Splitting. Note that, due to the 2-cycles on the vertices d u and \({c_{u}^{F}}\), we have that for every uX, all vertices \({c_{u}^{F}}\) belong to V 2, whereas for every uX, all vertices \({c_{u}^{F}}\) belong to V 1.

Take any \(F\in {{\mathcal {F}}}\). As the cycle formed by vertices \({c_{u}^{F}}\) is not entirely contained in any of the graphs D[V 1], D[V 2], there exist some u 1 such that \(c_{u_{1}}^{F}\in V_{1}\) and u 2 such that \(c_{u_{2}}^{F}\in V_{2}\). As the cycles formed by pairs \(\{d_{u_{1}}, c_{u_{1}}^{F}\}\) and \(\{d_{u_{2}}, c_{u_{2}}^{F}\}\) are also not entirely contained in D[V 1] nor in D[V 2], \(d_{u_{1}}\in V_{2}\) and \(d_{u_{2}}\in V_{1}\). Consequently, u 1UX, u 2X and F is split.

Lemma 4.2

There exists a polynomial-time algorithm that given an instance D=(V, A) of Acyclic Partition outputs an equivalent instance \(H=(V^{\prime }, E^{+}, E^{-})\) of Line Cluster Embedding, such that \(|V^{\prime }|=|V|+|A|+1\) , |E + |=2|A| and |E |=|A|+|V|.

Proof

We construct the graph H as follows: The set of vertices, \(V^{\prime }\), consists of:

  • a special vertex s;

  • for every eA, a checker vertex c e ;

  • for every vV, an alignment vertex a v .

We construct the edges of the signed graph as follows:

  • for every eA, we introduce a positive edge sc e ;

  • for every vV, we introduce a negative edge sa v ;

  • for every arc (v, w) ∈ A, we introduce a positive edge c (v, w) a v and a negative edge c (v, w) a w .

This concludes the construction; it is easy to verify the claimed sizes of \(V^{\prime }, E^{+}, E^{-}\).

Let us prove equivalence of the instances. Let π, an ordering of \(V^{\prime }\), be a solution of the Line Cluster Embedding instance \((V^{\prime }, E^{+}, E^{-})\). As the special vertex s is adjacent via positive edges to all the checker vertices, and via negative edges to all the other, alignment, vertices, in the ordering π the checker vertices together with the special vertex have to form an interval, i.e., a set of consecutive elements with respect to π. Let V 1 be the set of those vV for which a v is to the left of this interval, whereas V 2 is the set of those vV for which a v is to the right of this interval. Formally, V 1={vV : a v π s} and V 2={vV : a v π s}. We claim that (V 1, V 2) is a feasible solution of the Acyclic Partition instance (V, A). Consider any arc (v, w) such that v, wV 1. As a v π c (v, w), a w π c (v, w), c (v, w) a v E + and c (v, w) a w E , then it follows that a w π a v . Thus, π has to induce a reverse topological ordering on the vertices of D[V 1] and, therefore, D[V 1] has to be acyclic. Symmetrically, D[V 2] has to be acyclic as well, which concludes the proof of (V 1, V 2) being a feasible solution.

Now take any solution (V 1, V 2) of Acyclic Partition instance (V, A). Let π 1 be any topological ordering of D[V 1] and π 2 be any topological ordering of D[V 2], by which we mean that if (u, v) is an arc of D[V 1], π 1(u) < π 1(v), and the same holds for π 2. Let us construct an ordering π of \(V^{\prime }\) as follows:

  • first, place all the vertices a v for vV 1 in the reverse order induced by π 1;

  • then, place all the checker vertices c (v, w) for which vV 1 and wV 2, in any order;

  • then, place all the checker vertices c (v, w) for which v, wV 1, in reverse lexicographic order imposed by π 1 on pairs (v, w);

  • then, place the special vertex s;

  • then, place all the checker vertices c (v, w) for which v, wV 2, in lexicographic order imposed by π 2 on pairs (v, w);

  • then, place all the checker vertices c (v, w) for which vV 2 and wV 1, in any order;

  • finally, place all the vertices a v for vV 2 in the order induced by π 2.

We claim that such π is a feasible solution to Line Cluster Embedding instance \((V^{\prime }, E^{+}, E^{-})\).

Note that the positive neighbours of the special vertex s form an interval, therefore the condition imposed on this vertex is satisfied. Now consider a checker vertex c (v, w). If v, w belong to different sets V 1, V 2, then the only negative neighbour of c (v, w) is the first or the last of his closed neighbourhood with respect to π, thus satisfying the condition imposed on c (v, w). In case when v, wV 1 or v, wV 2 this is also true, due to π 1, π 2 being topological orderings of D[V 1], D[V 2] respectively.

Now take any vertex a v , by symmetry assume vV 1. We need to prove that the condition imposed on a v is satisfied as well. The neighbours of v consist of:

  1. 1.

    positive neighbours \(c_{(v, v^{\prime })}\), such that \(v^{\prime }\in V_{2}\);

  2. 2.

    positive neighbours \(c_{(v, v^{\prime })}\), such that \(v^{\prime }\in V_{1}\);

  3. 3.

    negative neighbours \(c_{(v^{\prime }, v)}\), such that \(v^{\prime }\in V_{1}\);

  4. 4.

    negative neighbours \(c_{(v^{\prime }, v)}\), such that \(v^{\prime }\in V_{2}\).

We now verify that by the construction of π the neighbours of a v lie in this very order with respect to π. Clearly, the order in which we placed the checkers in π ensures that the neighbours from (1) are placed before the neighbours from (2) and that the neighbours from (3) are placed before the neighbours from (4). Thus the only non-trivial check is whether the vertices from (2) lie before the vertices from (3). Assume otherwise, that there are some \(v_{1}^{\prime }, v_{2}^{\prime }\) such that \((v, v_{1}^{\prime })\in A\), \((v_{2}^{\prime }, v)\in A\), but \(c_{(v, v_{1}^{\prime })}>_{\pi }c_{(v_{2}^{\prime }, v)}\). Then \(v_{2}^{\prime }<_{\pi _{1}}v\) as π 1 is a topological ordering of D[V 1], so the pair \((v_{2}^{\prime }, v)\) is lexicographically smaller than the pair \((v, v_{1}^{\prime })\). Hence \(c_{(v, v_{1}^{\prime })}>_{\pi }c_{(v_{2}^{\prime }, v)}\), a contradiction with the construction of π.

We have verified that for all the vertices the conditions imposed on them are satisfied, so the instances are equivalent.

The NP-completeness of the Set Splitting problem [8], together with Lemmata 4.1, 4.2 and a trivial observation that Line Cluster Embedding is in NP, gives us the following theorem.

Theorem 4.3

The Line Cluster Embedding problem is NP-complete.

As mentioned before, the question of finding the smallest dimension of the Euclidean space, into which the given graph can be embedded, clearly generalizes testing embeddability into a line. Therefore, we have the followingcorollary.

Corollary 4.4

It is NP-hard to decide the smallest dimension of the Euclidean space, into which a given signed graph can be embedded.

4.2 Lower Bound on the Complexity

In this subsection we observe that the presented chain of reductions enables us also to establish a lower bound on the complexity of solving Line Cluster Embedding under ETH. Firstly, let us complete the chain of the reductions.

Lemma 4.5

There exists a polynomial-time algorithm that given an instance φ of 3 -CNF-SAT with n variables and m clauses, outputs an equivalent instance \((U, {\mathcal {F}})\) of Set Splitting with |U|=2n+1 and \({\sum }_{F\in {\mathcal {F}}} |F|=2n+4m\).

Proof

We construct the instance \((U, {{\mathcal {F}}})\) as follows. The universe U consists of one special element s and two literals x, ¬x for every variable x of φ. The family \({\mathcal {F}}\) includes (a) for every variable x, a set F x ={x, ¬x}; (b) for every clause C, a set F C consisting of s and all the literals in C. It is easy to check the claimed sizes of \(U, {\mathcal {F}}\). We claim that the instance of Set Splitting \((U, {\mathcal {F}})\) is equivalent to the instance φ of 3-CNF-SAT.

Assume that ψ is a boolean evaluation of variables of φ that satisfies φ. We construct a set \(X\subseteq U\) as follows: X consists of all the literals that are true in ψ. Now, every set F x is split, as exactly one of the literals is true and one is false, whereas every set F C is split as well, as it contains a true literal, which belongs to X, and the special element s, which does not.

Now assume that \(X\subseteq U\) is a solution to the Set Splitting instance \((U, {{\mathcal {F}}})\). As taking UX instead of X also yields a solution, without losing generality we can assume that sX. Every set F x is split by X; therefore, exactly one literal of every variable belongs to X and exactly one does not. Let ψ be a boolean evaluation of variables of φ such that it satisfies all the literals belonging to X. Observe that ψ satisfies φ : for every clause C the set F C has to be split, so, as sX, one of the literals of C belongs to X and, thus, is satisfied by ψ.

Note that by pipelining Lemmata 4.5, 4.1 and 4.2, we obtain a reduction from 3-CNF-SAT to Line Cluster Embedding, where the output instance has a number of vertices and edges bounded linearly in the number of variables and clauses of the input formula. As the Exponential Time Hypothesis also excludes a possibility of having an algorithm for 3-CNF-SAT with running time subexponential in the total number of variables and clauses of the formula [12], we obtain the following.

Theorem 4.6

Unless ETH fails, there is a constant δ>0 such that there is no algorithm that given a (V, E + , E ) instance of Line Cluster Embedding problem, solves it in \(O(2^{\delta (|V|+|E^{+}|+|E^{-}|)})\) time.

4.3 A Single-Exponential Algorithm for Line Cluster Embedding

Note that the trivial brute-force algorithm for Line Cluster Embedding checks all possible orderings, working in O (n!) time. To complete the picture of the complexity of Line Cluster Embedding, we show that a simple dynamic programming approach can give single-exponential time complexity. This matches the lower bound obtained from under Exponential Time Hypothesis (up to a constant in the base of the exponent).

Before we proceed with the description of the algorithm, let us state a combinatorial observation that will be its main ingredient. Let (V, E +, E ) be the given Line Cluster Embedding instance. For \(X\subseteq V\) and vX we will say that v is good for the set X iff

  • no vertex wX that is adjacent to v via a negative edge is simultaneously adjacent to some vertex from \(V\setminus (X\cup \{v\})\) via a positive edge;

  • no vertex \(w\in V\setminus (X\cup \{v\})\) that is adjacent to v via a negative edge is simultaneously adjacent to some vertex from X via a positive edge.

Lemma 4.7

An ordering π is a feasible solution of (V, E + , E ) if and only if every vertex v ∈ V is good for the set {u : u < π v}.

Proof

One direction is obvious: if π is a feasible solution, then every vertex v has to be good for the set {u : u < π v}. If v would not be good for {u : u < π v}, there would exist a vertex w certifying that v is not good, and the condition imposed upon w would be not satisfied.

Now assume that every vertex vV is good for {u : u < π v} and take an arbitrary vertex vV. If there were vertices u 1 < π u 2 < π v such that u 1 vE + while u 2 vE , then u 2 would not be good for the set {u : u < π u 2}, a contradiction. Similarly, if there were vertices u 1 > π u 2 > π v such that u 1 vE + while u 2 vE , then u 2 would not be good for the set {u : u < π u 2}, a contradiction as well. Therefore, the condition imposed on v is satisfied for an arbitrary choice of v.

Theorem 4.8

Line Cluster Embedding can be solved in O (2 n ) time and space complexity. Moreover, the algorithm can also output a feasible ordering of the vertices, if it exists.

Proof

Let (V, E +, E ) be the given Line Cluster Embedding instance. Let W = {(v, X):v is good for X}. Let us construct a directed graph D = (W, F), where \(((v, X), (v^{\prime }, X^{\prime }))\in F\) if and only if \(X^{\prime }=X\cup \{v\}\). As recognizing being good is clearly a polynomial time operation, the graph D can be constructed in O (2n) time and has that many vertices and edges. Observe that by Lemma 4.7 there is a feasible ordering π if and only if some sink (v, V∖{v}) is reachable from some source (u, ); indeed, such a path corresponds to introducing the vertices of V one by one in such a manner that each of them is good for the respective prefix. Reachability of any sink from any source can be, however, tested in time linear in the size of the graph using a breadth-first search. The search can also reconstruct the path in the same complexity, thus constructing the feasible solution.

5 Conclusions

In this paper we addressed a number of problems raised by Kermarrec and Thraves in [14] for embeddability of a signed graph into a line. We refined their study of the case of a complete signed graph by showing relation with proper interval graphs. Moreover, we have proven NP-hardness of the general case and shown an almost complete picture of its complexity.

Although the general case of the problem appears to be hard, real-life social networks have a certain structure. Is it possible to develop faster, maybe even polynomial-time algorithms for classes of graphs reflecting this structure?