Recognizing Partial Cubes in Quadratic Time David Eppstein 1
Total Page:16
File Type:pdf, Size:1020Kb
Journal of Graph Algorithms and Applications http://jgaa.info/ vol. 15, no. 2, pp. 269{293 (2011) Recognizing Partial Cubes in Quadratic Time David Eppstein 1 1Computer Science Department, University of California, Irvine Abstract We show how to test whether a graph with n vertices and m edges is a partial cube, and if so how to find a distance-preserving embedding of the graph into a hypercube, in the near-optimal time bound O(n2), improving previous O(nm)-time solutions. Submitted: Reviewed: Accepted: Final: Published: February 2011 May 2011 May 2011 May 2011 July 2011 Article type: Communicated by: Regular paper G. Liotta E-mail address: [email protected] (David Eppstein) 270 Eppstein Recognizing Partial Cubes in Quadratic Time 1 Introduction A partial cube is an undirected and unweighted graph that admits a simple distance-labeling scheme: one can label its vertices by bitvectors in such a way that the distance between any two vertices equals the Hamming distance be- tween the corresponding labels (Figure 1). That is, the graph can be isometri- cally embedded into a hypercube. Graham and Pollak [26] were the first to discuss partial cubes, for an appli- cation involving communication networks. Since then, these graphs have been shown to model a large variety of mathematical systems: • In computational geometry, the adjacencies between the cells in any hyper- plane arrangements (represented as a graph with a vertex per cell and an edge between any two cells that share a facet) forms a partial cube [21,35]. As a second geometric example, the flip graphs of triangulations of certain point sets also form partial cubes, a fact that can be used to compute flip distance efficiently for these triangulations [19]. • In order theory, the family of total orders over a finite set (with adjacency defined by transpositions), the family of linear extensions of a finite par- tially ordered set (again with adjacency defined by transpositions), the family of partial orders of a finite set (with adjacency defined by inclu- sion or removal of an order relation between a single pair of items), and the family of strict weak orders on a finite set (with adjacency defined by inclusion or removal of a separation of the items into two subsets, one of which is less than the other in the weak order) all form partial cubes [21]. For instance, the permutohedron shown in Figure 1 can be interpreted as the graph of total orders of a four-element set. • In the combinatorial study of human learning, antimatroids (called in this context \learning spaces") form a standard model of the sets of concepts that a student could feasibly have learned: they are defined by the axioms that such a set may be learned a single concept at a time, and that the union of two feasible sets is another feasible set. In this context, the state space of a learner (a graph with a vertex for each feasible set and an edge connecting any two sets that differ in a single concept) forms a partial cube [13, 21]. • In organic chemistry, the carbon backbones of certain benzenoid molecules form partial cubes [36], and partial cube labelings of these graphs can be applied in the calculation of their Wiener indices [31]. Partial cubes admit more efficient algorithms than arbitrary graphs for sev- eral important problems including unweighted all-pairs shortest paths [20], and are the basis for several graph drawing algorithms [14, 16, 18, 22]. JGAA, 15(2) 269{293 (2011) 271 111111 111110 011111 011110 110111 111100 001111 011010 110101 100111 000111 110100 001011 111000 011000 001010 100101 110000 000011 001000 100001 100000 000001 000000 Figure 1: A partial cube, with labeled vertices. The distance between any pair of vertices equals the Hamming distance between the corresponding labels, a defining property of partial cubes. 1.1 New Results In this paper we study the problem of recognizing partial cubes and assigning labels to their vertices. We show that both problems can be solved in time O(n2), where n is the number of vertices in the input graph. Our algorithm has two phases: • In the first phase, we assign bitvector labels to each vertex. It would be straightforward, based on previously known characterizations of partial cubes, to assign a single coordinate of each of these labels by perform- ing a single breadth-first search of the graph; however, the labels may require as many as n − 1 coordinates, and performing n − 1 breadth-first searches would be too slow. To speed this approach up, we use the bit-level parallelism inherent in computer arithmetic to assign multiple coordinate values in a single breadth-first pass over the graph. This part of our al- gorithm depends on a RAM model of computation in which integers of at least log n bits may be stored in a single machine word, and in which addition, bitwise Boolean operations, comparisons, and table lookups can be performed on log n-bit integers in constant time per operation. The constant-time assumption is standard in the analysis of algorithms, and any machine model that is capable of storing an address large enough to address the input to our problem necessarily has machine words with at least log n bits. 272 Eppstein Recognizing Partial Cubes in Quadratic Time • In the second phase, we verify that the labeling we have constructed is indeed distance-preserving. The labels produced in the first phase can be guaranteed to have a Hamming distance that is either equal to the graph distance, or an underestimate of the graph distance; therefore, in order to verify that the labeling is distance-preserving, it suffices to construct paths between each pair of vertices that are as short as the Hamming distance between their labels. To find these paths, we modify an algorithm from previous work with the author and Falmagne [20] that computes all pairs shortest paths in unweighted partial cubes. The modified algorithm either produces paths that are as short as the Hamming distance for each pair of vertices, verifying that the distance labeling is correct, or it detects an inconsistency and reports that the input graph is not a partial cube. Our running time, O(n2), is in some sense close to optimal, as the output of the algorithm, a partial cube labeling of the input graph, may consist of Ω(n2) bits. For instance, labeling a tree as a partial cube requires n − 1 bits per label. However, in our computational model, such a labeling may be represented in O(n2= log n) words of storage, so the trivial lower bound on the runtime of our checking algorithm is Ω(n2= log n). Additionally, in the case of partial cubes that have labelings with few bits per label, or other forms of output than an explicit bitvector labeling of the vertices, even faster runtimes are not ruled out. We leave any further improvements to the running time of partial cube recognition as an open problem. 1.2 Related Work Partial Cube Recognition. Since the time they were first studied, it has been of interest to recognize and label partial cubes. Djokovic [12] and Win- kler [38] provided mathematical characterizations of partial cubes in terms of certain equivalence relations on the edges; their results can also be used to de- scribe the bitvector labeling of the vertices of a partial cube, and to show that it is essentially unique when it exists. As Imrich and Klavˇzar[29] and Aurenham- mer and Hagauer [2] showed, these characterizations can be translated directly into algorithms for recognizing partial graphs in time O(mn), where m and n are respectively the number of edges and vertices in the given graph.1 Since then there has been no improvement to the O(mn) time bound for this problem until our work. Special Subclasses of Partial Cubes. Several important families of graphs are subclasses of the partial cubes, and can be recognized more quickly than arbitrary partial cubes: • Every tree is a partial cube [34], and obviously trees can be recognized in linear time. 1 As we discuss later, for partial cubes, m ≤ n log2 n; the time bound claimed in the title of Aurenhammer and Hagauer's paper is O(n2 log n), which is therefore slower than O(mn), but it is not hard to see that their algorithm actually takes time O(mn). JGAA, 15(2) 269{293 (2011) 273 • Squaregraphs are the planar graphs that can be drawn in the plane in such a way that every bounded face has four sides and every vertex with degree less than four belongs to the unbounded face. Every squaregraph is a partial cube, and squaregraphs may be recognized in linear time [4]. • A median graph is a graph in which, for every three vertices, there is a unique median vertex that belongs to shortest paths between each pair of the three vertices [3,9,33]. The graphs of distributive lattices are median graphs [9]; median graphs also arise from the solution sets of 2-satisfiability problems [24] and the reconstruction of phylogenetic trees [6,11]. Based on earlier work by Hagauer et al. [27], Imrich et al. [30] showed that the times for median graph recognition and for triangle-free graph recognition are within polylogarithmic factors of each other. Applying the best known algorithm for triangle detection, based on fast matrix multiplication [1] yields a time bound of O(n1:41) for median graph recognition. • Breˇsaret al. [10] discuss several other classes of partial cubes that are closely related to the median graphs and may be recognized in O(m log n) time.