Rainbow Colouring of
Split and Threshold Graphs
A rainbow colouring of a connected graph is a colouring of the edges of the graph, such that every pair of vertices is connected by at least one path in which no two edges are coloured the same. Such a colouring using minimum possible number of colours is called an optimal rainbow colouring, and the minimum number of colours required is called the rainbow connection number of the graph. A Chordal Graph is a graph in which every cycle of length more than has a chord. A Split Graph is a chordal graph whose vertices can be partitioned into a clique and an independent set. A threshold graph is a split graph in which the neighbourhoods of the independent set vertices form a linear order under set inclusion. In this article, we show the following:
The problem of deciding whether a graph can be rainbow coloured using colours remains NP-complete even when restricted to the class of split graphs. However, any split graph can be rainbow coloured in linear time using at most one more colour than the optimum.
For every integer , the problem of deciding whether a graph can be rainbow coloured using colours remains NP-complete even when restricted to the class of chordal graphs.
For every positive integer , threshold graphs with rainbow connection number can be characterised based on their degree sequence alone. Further, we can optimally rainbow colour a threshold graph in linear time.
Keywords: rainbow connectivity, rainbow colouring, threshold graphs, split graphs, chordal graphs, degree sequence, approximation, complexity.
Connectivity is one of the basic concepts of graph theory. It plays a fundamental role both in theoretical studies and in applications. When a network (transport, communication, social, etc) is modelled as a graph, connectivity gives a way of quantifying its robustness. This may be the reason why connectivity is possibly the problem that has been studied on the largest variety of computational models . Due to the diverse application requirements and manifold theoretical interests, many variants of the connectivity problem have been studied. One typical case is when there are different possible types of connections (edges) between nodes and additional restrictions on connectivity based on the types of edges that can used in a path. In this case we can model the network as an edge-coloured graph. One natural restriction to impose on connectivity is that any two nodes should be connected by a path in which no edge of the same type (colour) occurs more than once. This is precisely the property called rainbow connectivity. Such a restriction for the paths can arise, for instance, in routing packets in a cellular network with transceivers that can operate in multiple frequency bands or in routing secret messages between security agencies using different handshaking passwords in different links  . The problem was formalised in graph theoretic terms by Chartrand et al.  in 2008.
An edge colouring of a graph is a function from its edge set to the set of natural numbers. A path in an edge coloured graph with no two edges sharing the same colour is called a rainbow path. An edge coloured graph is said to be rainbow connected if every pair of vertices is connected by at least one rainbow path. Such a colouring is called a rainbow colouring of the graph. A rainbow colouring using minimum possible number of colours is called optimal. The minimum number of colours required to rainbow colour a connected graph is called its rainbow connection number, denoted by . For example, the rainbow connection number of a complete graph is , that of a path is its length, that of an even cycle is its diameter, that of an odd cycle of length at least is one more than its diameter, and that of a tree is its number of edges. Note that disconnected graphs cannot be rainbow coloured and hence the rainbow connection number for them is left undefined. Any connected graph can be rainbow coloured by giving distinct colours to the edges of a spanning tree of the graph. Hence the rainbow connection number of any connected graph is less than its number of vertices.
While formalising the concept of rainbow colouring, Chartrand et al. also determined the precise values of rainbow connection number for some special graphs . Subsequently, there have been various investigations towards finding good upper bounds for rainbow connection number in terms of other graph parameters      and for many special graph classes    . Behaviour of rainbow connection number in random graphs is also well studied    . A basic introduction to the topic can be found in Chapter of the book Chromatic Graph Theory by Chartrand and Zhang  and a survey of most of the recent results in the area can be found in the article by Li and Sun  and also in their forthcoming book Rainbow Connection of Graphs .
On the computational side, the problem has received relatively less attention. It was shown by Chakraborty et al. that computing the rainbow connection number of an arbitrary graph is NP-Hard . In particular, it was shown that the problem of deciding whether a graph can be rainbow coloured using colours is NP-complete. Later, Ananth et al.  complemented the result of Chakraborty et al., and now we know that for every integer , it is NP-complete to decide whether a given graph can be rainbow coloured using colours. Chakraborty et al., in the same article, also showed that deciding whether a given edge coloured graph is rainbow connected is NP-complete. It was then shown by Li and Li that this problem remains NP-complete even when restricted to the class of bipartite graphs .
On the positive side, Basavaraju et al. have demonstrated an -time -factor approximation algorithm for rainbow colouring any graph with radius . Constant factor approximation algorithms for rainbow colouring Cartesian, strong and lexicographic products of non-trivial graphs are reported in . Constant factor approximation algorithms for bridgeless chordal graphs, and additive approximation algorithms for interval, AT-free, threshold and circular arc graphs without pendant vertices will follow from the proofs of their upper bounds . To the best of our knowledge, no efficient optimal rainbow colouring algorithm has been reported for any non-trivial subclass of graphs.
1.1 Our Results
In this article we consider the problem of rainbow colouring split graphs and a particular subclass of split graphs called threshold graphs (Definition 3). We show the following results.
This is similar to the problem of finding the chromatic index of a graph. Though every graph with maximum degree can be properly edge-coloured in time using colours using a constructive proof of Vizing’s Theorem , it is NP-hard to decide whether the graph can be coloured using colours .
No two pendant edges (Definition 2) can share the same colour in any rainbow colouring of a graph (Observation 2). The -approximation algorithm above is obtained by carefully reusing the same colours on most of the remaining edges of the graph. The hardness result is obtained by demonstrating a reduction from the problem of -colourability of -uniform hypergraphs. In fact, the technique in the reduction can be extended to show the following result for chordal graphs.
For every integer , the problem of deciding whether a graph can be rainbow coloured using colours remains NP-complete even when restricted to the class of chordal graphs (Theorem 6).
Though a similar hardness result is known for deciding the rainbow connection number of general graphs, the above strengthening to chordal graphs is interesting since, unlike for general graphs, a constant factor approximation algorithm is already known for rainbow colouring chordal graphs. Chandran et al.  have shown that any bridgeless chordal graph can be rainbow coloured using at most colours, where is the radius of the graph. The proof given there is constructive and can be easily extended to a polynomial-time algorithm which will colour any chordal graph with bridges and radius using at most colours. Since is easily seen to be a lower bound for , this immediately gives us a -factor approximation algorithm.
In particular we show that if is the degree sequence of an -vertex threshold graph , then
where and .
Both the characterisation and the algorithm are obtained by connecting the problem of rainbow colouring a threshold graph to that of generating a prefix-free binary code.
All graphs considered in this article are finite, simple and undirected. For a graph , we use and to denote its vertex set and edge set respectively. Unless mentioned otherwise, and will respectively denote the number of vertices and edges of the graph in consideration. The shorthand denotes the set . The cardinality of a set is denoted by .
Let be a connected graph. The length of a path is its number of edges. The distance between two vertices and in , denoted by is the length of a shortest path between them in . The eccentricity of a vertex is . The diameter of is and radius of is .
The neighbourhood of a vertex is the set of vertices adjacent to but not including . The degree of a vertex is . The degree sequence of a graph is the non-increasing sequence of its vertex degrees. A vertex is called pendant if its degree is . An edge incident on a pendant vertex is called a pendant edge.
A graph is called chordal, if there is no induced cycle of length greater than . A graph is a split graph, if can be partitioned into a clique and an independent set. A graph is a threshold graph, if there exists a weight function and a real constant such that two vertices are adjacent if and only if .
Before getting into the main results, we note two elementary and well known observations on rainbow colouring whose proofs we omit.
For every connected graph , we have .
If and are two pendant vertices in a connected graph , then their incident edges get different colours in any rainbow colouring of . In particular, if has pendant vertices, then .
2 Split Graphs: Hardness and Approximation Algorithm
We first show that determining the rainbow connection number of a split graph is NP-hard, by demonstrating a reduction to it from the -colouring problem on -uniform hypergraphs.
A hypergraph is a tuple , where is a finite set and . Elements of and are called vertices and (hyper-)edges respectively. The hypergraph is called -uniform if for every . An -uniform hypergraph is called complete if .
Given a hypergraph and a colouring , an edge is called -coloured if the edge contains vertices of different colours. An edge is called monochromatic if it is -coloured. The colouring is called proper if no edge in is monochromatic under . The minimum number of colours required to properly colour is called its chromatic number and is denoted by .
We need a -uniform hypergraph of chromatic number to avoid the occurrence of a border case in the reduction. The following observation gives us one.
Let be the complete -uniform hypergraph on vertices. Then .
Assign colours to the vertices of . This is a proper colouring of since every edge contains vertices and hence cannot be monochromatic. On the other hand, in any colouring of using fewer than colours, some three vertices have to share the same colour and hence the edge of constituted of those vertices will be monochromatic. Hence . ∎
It follows from Theorem in  that it is NP-hard to decide whether an -vertex -uniform hypergraph can be properly coloured using colours. A reduction from this problem to a problem of computing the rainbow connection number of a split graph is illustrated in the proofs of Theorem 4 and Theorem 6.
The first problem below (P1) is polynomial-time reducible to the second (P2).
Given a -uniform hypergraph , decide whether .
Given a split graph , decide whether .
Let be the disjoint union of and a complete -uniform hypergraph on vertices (). This ensures that (Observation 3) and that iff . Let and be the vertex set and edge set, respectively, of . We construct a graph from as follows (See Figure 1).
The graph thus constructed is a split graph with being a clique and its complement with respect to , which is , being an independent set. It is clear that can be constructed from in polynomial-time. We complete the proof by showing that iff .
Firstly, we show that if , then . Since , it suffices to show that can be properly -coloured. Let be a rainbow colouring of . Define a colouring by for each . We claim that is a proper colouring of . For the sake of contradiction, suppose that one of the hyper-edges of is monochromatic under , i.e, all the vertices in get the same colour for some . This happens only when . Hence all the paths of length two from to in will use the colour . Since are pendant vertices, the edges from to all have distinct colours in any rainbow colouring of (Observation 2). Hence one of them, say , gets the colour . Then it is easy to see that there is no rainbow path from to in under (Note that any rainbow path in a -coloured graph has length at most ). This contradicts the fact that was a rainbow colouring of .
Next, we show that if , then . Since has pendant vertices, (Observation 2). So it suffices to show that can be rainbow coloured using colours. Let be a proper colouring of . Let , , be the colour classes. Note that none of the colour classes is empty as . We define a colouring as follows (See Figure 2). for each . Consider a hyper-edge of . If is -coloured in then (Note that the colours are from and hence the addition is modulo ). If is -coloured in , then without loss of generality, let and , . Set , , and . This ensures that for every hyper-edge , for each colour , there exists a -length rainbow path from to such that colour does not appear in path . The remaining edges of are coloured as follows.
We show that is a rainbow colouring of by demonstrating a rainbow path between every pair of non adjacent vertices in . First we demonstrate the paths from to all their non-adjacent vertices. (The numbers above an edge indicate the colour assigned to the edge under .)
The rainbow path between any vertex and a non-adjacent vertex is given by , if . It remains to demonstrate a rainbow path between any two vertices . By we denote the -tuple . If is -coloured, we relabel so that and hence . If is -coloured, we relabel so that and such that and . We do the same for too. Edges and may share some vertices, in which case the same vertex will get different labels when considered under and . We consider the following cases separately: (i) both and are -coloured, (ii) is -coloured and is 2-coloured and (iii) both and are -coloured. The last case is further split into sub-cases.
It is possible that may coincide with in Case (ii), and may coincide with in the first sub-case of Case (iii). In both those situations, we still get a -length rainbow path between the end points without using the middle edge indicated above. We have exhausted all the cases and hence is a rainbow colouring of . ∎
Since Problem P1 is known to be NP-hard, so is Problem P2. Further, it is easy to see that the problem P2 is in NP. Hence the following corollary.
Deciding whether remains NP-complete even when is restricted to be in the class of split graphs.
The reduction used in the proof of Theorem 4 can be extended to show that for every , it is NP-complete to decide whether a chordal graph can be rainbow coloured using colours.
For any integer , the first problem below (P1) is polynomial-time reducible to the second (P2).
Given a -uniform hypergraph , decide whether .
Given a chordal graph , decide whether .
In particular, for every integer , the problem of deciding whether remains NP-complete even when is restricted to be in the class of chordal graphs.
Let be the disjoint union of and a complete -uniform hypergraph on vertices (). This ensures that (Observation 3) and that iff . Let and be the vertex set and edge set, respectively, of . Let be fixed. We construct a graph from as follows (See Figure 3).
The graph thus constructed is easily seen to be a chordal graph with diameter . It is clear that can be constructed from in polynomial-time. We complete the proof by showing that iff .
It is easy to see that when , the graph constructed as above is the same as the split graph constructed in the proof of Theorem 4. In that proof we showed a rainbow colouring of using colours in the case when . The same colouring can be extended to by giving new colours exclusively to the edges . Since the original -colouring made rainbow connected, it is easy to see that this colouring makes rainbow connected. Hence it is enough to show that if , then .
Since , it suffices to show that can be properly -coloured. Let be a rainbow colouring of . Since the subgraph of induced on is a tree with edges, it is easy to see that in any rainbow colouring of the edges of get distinct colours. Without loss of generality we rename the colours so that . Hence the edges in the path from to get colours from . Define a colouring by for each . We claim that is a proper colouring of . For the sake of contradiction, suppose that one of the hyper-edges of is monochromatic under , i.e, all the vertices in get the same colour for some . This happens only when . If is or , all the paths of length two from to in will use the colour and hence there is no (-length) rainbow path from to . If is , then too, all the paths of length two from to in will use one of the colours already used in the unique path from to and hence there is no (-length) rainbow path from to .
Since Problem P1 is known to be NP-hard, so is Problem P2. Further, it is easy to see that the problem P2 is in NP. Hence the result. ∎
In the wake of Corollary 5, it is unlikely that there exists a polynomial-time algorithm to optimally rainbow colour split graphs in general. In Section 3, we show that the problem is efficiently solvable when restricted to threshold graphs, which are a subclass of split graphs. Before that, we describe a linear-time (approximation) algorithm which rainbow colours any split graph using at most one colour more than the optimum (Theorem 7). First we note that it is easy to find a maximum clique in a split graph, as follows.
The vertices of a graph can be sorted according to their degrees in time using a counting sort . If is a split graph with the vertices labelled so that , where is degree of vertex , then is a maximum clique in and is a maximum independent set in . Hence we can assume, if needed, that a maximum clique or a maximum independent set or an ordering of the vertices according to their degrees is given as input to our algorithms.
If is a clique, then and Algorithm 1 colours every edge of with colour . This is an optimal rainbow colouring for . Hence we can assume that is not a clique in the following discussions. So . It is easy to check, by considering all pairs of non-adjacent vertices, that Algorithm 1 indeed produces a rainbow colouring of . For example, between two vertices , we get a rainbow path . It is also evident that the algorithm uses at most colours. By Observation 1 and Observation 2, . Hence the rainbow colouring produced by Algorithm 1 uses at most colours.
Further, the algorithm visits each edge exactly once and hence the time-complexity is . ∎
For every connected split graph with pendant vertices and diameter ,
3 Threshold Graphs: Characterisation and Exact Algorithm
Threshold graphs form a subclass of split graphs (Observation 9b). The neighbourhoods of vertices in a maximum independent set of a threshold graph form a linear order under set inclusion (Observation 9c). We exploit this structure to give a full characterisation of rainbow connection number of threshold graphs based on degree sequences (Corollary 14). We use this characterisation to design a linear-time algorithm to optimally rainbow colour any threshold graph (Algorithm 4).
The following observations are easy to make from the definition of a threshold graph (Definition 3).
Let be a threshold graph with a weight function . Let the vertices be labelled so that . Then
, where is the degree of vertex .
is a maximum independent set and is a clique in . In particular, every threshold graph is a split graph.
, for every . Thus the neighbourhoods of vertices in form a linear order under set inclusion. Further, if is connected, then every vertex in is adjacent to .
A binary codeword is a finite string over the alphabet (bits). The length of a codeword , denoted by , is the number of bits in the string . We denote the -th bit of by . A codeword is said to be a prefix of a codeword if and for all . A binary code is a set of binary codewords. A binary code is called prefix-free if no codeword in is a prefix of another codeword in .
The Kraft’s Inequality  gives a necessary and sufficient condition for the existence of a prefix-free code for a given set of codeword lengths.
Theorem 10 (Kraft 1949 ).
For every prefix-free binary code ,
where , and conversely, for any sequence of lengths satisfying the above inequality, there exists a prefix-free binary code , with .
Given any sequence of lengths satisfying the Kraft Inequality, we can construct a prefix-free binary code , with in time . Further, we can ensure that every bit in is .
A binary tree is a rooted tree in which every node has at most two child nodes. A node with only one child node is said to be unsaturated. The level of a node is its distance from the root. We assume that every edge from a parent to its first (second) child, if it exists, is labelled (). We can represent a prefix-free binary code by a binary tree such that (i) every codeword corresponds to a leaf of the binary tree at level and (ii) the labels on the unique path from the root to a leaf will be the codeword associated with that leaf . We construct a prefix-free binary code with the given length sequence by constructing the corresponding binary tree as explained below.
Create the root, and for every new node created, create its first child till we hit a node at depth for the first time. Declare as a leaf. Once we have created a leaf , , we proceed to create the next leaf as follows. Backtrack from along the tree created so far towards the root till we hit the first unsaturated node. Create its second child. If the second child is at level , then declare it as the leaf . Else, recursively create first child till we create a node at level and declare it as leaf . Terminate this process once we create the leaf .
The process will continue till we create all the leaves. Otherwise, it has to be the case that every internal node in the tree got saturated by the time we created some leaf , . If we have a binary tree with every internal node saturated, it is easy to see by an inductive argument that , where is the set of leaves of and denotes the level of leaf . Hence , contradicting the hypothesis that the lengths satisfy the Kraft Inequality.
It follows from the construction that every bit of is . Since every edge in the tree constructed corresponds to a bit in at least one of the codewords returned, the total number of edges in the tree constructed is at most . Since each edge of the tree is traversed at most twice, the construction will be completed in time . ∎
Now we give a necessary and sufficient condition for -rainbow-colourability of a threshold graph.
First we show that if , then the inequality is satisfied. Let be a rainbow colouring of . We can associate a codeword with each vertex by reading the colours assigned by to edges . Since every pair are non-adjacent, they need a -length rainbow path between them through a common neighbour (Observation 9c). This ensures that the codewords corresponding to and are complementary in at least one bit position. Hence the binary code formed by codewords corresponding to all the vertices in form a prefix-free code. Hence the inequality is satisfied (by Theorem 10).
Conversely, if the inequality is satisfied, then Algorithm 2 gives a colouring of using at most colours. We show that is indeed a rainbow colouring of . Consider any two non-adjacent vertices . Since they are non-adjacent, either both of them are in or otherwise is in and is from the clique such that (Since ). In the former case, and there exists a such that since is not a prefix of (They both belong to a prefix-free code ). Hence is a rainbow path. Similarly in the latter case, and there exists a such that since is not a prefix of . Hence and