Sitting Closer to Friends than Enemies, Revisited

Signed graphs, i.e., undirected graphs with edges labelled with a plus or minus sign, are commonly used to model relationships in social networks. Recently, Kermarrec and Thraves (2011) initiated the study of the problem of appropriately visualising the network: They asked whether any signed graph can be embedded into the metric space \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}${{\mathbb {R}}}^{l}$\end{document}ℝl in such a manner that every vertex is closer to all its friends (neighbours via positive edges) than to all its enemies (neighbours via negative edges). Interestingly, embeddability into \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}${{\mathbb {R}}}^{1}$\end{document}ℝ1 can be expressed as a purely combinatorial problem. In this paper we pursue a deeper study of this case, answering several questions posed by Kermarrec and Thraves. First, we refine the approach of Kermarrec and Thraves for the case of complete signed graphs by showing that the problem is closely related to the recognition of proper interval graphs. Second, we prove that the general case, whose polynomial-time tractability remained open, is in fact NP-complete. Finally, we provide lower and upper bounds for the time complexity of the general case: we prove that the existence of a subexponential time (in the number of vertices and edges of the input signed graph) algorithm would violate the Exponential Time Hypothesis, whereas a simple dynamic programming approach gives a running time single-exponential in the number of vertices.


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,5,12,13,14,15,17].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 [11] formalized this problem as follows: Consider the metric space R l with the Euclidean metric denoted by d.Given a signed graph G, is it possible to embed the vertices of G in 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 [11] 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.
Our results.In this paper, we focus on the problem of embedding a signed graph into a line.The reformulation of the 1-dimensional case, proven by 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 wellstudied 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 embedability of a complete graph into a line, with a linear runtime.
We next analyse the general case.We resolve the open problem posed in [11] negatively: it is N Pcomplete to resolve whether a given signed graph can be embedded into a line.This hardness result also answers other questions of Kermarrec and Thraves [11].For example, we infer that it is N P -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 [8] (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 ⋆ (2 n ) time1 , 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 [11].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.

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, v ∈ V we write u ≤ π v to denote π(u) ≤ π(v).
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 : vw ∈ E}.The closed neighbourhood of v is defined as A signed graph is a triple G = (V, E + , E − ), where E + , E − ⊆ V [2] and E + ∩ E − = ∅.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 [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, I be a family of size |V | of intervals on real line with nonempty interiors and pairwise different endpoints and ι : V → I be any bijection.We say that I is an interval model for G if for every v, w ∈ 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.We will omit the mapping ι whenever it is clear from the context.Exponential Time Hypothesis [8]: 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(2 Cn ) exists, where n denotes the number of variables in the input formula.
Combinatorial problem statement.In [11], Kermarrec and Thraves work with the metric definition of the problem: Given a signed graph that d stands for the Euclidean distance in R l ).However, for the 1-dimensional case they have in essence proved the following result: Theorem 2.1 (Lemmata 3 and 4 of [11], 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 : 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: Line Cluster Embedding Task: Does there exist an ordering π on V such that for every u ∈ V : (i) there are no

The complete signed graph case
In their work, Kermarrec and Thraves [11] 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 that a complete graph has a line embedding if and only if its positive part 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,7,10,16]), 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.
is a proper interval graph.Moreover, having a feasible ordering π of vertices of V , a proper interval model of G + sorted with respect to the left ends of the intervals can be computed in linear time; conversely, having a proper interval model of G + sorted with respect to the left ends of the intervals, we can compute a feasible ordering π in linear time.
Proof.First, let us assume that G + is a proper interval graph, and let I = {I v : v ∈ V } be a proper interval model of G + .Notice that as no interval is contained in another, we have a natural order on I -ordering the intervals with respect to the left ends (or, equivalently, the right ends).We claim that π is a feasible solution for the Line Cluster Embedding instance G = (V, E + , E − ).Take any u ∈ V .Assume that there were some u 1 < π u 2 < π u such that u 1 u ∈ E + and u 2 u ∈ E − ; this implies intervals I u1 and I u would overlap.This, in turn, means that the right end of interval I u1 would be on the right of the left end of interval I u .Therefore, the left and right ends of I u2 are on different sides of the left end of I u , as u 2 < π u and u 1 < π u 2 , so I u2 and I u overlap.This is a contradiction with u 2 u / ∈ E + .A symmetrical argument for the second case finishes the proof in this direction.Now let us assume that G is embeddable in the line and let π, an ordering of V , be a solution.Moreover, let v ← be the first (with respect to π) vertex in the closed neighbourhood of v in G + , while let v → be the for v ∈ V and I = {I v : v ∈ V }.Observe that intervals I v have nonempty interior and pairwise different endpoints.Now, we prove that (1) no I v is fully contained in some other I w and (2) for all v, w ∈ V , vw ∈ E + if and only if I v ∩ I w = ∅.This suffices to show that I is a proper interval model for G + .
In order to establish (1), let us assume the contrary: there exists a pair of vertices v, w such that π(v) > π(w) and π(v Therefore, by definition of v → , vw → ∈ E − .On the other hand, ww → ∈ E + and w < π v < π w → , a contradiction with the assumption that π was a proper embedding.Now we proceed to the proof of (2).Take any two distinct vertices v, w, without losing generality assume that v < π w.
|V |+1 , so I v and I w overlap.On the other hand if vw ∈ E − , then from the condition imposed on v it follows that w > π v → .Consequently, π(w) > π(v → ) and, as π(v |V |+1 .Therefore, in this case I v and I w do not overlap.This proves I is in fact a proper interval model for G + .
The algorithmic part of the theorem statement follows directly from the presented constructions.
Let us recall the result of Corneil et al. [4], which states that proper interval graphs can be recognized in linear time and the algorithm can also output an ordering of the vertices with respect to the left ends of intervals in some model.We can pipeline this routine with Theorem 3.1 in order to obtain the following corollary: Theorem 3.2.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.

The general case 4.1 NP -completeness of the general case
In [11] Kermarrec and Thraves asked whether the Line Cluster Embedding problem is also polynomialtime 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 N P -complete.The proof consists of two steps.First, using a reduction from the Set Splitting problem we show that an auxiliary problem, called Acyclic Digraph Partition, is N P -complete.Next, we reduce Acyclic Digraph Partition to Line Cluster Embedding.We believe that the Acyclic Digraph Partition can turn out to be a useful pivot problem also in other hardness reductions.

Acyclic Digraph Partition
Input: A directed graph D = (V, A).
Task: Is it possible to partition V into two sets V 1 and V 2 , so that both D[V 1 ] and D[V 2 ] are directed acyclic graphs (DAGs)?
Let us also recall the definition of the NP-complete Set Splitting problem [6].

Set Splitting
Input: A set system (F , U ), where F ⊆ 2 U .Task: Does there exist a subset X ⊆ U such that each set in F contains both an element from X and an element from U \ X? Proof.We construct the directed graph D = (V, A) as follows.For every set F ∈ F and every u ∈ F we build a vertex c F u and connect all the vertices corresponding to the same set F into a directed cycle in any order.For every element u ∈ U we build a vertex d u and for every vertex of the form c F u we introduce two arcs: (d u , c F u ) and (c F u , 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 (F , U ) instance of Set Splitting.
As X splits every set F ∈ F , none of the cycles formed by vertices c F u 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 Digraph Partition instance.
In the other direction, let (V 1 , V 2 ) be a solution to the instance of Acyclic Digraph Partition.Let X = {u : we claim that X is a solution to the instance of Set Splitting.Take any F ∈ F .As the cycle formed by vertices c F u is not entirely contained in any of the graphs As the cycles formed by pairs {d u1 , c F u1 } and {d u2 , c F u2 } are also not entirely contained in Proof.We construct the graph H as follows: The set of vertices, V ′ , consists of: • a special vertex s; • for every e ∈ A, a checker vertex c e ; • for every v ∈ V , an alignment vertex a v .
We construct the edges of the signed graph as follows: • for every e ∈ A, we introduce a positive edge sc e ; • for every v ∈ V , 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 ′ , E + , E − .
Let us now formally prove equivalence of the instances.Let π, an ordering of V ′ , be a solution of the Line Cluster Embedding instance (V ′ , 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.Let V 1 be the set of those v ∈ V for which a v is to the left of this interval, whereas V 2 is the set of those v ∈ V for which a v is to the right of this interval.Formally, 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 Digraph 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 ′ as follows: • first, we place all the vertices a v for v ∈ V 1 in the reverse order induced by π 1 ; • then, we place all the checker vertices c (v,w) for which v ∈ V 1 and w ∈ V 2 , in any order; • then, we place all the checker vertices c (v,w) for which v, w ∈ V 1 , in reverse lexicographic order imposed by π 1 on pairs (v, w); • then, we place the special vertex s; • then, we place all the checker vertices c (v,w) for which v, w ∈ V 2 , in lexicographic order imposed by π 2 on pairs (v, w); • then, we place all the checker vertices c (v,w) for which v ∈ V 2 and w ∈ V 1 , in any order; • finally, we place all the vertices a v for v ∈ V 2 in the order induced by π 2 .
We claim that such π is a feasible solution to Line Cluster Embedding instance (V ′ , 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, w ∈ V 1 or v, w ∈ V 2 this is also true, due to π 1 , π 2 being topological orderings of Now take any vertex a v , by symmetry assume v ∈ V 1 .We need to prove that the condition imposed on a v is satisfied as well.The neighbours of v consist of: 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 ) is 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 N P -completeness of the Set Splitting problem [6], together with Lemmata 4.1, 4.2 and a trivial observation that Line Cluster Embedding is in N P , gives us the following theorem.
Theorem 4.3.The Line Cluster Embedding problem is N P -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 following corollary.
Corollary 4.4.It is N P -hard to decide the smallest dimension of the Euclidean space, into which a given signed graph can be embedded.
• take an instance of 3-CNF-SAT and using Sparsification Lemma in O ⋆ (2 εn/2 ) time express it as a disjunction of at most 2 εn/2

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 ⊆ V and v / ∈ X we will say that v is good for the set X iff • no vertex w ∈ X that is adjacent to v via a negative edge is simultaneously adjacent to some vertex from V \ (X ∪ {v}) via a positive edge; • no vertex w ∈ V \ (X ∪ {v}) that is adjacent to v via a negative edge is simultaneously adjacent to some vertex from X via a positive edge.
Lemma 4.8.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 v ∈ V is good for {u : u < π v} and take an arbitrary vertex v ∈ V .If there were vertices u 1 < π u 2 < π v such that u 1 v ∈ E + while u 2 v ∈ E − , 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 v ∈ E + while u 2 v ∈ E − , 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.
We are now ready to provide the details of the algorithm.Theorem 4.9.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 ′ , X ′ )) ∈ F if and only if X ′ = X ∪ {v}.As recognizing being good is clearly a polynomial time operation, the graph D can be constructed in O ⋆ (2 n ) time and has that many vertices and edges.Observe that by Lemma 4.8 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.

Conclusions
In this paper we addressed a number of problems raised by Kermarrec and Thraves in [11] 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 N P -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?Can we make use of good combinatorial or spectral behaviour of real-life instances?

Lemma 4 . 1 .
There exists a polynomial-time algorithm that given an instance (F , U ) of Set Splitting outputs an equivalent instance G = (V, A) of Acyclic Digraph Partition, for which |V | = |U |+ F ∈F |F | and |A| = 3 F ∈F |F |.
3-CNF-SAT instances, each containing at most Cn clauses for some constant C; • reduce each instance in polynomial time via Set Splitting and Acyclic Digraph Partition to Line Cluster Embedding, thus obtaining at most 2 εn/2 instances of Line Cluster Embedding, each having |V |, |E + |, |E − | ≤ C ′ n for some constant C ′ ; • in each of the instances run the assumed algorithm for Line Cluster Embedding, running in O(2 δ(|V |+|E + |+|E − |) ) time, for δ = ε 6C ′ .