Lecture Notes in Computer Science Commenced Publication in 1973 Founding and Former Series Editors: Gerhard Goos, Juris...

This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!

Lecture Notes in Computer Science Commenced Publication in 1973 Founding and Former Series Editors: Gerhard Goos, Juris Hartmanis, and Jan van Leeuwen

Editorial Board David Hutchison Lancaster University, UK Takeo Kanade Carnegie Mellon University, Pittsburgh, PA, USA Josef Kittler University of Surrey, Guildford, UK Jon M. Kleinberg Cornell University, Ithaca, NY, USA Alfred Kobsa University of California, Irvine, CA, USA Friedemann Mattern ETH Zurich, Switzerland John C. Mitchell Stanford University, CA, USA Moni Naor Weizmann Institute of Science, Rehovot, Israel Oscar Nierstrasz University of Bern, Switzerland C. Pandu Rangan Indian Institute of Technology, Madras, India Bernhard Steffen TU Dortmund University, Germany Madhu Sudan Microsoft Research, Cambridge, MA, USA Demetri Terzopoulos University of California, Los Angeles, CA, USA Doug Tygar University of California, Berkeley, CA, USA Gerhard Weikum Max Planck Institute for Informatics, Saarbruecken, Germany

7056

Costas S. Iliopoulos William F. Smyth (Eds.)

Combinatorial Algorithms 22nd International Workshop, IWOCA 2011 Vancouver, BC, Canada, July 20-22, 2011 Revised Selected Papers

13

Volume Editors Costas S. Iliopoulos King’s College London Department of Informatics Strand, London WC2R 2LS, UK E-mail: [email protected] and Curtin University Digital Ecosystems and Business Intelligence Institute Perth WA 6845, Australia William F. Smyth McMaster University Department of Computing and Software Hamilton, ON L8S 4K1, Canada E-mail: [email protected] and Curtin University Digital Ecosystems and Business Intelligence Institute Perth WA 6845, Australia

ISSN 0302-9743 e-ISSN 1611-3349 ISBN 978-3-642-25010-1 e-ISBN 978-3-642-25011-8 DOI 10.1007/978-3-642-25011-8 Springer Heidelberg Dordrecht London New York Library of Congress Control Number: 2011939494 CR Subject Classiﬁcation (1998): G.2.1, G.2.2, I.1, I.3.5, F.2, E.1, E.4, H.1 LNCS Sublibrary: SL 1 – Theoretical Computer Science and General Issues

© Springer-Verlag Berlin Heidelberg 2011 This work is subject to copyright. All rights are reserved, whether the whole or part of the material is concerned, speciﬁcally the rights of translation, reprinting, re-use of illustrations, recitation, broadcasting, reproduction on microﬁlms or in any other way, and storage in data banks. Duplication of this publication or parts thereof is permitted only under the provisions of the German Copyright Law of September 9, 1965, in its current version, and permission for use must always be obtained from Springer. Violations are liable to prosecution under the German Copyright Law. The use of general descriptive names, registered names, trademarks, etc. in this publication does not imply, even in the absence of a speciﬁc statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use. Typesetting: Camera-ready by author, data conversion by Scientiﬁc Publishing Services, Chennai, India Printed on acid-free paper Springer is part of Springer Science+Business Media (www.springer.com)

Preface

This volume contains the papers presented at IWOCA 11: the 22nd International Workshop on Combinatorial Algorithms The 22nd IWOCA was held July 20–22, 2011 on the green and spacious campus of the University of Victoria (UVic), itself located on green and spacious Vancouver Island, oﬀ the coast of British Columbia, a few scenic kilometers by ferry from the city of Vancouver. The meeting was sponsored and supported ﬁnancially by the Paciﬁc Institute for the Mathematical Sciences (PIMS); hosted by the UVic Department of Computer Science. The Local Arrangements Committee, cochaired by Wendy Myrvold and Venkatesh Srinivasan, did an outstanding job; the Program Committee was cochaired by Costas Iliopoulos and Bill Smyth; the intricacies of EasyChair were handled by German Tischler. IWOCA descends from the original Australasian Workshop on Combinatorial Algorithms, ﬁrst held in 1989, then renamed “International” in 2007 in response to consistent interest and support from researchers outside the Australasian region. The workshop’s permanent website can be accessed at iwoca.org, where links to previous meetings, as well as to IWOCA 2011, can be found. The IWOCA 2011 call for papers was distributed around the world, resulting in 71 submitted papers. The EasyChair system was used to facilitate management of submissions and refereeing, with three referees selected from the 40member Program Committee assigned to each paper. A total of 30 papers were accepted, subject to revision, for presentation at the workshop. The workshop also featured a problem session, chaired — in the absence of IWOCA Problems Cochairs Yuqing Lin and Zsuzsanna Liptak — by UVic graduate student Alejandro Erickson. Four invited talks were given by Tetsuo Asano on “Nearest Larger Neighbors Problem and Memory-Constrained Algorithms,” Pavol Hell on “Graph Partitions,” J. Ian Munro on “Creating a Partial Order and Finishing the Sort, with Graph Entropy” and Cenk Sahinalp on “Algorithmic Methods for Structural Variation Detection Among Multiple High-Throughput Sequenced Genomes.” The 51 registered participants at IWOCA 2011 hold appointments at institutions in 15 diﬀerent countries on four continents (Asia, Australia, Europe, North America). The nations represented were: Australia (2), Canada (28), China (1), Czech Republic (2), Denmark (1), France (1), Germany (3), India (2), Israel (1), Iran (1), Italy (1), Japan (1), Russia (1), Taiwan (1), USA (5). Atypical for IWOCA, the contributed talks were split into concurrent streams, A (Combinatorics) and B (Graph Theory). This strategy allowed 30-minute talks and so encouraged a relaxed atmosphere; still, one was often forced to choose between two attractive alternatives. Stream A included such topic areas as combinatorics on words, string algorithms, codes, Venn diagrams, set partitions;

VI

Preface

Stream B dealt with several graph theory areas of current interest: Hamiltonian & Eulerian properties, graph drawing, coloring, dominating sets, spanning trees, and others. We wish to thank the authors for their contributions: the quality of their papers made IWOCA exceptional this year. We would also like to thank the referees for their thorough, constructive and helpful comments and suggestions on the manuscripts. August 2011

Costas S. Iliopoulos Bill F. Smyth

Organization

Program Committee Faisal Abu-Khzam Amihood Amir Subramanian Arumugam Hideo Bannai Ljiljana Brankovic Gerth Stølting Brodal Charles Colbourn Maxime Crochemore Diane Donovan Alan Frieze Dalibor Froncek Roberto Grossi Sylvie Hamel Jan Holub Seok-Hee Hong Costas Iliopoulos Ralf Klasing Rao Kosaraju Marcin Kubica Anna Lubiw Mirka Miller Laurent Mouchard Ian Munro Wendy Myrvold Kunsoo Park Simon Puglisi Rajeev Raman Frank Ruskey Jeﬀrey Shallit Michiel Smid Bill Smyth Iain Stewart Gabor Tardos German Tischler

Lebanese American University, Lebanon Bar-Ilan University and Johns Hopkins University, Israel/USA Kalasalingam University, India Kyushu University, Japan University of Newcastle, UK Aarhus University, Dem Arizona State University, USA King’s College London, UK and Universit´e Paris-Est, France University of Queensland, Australia Carnegie Mellon University, USA University of Minnesota Duluth, USA Universit` a di Pisa, Italy University of Montreal, Canada Czech Technical University in Prague, Czech Republic University of Sydney, Australia King’s College London, UK LaBRI - CNRS, France Johns Hopkins University, USA Warsaw University, Poland University of Waterloo, Canada University of Newcastle, UK University of Rouen, France University of Waterloo, Canada University of Victoria, Canada Seoul National University, Korea Royal Melbourne Institute of Technology, Australia University of Leicester, UK University of Victoria, Canada University of Waterloo, Canada Carleton University, Canada McMaster University, Canada Durham University, UK Simon Fraser University, Canada King’s College London, UK

VIII

Organization

Alexander Tiskin Eli Upfal Lynette Van Zijl Koichi Wada Sue Whitesides Christos Zaroliagis

University of Warwick, UK Brown University, USA Stellenbosch University, South Africa Nagoya Institute of Technology, Japan University of Victoria, Canada CTI University of Patras, Greece

Additional Reviewers Barbay, J´er´emy Battaglia, Giovanni Beveridge, Andrew Blin, Guillaume Boeckenhauer, Hans-Joachim Broersma, Hajo Cadilhac, Micha¨el Chauve, Cedric Cooper, Colin Cordasco, Gennaro Erickson, Alejandro Erlebach, Thomas Fotakis, Dimitris Foucaud, Florent Franceschini, Gianni Frieze, Alan Golovach, Petr Greene, John Gupta, Anupam Hahn, Gena Hoﬀmann, Michael Huang, Jing Izumi, Taisuke Izumi, Tomoko Kalvoda, Tomas Katayama, Yoshiaki Klouda, Karel Kontogiannis, Spyros Korf, Richard Kyncl, Jan

Langiu, Alessio Loh, Po-Shen Macgillivray, Gary Mamakani, Khalegh Marshall, Kim Martin, Barnaby Mcfarland, Robert Merlini, Donatella Mertzios, George B. Moemke, Tobias Ono, Hirotaka Phanalasy, Oudone Pineda-Villavicencio, Guillermo Pissis, Solon Prencipe, Giuseppe Puglisi, Simon Radoszewski, Jakub Radzik, Tomasz Razgon, Igor Rylands, Leanne Sau, Ignasi Steinhofel, Kathleen Teska, Jakub Theodoridis, Evangelos Tsichlas, Kostas Vandin, Fabio Vialette, St´ephane Wallis, Wal Yamashita, Yasushi Yuster, Raphael

Table of Contents

Weighted Improper Colouring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Julio Araujo, Jean-Claude Bermond, Fr´ed´eric Giroire, Fr´ed´eric Havet, Dorian Mazauric, and Remigiusz Modrzejewski

1

Algorithmic Aspects of Dominator Colorings in Graphs . . . . . . . . . . . . . . . S. Arumugam, K. Raja Chandrasekar, Neeldhara Misra, Geevarghese Philip, and Saket Saurabh

19

Parameterized Longest Previous Factor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Richard Beal and Donald Adjeroh

31

p-Suﬃx Sorting as Arithmetic Coding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Richard Beal and Donald Adjeroh

44

Periods in Partial Words: An Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . Francine Blanchet-Sadri, Travis Mandel, and Gautam Sisodia

57

The 1-Neighbour Knapsack Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Glencora Borradaile, Brent Heeringa, and Gordon Wilfong

71

A Golden Ratio Parameterized Algorithm for Cluster Editing . . . . . . . . . . Sebastian B¨ ocker

85

Stable Sets of Threshold-Based Cascades on the Erd˝os-R´enyi Random Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ching-Lueh Chang and Yuh-Dauh Lyuu

96

How Not to Characterize Planar-Emulable Graphs . . . . . . . . . . . . . . . . . . . Markus Chimani, Martin Derka, Petr Hlinˇen´y, and Matˇej Klus´ aˇcek

106

Testing Monotone Read-Once Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . Dmitry V. Chistikov

121

Complexity of Cycle Transverse Matching Problems . . . . . . . . . . . . . . . . . . Ross Churchley, Jing Huang, and Xuding Zhu

135

Eﬃcient Conditional Expectation Algorithms for Constructing Hash Families . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Charles J. Colbourn

144

2-Layer Right Angle Crossing Drawings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Emilio Di Giacomo, Walter Didimo, Peter Eades, and Giuseppe Liotta

156

X

Table of Contents

Hamiltonian Orthogeodesic Alternating Paths . . . . . . . . . . . . . . . . . . . . . . . Emilio Di Giacomo, Luca Grilli, Marcus Krug, Giuseppe Liotta, and Ignaz Rutter

170

Ranking and Loopless Generation of k-ary Dyck Words in Cool-lex Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stephane Durocher, Pak Ching Li, Debajyoti Mondal, and Aaron Williams

182

Two Constant-Factor-Optimal Realizations of Adaptive Heapsort . . . . . . Stefan Edelkamp, Amr Elmasry, and Jyrki Katajainen

195

A Unifying Property for Distribution-Sensitive Priority Queues . . . . . . . . Amr Elmasry, Arash Farzan, and John Iacono

209

Enumerating Tatami Mat Arrangements of Square Grids . . . . . . . . . . . . . . Alejandro Erickson and Mark Schurch

223

Quasi-Cyclic Codes over F13 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . T. Aaron Gulliver

236

Acyclic Colorings of Graph Subdivisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . Debajyoti Mondal, Rahnuma Islam Nishat, Sue Whitesides, and Md. Saidur Rahman

247

Kinetic Euclidean Minimum Spanning Tree in the Plane . . . . . . . . . . . . . . Zahed Rahmati and Alireza Zarei

261

Generating All Simple Convexly-Drawable Polar Symmetric 6-Venn Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Khalegh Mamakani, Wendy Myrvold, and Frank Ruskey

275

The Rand and Block Distances of Pairs of Set Partitions . . . . . . . . . . . . . . Frank Ruskey and Jennifer Woodcock

287

On Minimizing the Number of Label Transitions around a Vertex of a Planar Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ˇ Bojan Mohar and Petr Skoda

300

A New View on Rural Postman Based on Eulerian Extension and Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Manuel Sorge, Ren´e van Bevern, Rolf Niedermeier, and Mathias Weller

310

Hamilton Cycles in Restricted Rotator Graphs . . . . . . . . . . . . . . . . . . . . . . . Brett Stevens and Aaron Williams

324

Eﬃcient Codon Optimization with Motif Engineering . . . . . . . . . . . . . . . . . Anne Condon and Chris Thachuk

337

Table of Contents

XI

An Algorithm for Road Coloring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A.N. Trahtman

349

Complexity of the Cop and Robber Guarding Game . . . . . . . . . . . . . . . . . . ˇamal, Rudolf Stolaˇr, and Tomas Valla Robert S´

361

Improved Steiner Tree Algorithms for Bounded Treewidth . . . . . . . . . . . . . Markus Chimani, Petra Mutzel, and Bernd Zey

374

Author Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

387

Weighted Improper Colouring Julio Araujo1,2 , Jean-Claude Bermond1, Fr´ed´eric Giroire1 , Fr´ed´eric Havet1 , Dorian Mazauric1 , and Remigiusz Modrzejewski1 2

1 Mascotte, joint project I3S(CNRS/Univ. de Nice)/INRIA, France ParGO Research Group - Universidade Federal do Cear´a - UFC, Brazil

Abstract. In this paper, we study a colouring problem motivated by a practical frequency assignment problem and up to our best knowledge new. In wireless networks, a node interferes with the other nodes the level of interference depending on numerous parameters: distance between the nodes, geographical topography, obstacles, etc. We model this with a weighted graph G where the weights on the edges represent the noise (interference) between the two endnodes. The total interference in a node is then the sum of all the noises of the nodes emitting on the same frequency. A weighted t-improper k-colouring of G is a k-colouring of the nodes of G (assignment of k frequencies) such that the interference at each node does not exceed some threshold t. The Weighted Improper Colouring problem, that we consider here consists in determining the weighted t-improper chromatic number defined as the minimum integer k such that G admits a weighted t-improper k-colouring. We also consider the dual problem, denoted the Threshold Improper Colouring problem, where given a number k of colours (frequencies) we want to determine the minimum real t such that G admits a weighted t-improper k-colouring. We show that both problems are NP-hard and first present general upper bounds; in particular we show a generalisation of Lov´asz’s Theorem for the weighted t-improper chromatic number. We then show how to transform an instance of the Threshold Improper Colouring problem into another equivalent one where the weights are either 1 or M, for a sufficient big value M. Motivated by the original application, we study a special interference model on various grids (square, triangular, hexagonal) where a node produces a noise of intensity 1 for its neighbours and a noise of intensity 1/2 for the nodes that are at distance 2. Consequently, the problem consists of determining the weighted t-improper chromatic number when G is the square of a grid and the weights of the edges are 1, if their end nodes are adjacent in the grid, and 1/2 otherwise. Finally, we model the problem using linear integer programming, propose and test heuristic and exact Branch-and-Bound algorithms on random cell-like graphs, namely the Poisson-Voronoi tessellations.

1 Introduction Let G = (V, E) be a graph. A k-colouring of G is a function c : V → {1, . . . , k}. The colouring c is proper if uv ∈ E implies c(u) = c(v). The chromatic number of G, denoted by χ(G), is the minimum integer k such that G admits a proper k-colouring. The goal

This work was partially supported by r´egion PACA, ANR Blanc AGAPE and ANR International Taiwan GRATEL.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 1–18, 2011. c Springer-Verlag Berlin Heidelberg 2011

2

J. Araujo et al.

of the V ERTEX C OLOURING problem is to determine χ(G) for a given graph G. It is a well-known NP-hard problem [11]. A k-colouring c is l-improper if |{v ∈ N(u) | c(v) = c(u)}| ≤ l for all u ∈ V . Given a non-negative integer l, the l-improper chromatic number of a graph G, denoted by χl (G), is the minimum integer k such that G has an l-improper k-colouring. For given graph G and integer l, the I MPROPER C OLOURING problem consists in determining χl (G) [14, 6] and is also NP-hard. Indeed, if l = 0, observe that χ0 (G) = χ(G). Consequently, V ERTEX C OLOURING is a particular case of I MPROPER C OLOURING. In this work we define and study a new variation of the improper colouring problem for edge-weighted graphs. Given an edge-weighted graph G = (V, E, w), w : E → R∗+ , a threshold t ∈ R+ , and a colouring c, we note the interference of a vertex w in this colouring as: Iu (G, w, c) =

∑

w(u, v).

{v∈N(u)|c(v)=c(u)}

We say that c is a weighted t-improper k-colouring of G if c is a k-colouring of G such that Iu (G, w, c) ≤ t, for all u ∈ V . Given a threshold t ∈ R∗+ , the minimum integer k such that the graph G admits a weighted t-improper k-colouring is the weighted t-improper chromatic number of G, denoted by χt (G, w). Given an edge-weighted graph G = (V, E, w) and a threshold t ∈ R∗+ , determining χt (G, w) is the goal of the W EIGHTED I MPROPER C OLOUR ING problem. Note that if t = 0 then χ0 (G, w) = χ(G), and if w(e) = 1 for all e ∈ E, then χl (G, w) = χl (G) for any positive integer l. Therefore, the W EIGHTED I MPROPER C OLOURING problem is clearly NP-hard since it generalises V ERTEX C OLOURING and I MPROPER C OLOURING . On the other hand, we define the minimum k-threshold of G, denoted by ωk (G, w) as the minimum real t such that G admits a weighted t-improper k-colouring. Then, for a given edge-weighted graph G = (V, E, w) and a positive integer k, the T HRESHOLD I MPROPER C OLOURING problem consists of determining ωk (G, w). Motivation. Our initial motivation to these problems was the design of satellite antennas for multi-spot MFTDMA satellites [2]. In this technology, satellites transmit signals to areas on the ground called spots. These spots form a grid-like structure which is modelled by an hexagonal cell graph. To each spot is assigned a radio channel or colour. Spots are interfering with other spots having the same channel and a spot can use a colour only if the interference level does not exceed a given threshold t. The level of interference between two spots depends on their distance. The authors of [2] introduced a factor of mitigation γ and the interferences of remote spots are reduced by a factor 1 − γ. When the interference level is too low, the nodes are considered to not interfere anymore. Considering such types of interferences, where nodes at distance at most i interfere, leads to the study of the i-th power of the graph modelling the network and a case of special interest is the power of grid graphs (see Section 3). Related Work. Our problems are particular cases of the FREQUENCY A SSIGNMENT P ROBLEM (FAP). FAP has several variations that were already studied in the literature (see [1] for a survey). In most of these variations, the main constraint to be satisfied is that if two vertices (mobile phones, antennas, spots, etc.) are close, then the difference

Weighted Improper Colouring

3

between the frequencies that are assigned to them must be greater than some function that usually depends on their distance. There is a strong relationship between most of these variations and the L(p1 , . . . , pd )LABELLING PROBLEM [15]. In this problem, the goal is to find a colouring of the vertices of a given graph G in such a way that the difference between the colours assigned to vertices at distance i must be at least pi , for every i = 1, . . . , d. For some other variations, for each non-satisfied interference constraint a penalty must be paid. In particular, the goal of the M INIMUM I NTERFERENCE A SSIGNMENT P ROBLEM (MI-FAP) is to minimise the total penalties that must be paid, when the number of frequencies to be assigned is given. This problem can also be studied for only co-channel interferences, in which the penalties are applied only if the two vertices have the same frequency. However, MI-FAP under these constraints does not correspond to W EIGHTED I MPROPER C OLOURING, because we consider the co-channel interference, i.e. penalties, just between each vertex and its neighbourhood. The two closest related works we found in the literature are [13] and [7]. However, they both apply penalties over co-channel interference, but also to the adjacent channel interference, i.e. when the colours of adjacent vertices differ by one unit. Moreover, their results are not similar to ours. In [13], they propose an enumerative algorithm for the problem, while in [7] a Branch-and-Cut method is proposed and applied over some instances. Results In this article, we study both parameters χt (G, w) and ωk (G, w). We first show that T HRESHOLD I MPROPER COLOURING is NP-hard. Then we present general upper bounds; in particular we show a generalisation of Lov´asz’ Theorem for χt (G, w). We then show how to transform an instance into an equivalent one where the weights are either 1 or M, for a sufficient big value M. Motivated by the original application, we study a special interference model on various grids (square, triangular, hexagonal) where a node produces a noise of intensity 1 for its neighbours and a noise of intensity 1/2 for the nodes that are at distance 2. Consequently, the problem consists of determining χt (G, w) and ωk (G, w), when G is the square of a grid and the weights of the edges are 1, if their end nodes are adjacent in the grid, and 1/2 otherwise. Finally, we propose a heuristic and a Branch-and-Bound algorithm to solve the T HRESHOLD I MPROPER COLOURING for general graphs. We compare them to an integer programming formulation on random cell-like graphs, namely Voronoi diagrams of

Fig. 1. Construction of G(I,t) from an instance (I,t) of the PARTITION P ROBLEM

4

J. Araujo et al.

random points of the plan. These graphs are classically used in the literature to model telecommunication networks [4, 8, 9].

2 General Results In this section, we present some results for W EIGHTED I MPROPER COLOURING and T HRESHOLD I MPROPER COLOURING for general graphs and general interference models. 2.1 NP-Completeness of T HRESHOLD I MPROPER

COLOURING

In this section, we prove that the decision problem associated to T HRESHOLD I M PROPER COLOURING is NP-complete already for k = 2. Theorem 1. The following problem is NP-complete. Instance: An edge-weighted graph G = (V, E, w), w : E → R∗+ , a threshold t ∈ R+ . Question: Does G have a weighted t-improper 2-colouring? Proof. Given a 2-colouring c of G, one can test in O (|E|)-time if c is weighted t-improper by just checking, for each vertex v, if Iv (G, w, c) ≤ t. Consequently, this problem is in NP. Now we reduce the PARTITION problem [11] which is NP-complete, to it. In the PARTITION problem, given a set of p positive integers I = {i1 , . . . , i p } and a threshold t, we want to decide if there is a partition of the elements of I into two sets A and B such that ∑ia ∈A ia ≤ t and ∑ib ∈B ib ≤ t. We consider that i j ≤ t, for all j ∈ {1, . . . , p}, and that p t ≤ ∑ j=1 i j , otherwise the answer for this problem is trivially no and yes, respectively. Given an instance (I,t) of the PARTITION P ROBLEM, let G(I,t) be a graph whose vertex set is V (G(I,t)) = {v j | j ∈ {1, . . . , p}}∪{a, b} and whose edge set is E(G(I,t)) = p {(a, b)} ∪ {(a, v j ), (b, v j ) | j ∈ {1, . . . , p}} (see Figure 1). Define M = 1 + ∑ j=1 i j . Let w : E(G(I,t)) → {i1 , . . . , i p , M} be a weight function for the edges of G(I,t) defined in the following way: w(a, b) = M and w(a, v j ) = w(b, v j ) = i j , for every j ∈ {1, . . . p}. We claim that (I,t) is a yes answer for the PARTITION P ROBLEM if, and only if, G(I,t) admits a weighted t-improper 2-colouring. If (I,t) is a yes instance, let (A, B) be a partitioning such that ∑ia ∈A ia ≤ t and ∑ib ∈B ib ≤ t. We claim that the following colouring c is a weighted t-improper 2-colouring of G(I,t): 1 i f v ∈ {a} ∪ {v j | i j ∈ A}; c(v) = 2 otherwise. To verify this fact, observe that Ia (G, w, c) = ∑i j ∈A i j ≤ t, that Ib (G, w, c) = ∑i j ∈B i j ≤ t and that Iv j (G, w, c) = i j ≤ t, for each j ∈ {1 . . . , p}. Conversely, consider that G(I,t) admits a weighted t-improper 2-colouring c. Remark that a and b must receive different colours since the weight of the edge (a, b) is M > t. Thus, assume that c(a) = 1 and that c(b) = 2. Let A be the subset of integers i j , j ∈ {1, . . . , p}, such that c(v j ) = 1 and B = I\A = {i j | c(v j ) = 2}. Observe that the sum of elements in A (resp. B) is equal to Ia (G, w, c) (resp. Ib (G, w, c)) and they are both smaller or equal to t, since c is a weighted t-improper 2-colouring.

Weighted Improper Colouring

5

2.2 Bounds Upper Bound for W EIGHTED I MPROPER C OLOURING. It is a folklore result χ(G) ≤ Δ(G) + 1, for any graph G. Lov´asz [12] extended this result for I MPROPER C OLOURING problem. He proved that χl (G) ≤ Δ(G)+1 l+1 . In what follows, we show an extension of these results to W EIGHTED I MPROPER C OLOURING. Given an edge-weighted graph G = (V, E, w), w : E → R∗+ , and v ∈ V , let dw (v) = ∑u∈N(v) w(u, v). Denote by Δ(G, w) = maxv∈V dw (v). Given a k-colouring c : i V → {1, . . . , k} of G, we denote dw,c (v) = ∑{u∈N(v)|c(u)=i} w(u, v), for every vertex v ∈ V c(v)

and colour i = 1, . . . , k. Note that dw,c (v) = Iv (G, w, c). Finally, we denote gcd(w) the greatest common divisor of the weights of w. We use here the generalisation of the gcd to non-integer numbers (e.g. in Q) where a number x is said to divide a number y if the fraction y/x is an integer. The important property of gcd(w) is that the difference between two interferences is a multiple of gcd(w); in particular, if for two vertices v i (v) > d j (u), then d i (v) ≥ d j (u) + gcd(w). and u, dw,c w,c w,c w,c If t is not a multiple of the gcd(w), that is, there exists an integer a ∈ Z such that a gcd(w) < t < (a + 1)gcd(w), then χtw (G) = χwa gcd(w) (G). Theorem 2. Given an edge-weighted graph G = (V, E, w), w : E → Q∗+ , and a threshold t multiple of gcd(w), then the following inequality holds: Δ(G, w) + gcd(w) χt (G, w) ≤ . t + gcd(w) Proof. We say that a k-colouring c of G is well-balanced if c satisfies the following property: j

Property 1. For any vertex v ∈ V , Iv (G, w, c) ≤ dw,c (v), for every j = 1, . . . , k. If k = 1 there is nothing to prove. Then, we prove that for any k ≥ 2, there exists a wellbalanced k-colouring of G. To prove this fact one may just colour G arbitrarily with k colours and then repeat the following procedure: if there exists a vertex v coloured i i (v) > d j (v), then recolour v with colour j. Observe that and a colour j such that dw,c w,c this procedure neither increases (we just move a vertex from one colour to another) nor decreases (a vertex without neighbour on its colour is never moved) the number of colours within this process. Let W be the sum of the weights of the edges having j the same colour in their endpoints. In this transformation, W has increased by dw,c (v) i (v) (edges that previously had colours i and j in their endpoints), but decreased by dw,c (edges that previously had colour i in both of their endpoints). So, W has decreased by j i dw,c (v) − dw,c (v) ≥ gcd(w). As W ≤ |E| maxe∈E w(e) is finite, this procedure finishes and produces a well-balanced k-colouring of G. Observe that in any well-balanced k-colouring c of a graph G, the following holds: dw (v) =

∑

u∈N(v)

c(v)

w(u, v) ≥ kdw,c (v).

(1)

Let k∗ = Δ(G,w)+gcd(w) ≥ 2 and c∗ be a well-balanced k∗ -colouring of G. We claim t+gcd(w) that c∗ is a weighted t-improper k∗ -colouring of G.

6

J. Araujo et al.

By contradiction, suppose that there is a vertex v in G such that c∗ (v) = i and that j is well-balanced, dw,c (v) > t, for all j = 1, . . . , k∗ . By the definition j of gcd(w) and as t is a multiple of gcd(w), it leads to dw,c (v) ≥ t + gcd(w) for all j = 1, . . . , k∗ . Combining this inequality with Inequality (1), we obtain:

i (v) > t. Since c∗ dw,c

Δ(G, w) ≥ dw (v) ≥ k∗ (t + gcd(w)), giving

Δ(G, w) ≥ Δ(G, w) + gcd(w),

a contradiction. The result follows. Note that when all weights are equal to one, we obtain the bound for the improper colouring derived in [12]. u

w’(u,v)=w(u,v)−1

1 Ku

u’

v

1 Kv

v’

Fig. 2. Construction of Gi+1 from Gi using edge (u, v) with k = 4. Dashed edges represent edges with infinite weights.

Brooks [5] proved that for a connected graph G, χ(G) = Δ(G) + 1 if, and only if, G is complete or an odd cycle. One could wonder for which edge-weighted graphs the bound we provide is tight. However, Correa et al. [6] already showed that it is NP-complete to determine if the improper chromatic number of a graph G attains the upper bound of Lov´asz, which is a particular case of W EIGHTED I MPROPER COLOURING and the bound we provided. Upper Bound for T HRESHOLD I MPROPER C OLOURING. Let G = (V, E, w), w : E → R∗+ , be an edge-weighted graph and k be a positive integer. Observe that, for the minimum k-threshold of G, ωk (G, w) ≤ Δ(G, w) ≤

∑

w(e).

e∈E(G)

In what follows, we improve this trivial upper bound. Let V = {u ∈ V, d(u) ≥ k} be the set of vertices with degree at least k. Set G = G − V . Lemma 1. ωk (G, w) = ωk (G , w) Proof. If there is a weighted t-improper k-colouring of G , then it is easy to get a weighted t-improper k-colouring of G choosing, for each vertex u ∈ V \ V , a colour different from the colours of its neighbours. It is always possible because d(u) ≤ k − 1. Conversely, if there is a weighted t-improper k-colouring of G, then there is a weighted t-improper k-colouring of G by choosing, for every v ∈ V , cG (v) = cG (v).

Weighted Improper Colouring

7

For the rest of the section, we only consider edge-weighted graphs with minimum dek−1 gree at least k. For each v ∈ V , let Emin (v) be the set of d(v) − (k − 1) least weighted edges incident to v. Theorem 3. Let G = (V, E, w), w : E → R∗+ , be an edge-weighted graph and k be a positive integer. Then, k−1 ωk (G, w) ≤ max w(Emin (v)), v∈V

where

k−1 (v)) w(Emin

= ∑e∈E k−1 (v) w(e). min

k−1 Proof. Let Gk−1 min = G[E\{ v∈V Emin (v)}]. Observe that the maximum degree of a verk−1 tex in Gk−1 min ≤ k − 1. Consequently, Gmin admits a proper k-colouring c of its vertices. Observe that the maximum interference of a vertex v in G when G is coloured by the k−1 colouring c is at most maxv∈V w(Emin (v)) and the result follows.

2.3 Transformation In this section, we prove that the T HRESHOLD I MPROPER C OLOURING problem can be transformed into a problem mixing proper and improper colouring. More precisely, we prove the following: Theorem 4. Let G0 = (V0 , E0 , w0 ) be an edge-weighted graph such that, for every e ∈ E, w(e) ∈ Z∗+ , and k be a positive integer. We can construct a graph G∗ = (V ∗ , E ∗ , w∗ ) such that w∗ (e) ∈ {1, M} for any e ∈ E(G∗ ), satisfying ωk (G0 , w0 ) = ωk (G∗ , w∗ ), where M = 1 + ∑e∈E(G) w0 (e). Proof. Consider the function f (G, w) = ∑{e∈E(G)|w(e)=M} (w(e) − 1). If f (G, w) = 0, all edges have weight either 1 or M and G has the desired property. In this case, G∗ = G. Otherwise, we construct a graph G and a function w such that ωk (G , w ) = ωk (G, w), but f (G , w ) = f (G, w) − 1. By repeating this operation f (G0 , w0 ) times we get the required graph G∗ . In case f (G, w) > 0, there exists an edge e = (u, v) ∈ E(G) such that 2 ≤ w(e) < M. G is obtained from G by adding two complete graphs on k − 1 vertices K u and K v and two new vertices u and v . We join u and u to all the vertices of K u and v and v to all the vertices of K v . We assign weight M to all these edges. Note that, u and u (v and v ) always have the same colour, namely the remaining colour not used in K u (resp. K v ). We also add two edges uv and u v both of weight 1. The edges of G keep their weight in G , except the edge e = uv whose weight is decreased by one unit, i.e., w (e) = w(e) − 1. Thus, f (G ) = f (G) − 1 as we added only edges of weights 1 and M and we decreased the weight of e by one unit. Now consider a weighted t-improper k-colouring c of G. We produce a weighted timproper k-colouring c to colour G as follows: we keep the colours of all the vertices in G, we assign to u (v ) the same colour as u (resp., v), and we assign to K u (K v ) the k − 1 colours different from the one used in u (resp. v).

8

J. Araujo et al.

Conversely, from any weighted improper k-colouring c of G , we get a weighted improper k-colouring c of G by just keeping the colours of the vertices that belong to G. For such colourings c and c we have that Ix (G, w, c) = Ix (G , w , c ), for any vertex x of G different from u and v. For x ∈ K u ∪ K v , Ix (G , w , c ) = 0. The neighbours of u with the same colour as u in G are the same as in G, except possibly v which has the same colour of u if, and only if, v has the same colour of u. Let ε = 1 if v has the same colour as u, otherwise ε = 0. As the weight of (u, v) decreases by one and we add the edge (u, v ) of weight 1 in G , we get Iu (G , w , c ) = Iu (G, w, c) − ε + w (u, v )ε = Iu (G, w, c). Similarly, Iv (G , w , c ) = Iv (G, w, c). Finally, Iu (G , w , c ) = Iv (G , w , c ) = ε. But Iu (G , w , c ) ≥ (w(u, v) − 1)ε and so Iu (G , w , c ) ≤ Iu (G , w , c ) and Iv (G , w , c ) ≤ Iv (G , w , c ). In summary, we have max Ix (G , w , c ) = max Ix (G, w, c) x

x

and therefore ωk (G, w) = ωk (G , w ). In the worst case, the number of vertices of G∗ is n + m(wmax − 1)2k and the number of edges of G∗ is m + m(wmax − 1)[(k + 4)(k − 1) + 2] with n = |V (G)|, m = |E(G)| and wmax = maxe∈E(G) w(e). In conclusion, this construction allows to transform the T HRESHOLD I MPROPER C OLOURING problem into a problem mixing proper and improper colouring. Therefore the problem consists in finding the minimum l such that a (non-weighted) l-improper k-colouring of G∗ exists with the constraint that some subgraphs of G∗ must admit a proper colouring. The equivalence of the two problems is proved here only for integers weights, but it is possible to adapt the transformation to prove it for rational weights.

3 Squares of Particular Graphs As mentioned in the introduction, W EIGHTED I MPROPER COLOURING is motivated by networks of antennas similar to grids [2]. In these networks, the noise generated by an antenna undergoes an attenuation with the distance it travels. It is often modelled by a decreasing function of d, typically 1/d α or 1/(2d−1). Here we consider a simplified model where the noise between two neighbouring antennas is normalised to 1, between antennas at distance two is 1/2 and 0 when the distance is strictly greater than 2. Studying this model of interference corresponds to study the W EIGHTED I MPROPER COLOURING of the square of the graph G, the graph obtained from G by joining every pair of vertices at distance 2, and to assign weights w2 (e) = 1, if e ∈ E(G), and w2 (e) = 1/2, if e ∈ E(G2 ) − E(G). Observe that in this case the interesting threshold values are the non-negative multiples of 1/2. In Figure 3 are given some examples of colouring for the square grid. In Figure 3(a) each vertex x has neither a neighbour nor a vertex at distance 2 coloured with its own colour, so Ix (G2 , w2 , c) = 0. In Figure 3(b) each vertex x has exactly one vertex of the same colour at distance 2, so Ix (G2 , w2 , c) = 1/2.

Weighted Improper Colouring

9

For any t ∈ R+ , we determine the weighted t-improper chromatic number for the square of infinite paths, square grids, hexagonal grids and triangular grids under the interference model w2 . We also present lower and upper bounds for χt (T 2 , w2 ), for any tree T and any threshold t. 3.1 Infinite Paths and Trees In this section, we characterise the weighted t-improper chromatic number of the square of an infinite path, for all positive real t. Moreover, we present lower and upper bounds for χt (T 2 , w2 ), for a given tree T . Theorem 5. Let P = (V, E) be an infinite path. Then, ⎧ ⎪ ⎨3, if 0 ≤ t < 1; χt (P2 , w2 ) = 2, if 1 ≤ t < 3; ⎪ ⎩ 1, if 3 ≤ t. Proof. Let V = {vi | i ∈ Z} and E = {(vi−1 , vi ) | i ∈ Z}. Each vertex of P has two neighbours and two vertices at distance two. Consequently, the first case t ≥ 3 is trivial. There is a 2-colouring c of (P2 , w2 ) with maximum interference 1 by just colouring vi with colour i mod 2. So χt (P2 , w2 ) ≤ 2 if t ≥ 1. We claim that there is no weighted 0.5improper 2-colouring of (P2 , w2 ). By contradiction, suppose that c is such a colouring. If c(vi ) = 0, for some i ∈ Z, then c(vi−1 ) = c(vi+1 ) = 1 and c(vi−2 ) = c(vi+2 ) = 0. This is a contradiction because vi would have interference 1. Finally, the colouring c(vi ) = i mod 3, for every i ∈ Z, is a feasible weighted 0improper 3-colouring. )− t )−1 Theorem 6. Let T = (V, E) be a tree. Then, Δ(T2t+1

+1 ≤ χt (T 2 , w2 ) ≤ Δ(T 2t+1 +2.

Proof. The lower bound is obtained by two simple observations. First, χt (H, w) ≤ χt (G, w), for any H ⊆ G. Let T be a tree and v be a node of maximum degree in T . Then, observe that the weighted t-improper chromatic number of the subgraph of T 2 )− t induced by v and its neighbourhood is at least Δ(T2t+1

+ 1. The colour of v can be assigned to at most t vertices on its neighbourhood. Any other colour used in the neighbourhood of v cannot appear in more than 2t + 1 vertices because each pair of vertices in the neighbourhood of v is at distance two. Let us look now at the upper bound. Choose any node r ∈ V to be its root. Colour r with colour 1. Then, by a pre-order traversal in the tree, for each visited node v colour )−1 all the children of v with the Δ(T 2t+1 colours different from the ones assigned to v and to its parent. This is a feasible weighted t-improper k-colouring of T 2 , with k ≤ )−1 Δ(T 2t+1 + 2, since each vertex interferes with at most 2t vertices at distance two which are children of its parent. 3.2 Grids In this section, we show the optimal values of χt (G2 , w2 ), whenever G is an infinite square, or hexagonal or triangular grid, for all the possible values of t. The proofs of the theorems presented in this section can be found in the research report [3].

10

J. Araujo et al.

(a)

(b)

(c)

(d)

Fig. 3. Optimal colorings of G2 , for square grid G. Weighted 0-improper 5-colouring of G2 in Figure 3(a), weighted 0.5-improper 4-colouring of G2 in Figure 3(b) and weighted 3-improper 2-colouring of G2 in 3(c). Figure 3(d) shows that there is no weighted 0.5-improper 3-colouring of G2 .

Square Grid. The square grid is the graph in which the vertices are all integer linear combinations ae1 + be2 of the two vectors e1 = (1, 0) and e2 = (0, 1), for any a, b ∈ Z. Each vertex (a, b) has four neighbours: its down neighbour (a − 1, b), its top neighbour (a + 1, b), its right neighbour (a, b + 1) and its left neighbour (a, b − 1). Theorem 7. If G is an infinite square grid, then ⎧ ⎪ ⎪ ⎪5, if t = 0; ⎪ ⎪ ⎪ ⎨4, if t = 0.5; 2 χt (G , w2 ) = 3, if 1 ≤ t < 3; ⎪ ⎪ ⎪2, if 3 ≤ t < 8; ⎪ ⎪ ⎪ ⎩1, if 8 ≤ t. Proof. If t = 0, then the colour of vertex (a, b) must be different from the ones used on its four neighbours. Moreover, all the neighbours have different colours, as each pair of neighbours is at distance two. Consequently, at least 5 colours are needed. Figure 3(a) gives a a weighted 0-improper 5-colouring of G2 . When t = 0.5, we claim that at least four colours are needed to colour G2 . The proof is by contradiction. Suppose that there exists a weighted 0.5-improper 3-colouring of it. Let (a, b) be a vertex coloured 0. No neighbour is coloured 0, otherwise (a, b) has interference 1. If three neighbours have the same colour, then each of them will have

Weighted Improper Colouring

11

interference 1. So two of its neighbours have to be coloured 1 and the two other ones 2 (see Figure 3(d)). Consider now the four nodes (a−1, b−1), (a−1, b+1), (a+1, b−1) and (a + 1, b + 1). For all configurations, at least two of these 4 vertices have to be coloured 0. But then (a, b) will have interference at least 1, a contradiction. A weighted 0.5-improper 4-colouring of G2 is shown in Figure 3(b). If t = 1, there exists a weighted 1-improper 3-colouring of G2 given by the following construction: for 0 ≤ j ≤ 2, let A j = {(0, j) + a(3e2 ) + b(e1 + e2 ) | ∀a, b ∈ Z}. For 0 ≤ j ≤ 2, assign the colour j to all the vertices in A j . Now we prove by contradiction that for t = 2.5 we still need at least three colours in a weighted 2.5-improper colouring of G2 . Consider a weighted 2.5-improper 2-colouring of G2 and let (a, b) be a vertex coloured 0. Vertex (a, b) has at most two neighbours of colour 0, otherwise it will have interference 3. We distinguish three cases: 1. Exactly one of its neighbours is coloured 0; let (a, b − 1) be this vertex. Then, the three other neighbours are coloured 1. Consider the two set of vertices {(a − 1, b − 1), (a − 1, b + 1), (a − 2, b)} and {(a + 1, b − 1), (a + 1, b + 1), (a + 2, b)}; each of them has at least two vertices coloured 0, otherwise the vertex (a, b + 1) or (a, b − 1) will have interference 3. But then (a, b) having 4 vertices at distance 2 coloured 0 has interference 3, a contradiction. 2. Two neighbours of (a, b) are coloured 0. (a) These two neighbours are opposite, say (a, b − 1) and (a, b + 1). Consider again the two sets {(a − 1, b − 1), (a − 1, b + 1), (a − 2, b)} and {(a + 1, b − 1), (a + 1, b + 1), (a + 2, b)}; they both contain at least one vertex of colour 0 and therefore (a, b) will have interference 3, a contradiction. (b) The two neighbours of colour 0 are of the form (a, b − 1) and (a − 1, b). Consider the two sets of vertices {(a + 1, b − 1), (a + 1, b + 1), (a + 2, b)} and {(a + 1, b + 1), (a − 1, b + 1), (a, b + 2)}; these two sets contain at most one vertex of colour 0, otherwise (a, b) will have interference 3. So vertices (a + 1, b − 1), (a + 2, b), (a, b + 2) and (a − 1, b + 1) are of colour 1. Vertex (a + 1, b + 1) is of colour 0, otherwise (a + 1, b) has interference 3. But then (a, b − 2) and (a − 1, b − 1) are of colour 1, otherwise (a, b) will have interference 3. Thus, vertex (a, b − 1) has exactly one neighbour coloured 0 and we are again in Case 1. 3. All neighbours of (a, b) are coloured 1. If any of this neighbours has itself a neighbour (distinct from (a, b)) of colour 1, we are in case 1 or 2 for this neighbour. Therefore, all vertices at distance two from (a, b) have colour 0 and the interference in (a, b) is 4, a contradiction. A weighted 3-improper 2-colouring of G2 is given in Figure 3(c). Finally, since each vertex has 4 neighbours and 8 vertices at distance two, there is no weighted 7.5-improper 1-colouring of G2 and, whenever t ≥ 8, one colour suffices. Hexagonal Grid. To define the hexagonal grid graph, there are many ways to define the system of coordinates. Here, we use grid coordinates as shown in Figure 4. The hexagonal grid graph is then the graph whose vertex set is the pairs of integers (a, b) ∈ Z2 and where each vertex (a, b) has 3 neighbours: (a − 1, b), (a + 1, b), and (a, b + 1) if a + b is odd, or (a, b − 1) otherwise.

12

J. Araujo et al.

0

0

2 3

1

3

1

2

0

2 0

2 3

3

1 3

1 0

2

3

0

1

1

2

Fig. 4. Optimal construction with t = 0, k = 4. Left: Graph with coordinates. Right: Corresponding hexagonal grid in the euclidean space.

0 0

2 1

0

2

2

1

0

0

1 2

0

2

1

0 1

1

0

2

1 0

0

0 1

1 0

1

1 0

1

2

0 1

1 0 0

0

2

0 1

1

1

1 0

1 0

1

(a) t = 1, k = 3

(b) t = 2, k = 2

Fig. 5. Optimal constructions for the hexagonal grid

Theorem 8. If G is an infinite hexagonal grid, then ⎧ 4, ⎪ ⎪ ⎪ ⎨ 3, χt (G2 , w2 ) = ⎪ 2, ⎪ ⎪ ⎩ 1,

if 0 ≤ t < 1; if 1 ≤ t < 2; if 2 ≤ t < 6; if 6 ≤ t.

Triangular Grid. The triangular grid is graph whose vertices are all the integer linear √ combinations ae1 + be2 of the two vectors e1 = ( 23 , 12 ) and e2 = (0, 1). Thus we may identify the vertices with the ordered pairs (a, b) of integers. Each vertex v = (a, b) has six neighbours: its left neighbour (a, b − 1), its right neighbour (a, b + 1), its left-up neighbour (a + 1, b − 1), its right-up neighbour (a + 1, b + 1), its left-down neighbour (a − 1, b − 1) and its right-down neighbour (a − 1, b + 1).

Weighted Improper Colouring

6-

(b) Weighted 0.5-improper colouring of G2 .

(a) Weighted 0-improper 7-colouring of G2 .

13

(c) Weighted 1.5-improper colouring of G2 .

4-

Fig. 6. Constructions for the triangular grid

Theorem 9. If G is an infinite triangular grid, then ⎧ 7, ⎪ ⎪ ⎪ ⎪ ⎪ 6, ⎪ ⎪ ⎪ ⎪ ⎪ ⎨5, χt (G2 , w2 ) = 4, ⎪ ⎪ ⎪3, ⎪ ⎪ ⎪ ⎪ ⎪ 2, ⎪ ⎪ ⎩ 1,

if t = 0; if t = 0.5; if t = 1; if 1.5 ≤ t < 3; if 3 ≤ t < 5; if 5 ≤ t < 12; if 12 ≤ t.

For determining the lower bounds for the cases in which χt (G2 , w2 ) is equal to 2 and 3, the proofs involved too many subcases to be readable. Then, we used CPLEX with the integer programming formulations we present in Section 4 to validate them.

4 Integer Programs, Algorithms and Results In this section, we look at how to solve the W EIGHTED I MPROPER COLOURING and T HRESHOLD I MPROPER COLOURING for realistic instances. We consider PoissonVoronoi tesselations as they are good models of antennas networks [4, 8, 9]. We present integer programming models for both problems. Then, we introduce two algorithmic approaches for T HRESHOLD I MPROPER COLOURING: a simple greedy heuristic and a Branch-and-Bound algorithm.

14

J. Araujo et al.

4.1 Integer Programs and Algorithms Integer Programming Models. Given an edge-graph G = (V, E, w), w : E → R∗+ , and a positive real threshold t, we model W EIGHTED I MPROPER C OLOURING by using two kinds of variables. Variable xip indicate if vertex i is coloured p and variable c p indicate if colour p is used, for every 1 ≤ i ≤ n and 1 ≤ p ≤ l, where l is an upper bound for the number of colours needed in an optimal weighted t-improper colouring of G (see Section 2). The model follows: min subject to

∑p cp ∑ j=i w(i, j)x j p ≤ t + M(1 − xip) (∀i ∈ V, ∀p ∈ {1, . . . , l}) c p ≥ xip (∀i ∈ V, ∀p ∈ {1, . . . , l}) (∀i ∈ V ) ∑ p xip = 1 xip ∈ {0, 1} (∀i ∈ V, ∀p ∈ {1, . . . , l}) c p ∈ {0, 1} (∀p ∈ {1, . . . , l})

where M is a large integer. For instance, it is sufficient to choose M > ∑(u,v)∈E w(u, v). For T HRESHOLD I MPROPER C OLOURING , given an edge-weighted graph G = (V, E, w), w : E → R∗+ , and a positive integer k, the model we consider is: min subject to

t ∑ j=i w(i, j)x j p ≤ t + M(1 − xip) (∀i ∈ V, ∀p ∈ {1, . . . , k}) (∀i ∈ V ) ∑ p xip = 1 xip ∈ {0, 1} (∀i ∈ V, ∀p ∈ {1, . . . , k})

Levelling Heuristic. We develop a heuristic to solve T HRESHOLD I MPROPER COLOUR ING. The idea is to try to level the distribution of interference over the vertices. Each vertex is coloured one after the other by the colour minimising the local interference. More precisely this is achieved by considering for the nodes not yet coloured the “current interference” i.e. the interference induced by the already coloured vertices. Precisely, consider a vertex v not yet coloured and a colour i ∈ {1, . . . , k}. We define as: the potential interference Iv,i Iv,i =

∑

w(u, v),

{u∈N(v)∩Vi |c(u)=i}

where Vi is the set of vertices that have already been assigned a colour. The order in which vertices are coloured is decided according to the total potential interference, de . The algorithm finds a feasible colouring in the first step and tries fined as Iv = ∑ki=1 Iv,i to improve it for p runs, where p is part of the input. – The interference target is set tt = M; – while the number of runs is smaller than p; • all potential interferences are set to zero; • while there are still vertices to colour: ∗ choose a vertex v randomly among the uncoloured vertices that have the maximum total potential interference;

Weighted Improper Colouring

15

: ∗ try each colour i in the order of increasing potential interference Iv,i · if colouring v with i does not result in interference greater than tt for v or any of its neighbours, colour v with i, else try a new colour; · if all colours resulted in excessive interferences, start new run. • If all the vertices were successfully coloured, set tt = maxv∈V,i∈{1,...,k} Iv (G, w, c) − gcd(w) and store the colouring as the best found.

As a randomised greedy colouring heuristic, it has to be run multiple times to achieve satisfactory results. This is not a practical issue due to low computational cost of each run. The local immutable colouring decision is taken in time O(k). Then, after each such decision, the interference has to be propagated, which takes time linear in the vertex degree. This gives a computational complexity bound O(knΔ). Branch-and-Bound Algorithm. We also implemented a simple Branch-and-Bound algorithm inspired by the above heuristic. The order in which vertices are coloured is produced by a similar procedure to the one used in the above heuristic. In order to compute this order, we start by marking a random vertex and setting is as the first in a to colour list. Then, as long as there are unmarked vertices, we keep choosing a random vertex u among the unmarked vertices with biggest ∑v∈N(u)∩Vm w(u, v), where Vm is the set of already marked vertices. Then we mark u and append it to the to order. A basic Branch-and-Bound colours vertices in the obtained order. Potential interference, as defined for the heuristic, is tracked with the additional step of decreasing the values when backing from a colouring. Colours are tried in the order of increasing potential interference. Thanks to that it produces results similar to the heuristic in a short time. On the other hand it is guaranteed to find the optimal solution in a finite time. In the following, we compare the performance of these ILP models with the Levelling heuristic and the Branch-and-Bound algorithm . 4.2 Results In this section, we look at the performances of the methods to solve the T HRESHOLD I MPROPER COLOURING. We consider Delaunay graphs (dual of Voronoi diagram) for a set of random points. This kind of graph is a natural approximation of a network of irregular cells. The interference model is the one described in Section 3: adjacent nodes interfere by 1 and nodes at distance two interfere by 1/2. Figure 7 shows a performance comparison of the above-mentioned algorithms. For all the plots, each data point represents an average over ten different graphs. The same graph is used for all values of colours and time limit. Therefore sub-figures 7(b) and 7(c) plot how results for a given problem instance get enhanced with increasing time limits. Plots 7(e) and 7(f) show decreasing interference along increasing the number of colours allowed. Finally plot 7(d) shows how well all the programs scale with increasing graph sizes. One immediate observation about both the heuristic and Branch-and-Bound algorithm is that they provide solutions in relatively short time. Despite their naive implementation in a high-level programming language, they tend to find near-optimal results in matter of seconds even for graphs of thousands of vertices. On the other hand, with

16

J. Araujo et al. Delaunay graph, n=2000 vertices, k=5 colors

t - interference found

35

Branch & Bound Heuristic IP

30 25 20 15 10 5 0

0

100

200

300

400

500

600

700

l - Time limit [seconds]

(a) Example Delaunay graph, dotted lines delimit corresponding Voronoi diagram cells Delaunay graph, n=2000 vertices, k=2 colors

30 25 20 15 10 5 0

200

300

400

500

600

20 15 10 5 0

500

1000

1500

2000

(c) Over time

(d) Over size

25 20 15 10 5 4

25

n - number of vertices

Branch & Bound Heuristic IP

2

Branch & Bound Heuristic IP

30

l - Time limit [seconds]

30

0

35

0

700

Delaunay graph, N=2000 vertices, L=60 sec

35

t – interference found

100

Delaunay graph, k=2 colors, l=60 sec

40

t - interference found

Branch & Bound Heuristic IP

6

8

10

k – number of colors

(e) Over colours

12

14

t – interference found

t - interference found

35

0

(b) Over time

180 160 140 120 100 80 60 40 20 0

2500

3000

¨ ´ Erdos-R enyi graph, N=500 vertices, L=120 sec

Branch & Bound Heuristic IP

2

4

6

8

10

12

14

k – number of colors

(f) Over colours

Fig. 7. Results comparison for Levelling heuristic, Branch-and-Bound algorithm and Integer Programme

limited time, they fail to improve up to optimal results, especially with a low number of allowed colours. Although it is easy to envision an implementation faster by orders of magnitude, this may still give little improvement — once a near-optimal solution is found, the Branch-and-Bound algorithm does not improve for a very long time (an example near-optimal solution found in around three minutes was not improved in over six days). ILP solvers with good Branch-and-Cut implementations do not suffer from this problem. However, they can not take advantage of any specialised knowledge of the problem, only the basic integer programmming representation. Thus it takes much more time to produce first good results. Despite taking advantage of multi-core processing,

Weighted Improper Colouring

17

CPLEX — ILP solver used in this work, does not scale with increasing graph sizes as well as our simple algorithms. Furthermore, Figure 7(e) reveals one problem specific to integer programming. When increasing the number of allowed colours, obtaining small interferences gets easier. But this introduces additional constraints in the linear program, thus increasing the complexity for a solver. Above observations are valid only for the very particular case of the simple interference function and very sparse graphs. The average degree in Delaunay graph converges to 6. Proposed algorithms also work quite well for denser graphs. Figure 7(f) plots interferences for different numbers of colours allowed found by the programs for an Erd¨os-R´enyi graph with n=500 and p=0.1. This gives us an average degree of 50. Both Branch-and-Bound and heuristic programs achieve acceptable, and nearly identical, results. But the large number of constraints makes the linear program nearly inefficient.

5 Conclusion, Open Problems and Future Directions In this paper, we introduced and studied a new colouring problem, W EIGHTED I M PROPER COLOURING . This problem is motivated by the design of telecommunication antenna network in which the interferences between two vertices depends on different factors and can take various values. For each vertex, the sum of the interference it receives should be less than a given threshold value. We first give general bounds on the weighted-improper chromatic number. We then study the particular case of square, triangular and hexagonal grids. For these graphs, we provide their weighted-improper chromatic number for all possible values of t. Finally, we propose a heuristic and a Branch-and-Bound algorithm to find good solutions of the problem. We compare their results with the one of an integer program on cell-like networks, Poisson Voronoi tessellations. Open Problems and Future Directions. Many problems remain to be solved : – For the study of the grid graphs, we considered a specific function where vertex at distance one interfere by 1 and vertices at distance 2 by 1/2. Other weight functions should be considered. e.g. 1/d 2 or 1/(2d−1 ), where d is the distance between vertices. – Other families of graphs could be considered, for example hypercubes. – Let G = (V, E, w) be an edge-weighted graph where the weights are all equal to 1 or M. Let GM be the subgraph of G induced by the edges of weight M; is it true that if Δ(GM ) 0 are respective thresholds below which these problems cannot be approximated eﬃciently (unless NP has slightly super-polynomial time algorithm [12] or unless P=NP [27]). Dominating Set and Coloring have a number of applications and this has led to the algorithmic study of numerous variants of these problems. Among the most well known ones are Connected Dominating Set, Independent Dominating Set, Perfect Code, List Coloring, Edge Coloring, Acyclic Edge Coloring and Choosability. Since both the problem and its variants are computationally hard problems, most of the research centers around algorithms in special classes of graphs like interval graphs, chordal graphs, planar graphs and H-minor free graphs. In this paper we initiate a systematic algorithmic study on the Dominator Coloring (DC) problem that has a ﬂavor of both these classical problems. A dominator coloring of a graph G is an assignment of colors to the vertices of G such that it is a proper coloring (no edge is monochromatic) and every vertex dominates all vertices of at least one color class. The minimum number of colors required for a dominator coloring of G is called the dominator chromatic number of G and is denoted by χd (G). The problem we study is formally deﬁned as follows. Dominator Coloring (DC) Input: A graph G and an integer k ≥ 1. Parameter: k. Question: Does there exist a dominator coloring of G using at most k colors? Gera et al. [22] introduced the concept of dominator chromatic number, and a number of basic combinatorial and algorithmic results on DC have been obtained [20,21,22,24]. For example, it was observed by Gera et al. [22] that DC is NP-complete on general graphs by a simple reduction from 3-Coloring. More precisely, for any ﬁxed k ≥ 4, it is NP-complete to decide if a graph admits a dominator coloring with at most k colors [22]. In a recent paper Chellali and Maﬀray [6] show that unlike 3-Coloring, one can decide in polynomial time if a graph has dominator chromatic number 3. Furthermore, they show that the problem is polynomial time solvable on P4 free graphs, and leave as a “challenging open problem” whether the problem can be solved in polynomial time on chordal graphs. In this paper we do a thorough algorithmic study of this problem, analyzing both the classical complexity and the parameterized complexity. We begin by showing that unless P=NP, DC cannot be solved in polynomial time on bipartite, planar, or split graphs. The ﬁrst two arguments are simple but make use of an unusual sequence of observations. The NP-completeness reduction on split graphs is quite involved. Since split graphs form a subclass of chordal graphs, this answers, in the negative, the open problem posed by Chellali and Maﬀray.

Algorithmic Aspects of Dominator Colorings in Graphs

21

We complement our hardness results by showing that the problem is “ﬁxed parameter tractable" on several of the graph classes mentioned above. Informally, a parameterization of a problem assigns an integer k to each input instance and a parameterized problem is fixed-parameter tractable (FPT) if there is an algorithm that solves the problem in time f (k) · |I|O(1) , where |I| is the size of the input and f is an arbitrary computable function that depends only on the parameter k. We refer the interested reader to standard texts [10,14] on parameterized complexity. We show that DC is FPT on planar graphs, apex minor free graphs, split graphs and chordal graphs.

2

Preliminaries

All graphs in this article are ﬁnite and undirected, with neither loops nor multiple edges. n denotes the number of vertices in a graph, and m the number of edges. A subset D ⊆ V of the vertex set V of a graph G is said to be a dominating set of G if every vertex in V \ D is adjacent to some vertex in D. The domination number γ(G) of G is the size of a smallest dominating set of G. A proper coloring of graph G is an assignment of colors to the vertices of G such that the two end vertices of any edge have diﬀerent colors. The chromatic number χ(G) of G is the minimum number of colors required in a proper coloring of G. A clique is a graph in which there is an edge between every pair of vertices. The clique number ω(G) of G is the size of a largest clique which is a subgraph of G. We make use of the following known results. Theorem 1. [20] Let G be a connected graph. Then max{χ(G), γ(G)} ≤ χd (G) ≤ χ(G) + γ(G). Definition 1. A tree decomposition of a (undirected) graph G = (V, E) is a pair (X, U ) where U = (W, F ) is a tree, and X = ({Xi | i ∈ W }) is a collection of subsets of V such that 1. i∈W Xi = V , 2. for each edge vw ∈ E, there is an i ∈ W such that v, w ∈ Xi , and 3. for each v ∈ V, the set of vertices {i | v ∈ Xi } forms a subtree of U . The width of (X, U ) is maxi∈W {|Xi | − 1}. The treewidth tw(G) of G is the minimum width over all the tree decompositions of G. Both our FPT algorithms make use of the fact that the DC problem can be expressed in Monadic Second Order Logic (MSOL) on graphs. The syntax of MSOL on graphs includes the logical connectives ∨, ∧, ¬, ⇔, ⇒, variables for vertices, edges, sets of vertices and sets of edges, the quantiﬁers ∀, ∃ that can be applied to these variables, and the following ﬁve binary relations: (1) u ∈ U where u is a vertex variable and U is a vertex set variable; (2) d ∈ D where d is an edge variable and D is an edge set variable; (3) inc(d, u), where d is an edge variable, u is a vertex variable, and the interpretation is that the edge d is incident on the vertex u; (4) adj(u, v), where u and v are vertex variables

22

S. Arumugam et al.

and the interpretation is that u and v are adjacent; (5) equality of variables representing vertices, edges, sets of vertices and sets of edges. Many common graph and set-theoretic notions can be expressed in MSOL [5,8]. In particular, let V1 , V2 , . . . , Vk be a set of subsets of the vertex set V (G) of a graph G. Then the following notions can be expressed in MSOL: – V1 , V2 , . . . , Vk is a partition of V (G): P art(V (G); V1 , V2 , . . . , Vk ) ≡ ∀v ∈ V (G)[(v ∈ V1 ∨ v ∈ V2 ∨ · · · ∨ v ∈ Vk ) ∧ (¬(v ∈ V1 ∩ V2 )) ∧ (¬(v ∈ V1 ∩ V3 )) ∧ · · · ∧ (¬(v ∈ Vk−1 ∩ Vk ))] ∧ (∃v ∈ V (G)[v ∈ V1 ]) ∧ (∃v ∈ V (G)[v ∈ V2 ]) ∧ · · · ∧ (∃v ∈ V (G)[v ∈ Vk ]) – Vi is an independent set in G: IndSet(Vi ) ≡ ∀u ∈ Vi [∀v ∈ Vi [¬adj(u, v)]] – Vertex v dominates all vertices in the set Vi : Dom(v, Vi ) ≡ ∀w ∈ Vi [¬(w = v) =⇒ adj(v, w)] For a graph G and a positive integer k, we use ϕ(G, k) to denote an MSOL formula which states that G has a dominator coloring with at most k colors: ϕ(G, k) ≡ ∃V1 , V2 , . . . , Vk ⊆ V (G)[P art(V (G); V1 , V2 , . . . , Vk ) ∧

(1)

IndSet(V1 ) ∧ IndSet(V2 ) ∧ · · · ∧ IndSet(Vk ) ∧ ∀v ∈ V (G)[Dom(v, V1 ) ∨ Dom(v, V2 ) ∨ · · · ∨ Dom(v, Vk )]] The following well known result states that every optimization problem expressible in MSOL has a linear time algorithm on graphs of bounded treewidth. Proposition 1. [1,3,5,7,9] Let ϕ be a property that is expressible in Monadic Second Order Logic. For any fixed positive integer t, there is an algorithm that, given a graph G of treewidth at most t as input, finds a largest (alternatively, smallest) set S of vertices of G that satisfies ϕ in time f (t, |ϕ|)|V (G)| for a computable function f (). Since the size |ϕ(G, k)| of the MSOL expression 1 is a function of k, we have Theorem 2. Given a graph G of treewidth t and a positive integer k as inputs, the Dominator Coloring problem can be solved in f (t, k)|V (G)| time for a computable function f (). The operation of contracting an edge {u, v} of a graph consists of replacing the two vertices u, v with a single vertex which is adjacent to all the former neighbours of u and v. A graph H is said to be a contraction of a graph G if H can be obtained from G by contracting zero or more edges of G. H is said to be a minor of G if H is a contraction of some subgraph of G. A graph G is said to be apex graph if there exists a vertex in G whose removal from G yields a planar

Algorithmic Aspects of Dominator Colorings in Graphs

23

Fig. 1. The graph Γ6

graph. A family F of graphs is said to be apex minor free if there is a speciﬁc apex graph H such that no graph in F has H as a minor. For instance, planar graphs are apex minor free since they exclude the apex graph K5 as a minor. The treewidth of an apex minor free graph can be approximated to within a constant factor in polynomial time: Proposition 2. [13, Theorem 6.4] For any graph H, there is a constant wH and a polynomial time algorithm which finds a tree decomposition of width at most wH t for any H-minor-free graph G of treewidth t. For ∈ N, Γ is deﬁned [15] to be the graph obtained from the × -grid by (1) triangulating the internal faces such that all the internal vertices become of degree 6 and all non-corner external vertices are of degree 4, and (2) adding edges from one corner of degree two to all vertices of the external face. Figure 1 depicts Γ6 . Fomin et al. showed that any apex minor free graph of large treewidth contains a proportionately large Γ as a contraction. More precisely: Proposition 3. [15, Theorem 1] For any apex graph H, there is a constant cH such that every connected graph G which excludes H as a minor and has treewidth at least cH contains Γ as a contraction.

3

Hardness Results

In this section we show that DC is NP-hard on very restricted classes of graphs. The only known hardness result for this problem is that it is NP-complete on general graphs [22]. In fact even determining whether there exists a dominator coloring of G using at most 4 colors is NP-complete. The proof is obtained by a reduction from 3-Coloring – checking whether an input graph is 3-colorable or not – to DC. Given an instance G to 3-Coloring, an instance G for DC is obtained by adding a new vertex (universal vertex) and making it adjacent to every vertex of G. Now one can easily argue that G is 3 colorable if and only if G has dominator coloring of size at most 4. Notice, however, that this simple reduction cannot be used to show that DC is NP-complete on restricted graph classes like planar graphs or split graphs or chordal graphs. We start with a few simple claims that we will make use of later.

24

S. Arumugam et al.

Lemma 1. Let G = (V, E) be a graph. Given a proper a-coloring C of G and a dominating set D of G with |D| = b, we can find, in O(|V | + |E|) time, a dominator coloring of G with at most a + b colors. Proof. Let C = {V1 , V2 , . . . , Va } be a proper coloring of G and let D be a dominating set with |D| = b. Then C = {{v} : v ∈ D} ∪ {Vi ∩ (V − D) : Vi ∈ C} is a dominator coloring of G with at most a + b colors. Corollary 1. [ ]1 If there exists an α-approximation algorithm for the chromatic number problem and a β-approximation algorithm for the domination number problem, then there exists an (α + β)-approximation algorithm for the dominator chromatic number problem. Lemma 2. [ ] Let F be a class of graphs on which the Dominating Set problem is NP-complete. If the disjoint union of any two graphs in F is also in F, then there is no polynomial time algorithm that finds a constant additive approximation for the Dominating Set problem on F , unless P = N P. Corollary 2. [ ] Dominator Coloring on planar graphs cannot be solved in polynomial time, unless P = N P. Corollary 3. [ ] Dominator Coloring on bipartite graphs cannot be solved in polynomial time, unless P = N P. 3.1

NP-Hardness of DC on Split Graphs

We now proceed to prove that the DC problem is NP-complete for split graphs. Our starting point is the following known characterization: Theorem 3. [2] Let G be a split graph with split partition (K, I) and |K| = ω(G), where K is a clique and I an independent set. Then χd (G) = ω or ω + 1. Further χd (G) = ω if and only if there exists a dominating set D of G such that D ⊆ K and every vertex v in I is nonadjacent to at least one vertex in K \ D. We exploit this characterization, and prove NP-completeness on split graphs by demonstrating the NP-completeness of the problem of checking if there exists a dominating set D of G such that D ⊆ K and every vertex v in I is nonadjacent to at least one vertex in K \D. We call this problem Split Graph Domination. For showing Split Graph Domination NP-complete, we will need to deﬁne an intermediate problem called Partition Satisfiability, and demonstrate that it is NP-complete. We will then show that DC is NP-hard on split graphs by establishing a reduction from Partition Satisfiability. Let φ be a CNF formula. Then we use C(φ) to denote the set of clauses of φ. If C is a clause of φ, then we use ν(C) to denote the set of variables that appear in C. A clause is said to be all-positive (negative) if all the literals that appear in it are positive (negative). 1

Due to space constraints, proofs of results marked with a [] have been deferred to a longer version of the paper.

Algorithmic Aspects of Dominator Colorings in Graphs

25

Definition 2 (Partition Normal Form). A CNF formula φ over the variable set V is said to be in partition normal form if C(φ) admits a partition into two parts CP (φ) and CN (φ) and there exists a bijection f : CP (φ) → CN (φ) such that for every C ∈ CP (φ) the following conditions are satisfied: (1) ν(C) ∪ ν(f (C)) = V and (2) ν(C) ∩ ν(f (C)) = ∅. Any clause in CP (φ) is required to be an all-positive clause and any clause in CN (φ) is required to be an all-negative clause. We are now ready to describe the problem Partition Satisfiability. Partition Satisfiability Input: A formula φ in CNF, over variables in V , given in partition normal form. Question: Is φ satisﬁable? We establish the NP-completeness of Partition Satisfiability by a reduction from Disjoint Factors: Disjoint Factors Input: A word w over an alphabet Σ. Question: For every a ∈ Σ, does there exist a substring wa of w that begins and ends in a, such that for every a, b ∈ Σ, wa and wb do not overlap in w? The problem of Disjoint Factors is known to be NP-complete [4]. Substrings that begin and end with the same letter a are referred to as a-factors. Lemma 3. Partition Satisfiability is NP-complete. Proof. Let w = w1 w2 . . . wn be an instance of Disjoint Factors over the alphabet Σ = {a1 , . . . , ak }. For 1 ≤ i < j ≤ n and 1 ≤ l ≤ k, we call the triplet (i, j, l) valid if the substring wi . . . wj is an al -factor. Let F denote the set of valid triplets. We construct an instance of Partition Satisfiability as follows: For every valid triplet (i, j, l), introduce the variable Pl (i, j). For every 1 ≤ l ≤ k, introduce the clause: ⎛ ⎞ Cl := ⎝ Pl (i, j)⎠ . {i,j : (i,j,l)∈F }

Let φFACTOR be the conjunction of the clauses thus formed: φFACTOR := C1 ∧ C2 ∧ . . . ∧ Ck . Further, for every i1 , j1 and i2 , j2 such that 1 ≤ i1 < j1 ≤ n and 1 ≤ i2 < j2 ≤ n, and [i1 , j1 ] ∩ [i2 , j2 ] = ∅, and there exist l1 , l2 ; 1 ≤ l1 , l2 ≤ k, such that (i1 , j1 , l1 ) ∈ F and (i2 , j2 , l2 ) ∈ F , we introduce the following clause:

26

S. Arumugam et al.

C := Pl1 (i1 , j1 ) ∨ Pl2 (i2 , j2 ) Let D denote the set of clauses described above. Further, let φDISJOINT be the conjunction of these clauses: φDISJOINT := C∈D C. Claim. The formula: φ := φDISJOINT ∧ φFACTOR is satisﬁable if and only if (w, Σ) is a YES-instance of Disjoint Factors. Proof. (⇒) Let χ be a satisfying assignment of φ. For all l, 1 ≤ l ≤ k, there exists at least one pair (i, j), 1 ≤ i < j ≤ n, such that χ sets Pl (i, j) to 1. Indeed, if not, χ would fail to satisfy the clause Cl . Now, note that wi . . . wj is a al -factor, since the variable Pl (i, j) corresponds to a valid triplet. We pick wi . . . wj as the factor for al (if Pl (i, j) is set to 1 by χ for more than one pair (i, j), then any one of these pairs will serve our purpose). It only remains to be seen that for r, s ∈ Σ, if wi1 . . . wj1 is chosen as a ar -factor, and wi2 . . . wj2 is chosen as a as -factor, then wi1 . . . wj1 and wi2 . . . wj2 do not overlap in w. This is indeed the case, for if they did overlap, then it is easily checked that χ would fail to satisfy the clause: Pr (i1 , j1 ) ∨ Ps (i2 , j2 ) . (⇐) If (w, Σ) is a YES-instance of Disjoint Factors, then for every l, 1 ≤ l ≤ k, there exist i, j; 1 ≤ i < j ≤ n, such that (i, j, l) ∈ F . We claim that setting all the “corresponding” Pl (i, j) variables to 1 is a satisfying assignment for φ. Indeed, every Cl is satisﬁed because there exists an al -factor for every l. Further, it is routine to verify that all clauses in D are satisﬁed because the chosen factors do not overlap in w. Now, it remains to construct from φ an equivalent formula ψ that is in partition normal form. To this end, we will use two new variables, {x, y}. Recall that we use V to denote the set of variables that appear in φ. For every clause Cl , deﬁne the clause Cˆl as: Cˆl := x ∨ y ∨ z ∈ V \ν(Cl ) z . ˆ as: Cˆ := x ∨ y ∨ Similarly, for every clause C ∈ D, deﬁne C z ∈ V \ν(C) z . Let ψ be conjunction of φ with the newly described clauses: obtained by the ˆl ∧

ˆ . ψ := φ ∧ C C 1≤l≤k C∈D Clearly, ψ is in partition normal form. The following partition of the clauses of ψ: CP = {Cl : 1 ≤ l ≤ k} ∪ {Cˆ : C ∈ D} and CN = {Cˆl : 1 ≤ l ≤ k} ∪ {C : C ∈ D} is a partition into all-positive and all-negative clauses. The ˆ = C, for C ∈ D is bijection f deﬁned as: f (Cl ) = Cˆl , for 1 ≤ l ≤ k and f (C) easily seen to be a bijection with the properties demanded by the deﬁnition of the partition normal form. We now arrive at our concluding claim: Claim. φ is satisﬁable if and only if ψ is satisﬁable. Proof. (⇒) Let χ be a satisfying assignment for φ. Extend φ to the new variables {x, y} as follows: χ(x) = 1 and χ(y) = 0. It is easy to see that χ is satisfying for ψ. (⇐) This direction is immediate, as C(φ) ⊆ C(ψ).

Algorithmic Aspects of Dominator Colorings in Graphs

27

The proof that Partition Satisfiability is NP-hard follows when we put the two claims together: by appending the construction of ψ from φ to the formula φ obtained from the Disjoint Factors instance, we obtain an equivalent instance of Partition Satisfiability. This concludes the proof. We note that membership in NP is trivial — an assignment to the variables is clearly a certiﬁcate that can be veriﬁed in linear time. The lemma follows. Recall the Split Graph Domination problem that we introduced in the beginning of this section: Split Graph Domination Input: Split graph G with split partition (K, I) and |K| = ω. Question: Does there exist a dominating set D of G such that D ⊆ K and every vertex v in I is nonadjacent to at least one vertex in K \ D ? We now turn to a proof that Split Graph Domination is NP-complete. Theorem 4. Split Graph Domination is NP-complete. Proof. It is straightforward to see that Split Graph Domination is in NP. We now prove that it is NP-hard by a reduction from Partition Satisfiability. Given an instance φ (over the variables V ) of Partition Satisfiability, we construct a split graph G with split partition (K, I) as follows. Introduce, for every variable in V , a vertex in K and for every all-positive clause of φ, a vertex in I: K = {v[x] : x ∈ V }, I = {u[C] : C ∈ CP (φ)}. A pair of vertices v[x] and u[C] are adjacent if the variable x belongs to the clause C, that is, x ∈ ν(C). We also make all vertices in K pairwise adjacent and all vertices in I pairwise independent. This completes the construction. Suppose φ admits a satisfying truth assignment χ. Let D = {v[x] ∈ K : χ(x) = 1}. We now prove that this choice of D is a split dominating set. Consider u[C] ∈ I. There exists at least one x ∈ V such that x ∈ ν(C) and χ(x) = 1. Thus the corresponding vertex v[x] ∈ D, and u[C] is dominated. Further, consider the all-negative clause Cˆ corresponding to C, that contains every variable in V that is not in ν(C). Since χ is a satisfying assignment, there is at least one y ∈ V \ ν(C) such that χ(y) = 0. Clearly, v[y] ∈ / D, and v[y] is not adjacent to u[C]. Conversely, suppose there exists a dominating set D ⊆ K such that each u[C] in I is nonadjacent to at least one vertex in K \ D. Consider the following truth assignment χ for φ: χ(x) = 1 if, and only if, v[x] ∈ K ∩ D. We now prove that χ is a satisfying assignment. Consider any all-positive clause C. Since u[C] was dominated by D, there exists a variable x ∈ ν(C) such that v[x] ∈ D, and thus ˆ Since K \D contains χ(x) = 1. Consider the corresponding all-negative clause C. at least one non-neighbor of v[x], there exists a y ∈ / ν(C) such that χ(y) = 0. ˆ Recall that the assignment χ(y) = 0 Note that y ∈ / ν(C) implies that y ∈ ν(C). ˆ since Cˆ is an all-negative clause. is then satisfying for C, From Theorem 3 and Theorem 4 we get

28

S. Arumugam et al.

Theorem 5. DC when restricted to split graphs is NP-complete.

4

Parameterized Algorithms

In this section we investigate the ﬁxed-parameter tractability of the DC problem in certain graph classes. Recall that it is NP-complete to decide if a graph admits a dominator coloring with at most 4 colors [22]. It follows that in general graphs, the DC problem cannot be solved even in time ng(k) for any function g(k) — that is, DC does not belong to the complexity class XP — unless P=NP. Hence DC is not FPT in general graphs unless P=NP. As we show below, however, the problem is FPT in two important classes of graphs, namely apex-minorfree graphs (which include planar graphs as a special case) and chordal graphs. Recall that it is NP-complete to decide if a planar graph admits a proper 3coloring [18]. As a consequence, the Graph Coloring problem parameterized by the number of colors is not even in XP in planar graphs. Our result for planar graphs thus brings out a marked diﬀerence in the parameterized complexity of these two problems when restricted to planar graphs. Apex Minor Free Graphs. We now show that the Dominator Coloring problem is FPT on apex minor free graphs. This implies, as a special case, that the problem is FPT on planar graphs. We ﬁrst show that if the treewidth of the input apex minor free graph is large, then the graph has no dominator coloring with a small number of colors. Theorem 6. [ ] For any apex graph H, there is a constant dH such that any √ connected graph G which excludes H as a minor and has treewidth at least dH k has no dominator coloring with at most k colors. Let (G, k) be an instance of the Dominator Coloring problem, where G √ excludes the apex graph H as a minor. Let t = wH dH k where dH , wH are the constants of Theorem 6 and Proposition 2, respectively. To solve the problem on this instance, we invoke the approximation subroutine implied by Proposition 2 on the graph G. If this subroutine returns a tree decomposition with treewidth more than t, then we return NO as the answer. Otherwise we solve the problem using the algorithm of Theorem 2, and so we have: Theorem 7. [ ] The Dominator Coloring problem is fixed parameter tractable on apex minor free graphs. Chordal Graphs and Split Graphs. We now show that the Dominator Coloring problem is FPT on chordal graphs. For a special class of chordal graphs, namely split graphs, we give an FPT algorithm which runs in time single-exponential in the parameter. Theorem 8. The Dominator Coloring problem is fixed parameter tractable on chordal graphs. Proof. Let (G, k) be an instance of the Dominator Coloring problem, where G is chordal. The algorithm ﬁrst ﬁnds a largest clique in G. If the number of

Algorithmic Aspects of Dominator Colorings in Graphs

29

vertices in this clique is more than k, then it returns NO as the answer. Otherwise it invokes the algorithm of Theorem 2 as a subroutine to solve the problem. To see that this algorithm is correct, observe that if G contains a clique C with more than k vertices, then χ(G) > k since it requires more than k colors to properly color the subgraph C itself. It follows from Theorem 1 that χd (G) > k, and so it is correct to return NO. A largest clique in a chordal graph can be found in linear time [19]. If the largest clique in G has size no larger than k, then — as is well known — the treewidth of G is at most k − 1, and so the subroutine from Theorem 2 runs in at most f ((k − 1), k)|V (G)| = g(k)|V (G)| time. Thus the algorithm solves the problem in FPT time. The Dominator Coloring problem can be solved in “fast” FPT time on split graphs: Theorem 9. [ ] The Dominator Coloring problem can be solved in O(2k ·n2 ) time on a split graph on n vertices.

5

Conclusion and Scope

We derived several algorithmic results about the Dominator Coloring (DC) problem. We showed that the DC problem remains hard on several graph classes, including bipartite graphs, planar graphs, and split graphs. In the process we also answered, in the negative, an open problem by Chellali and Maﬀray [6] about the polynomial time solvability of DC on chordal graphs. Finally, we showed that though the problem cannot be solved in polynomial time on the aforementioned graph classes, it is FPT on apex minor free graphs and on chordal graphs. From Theorem 1 and from the fact that ﬁnding a constant additive approximation for the Dominating Set problem is W[2]-hard [11], it follows that the DC problem is W[2]-hard on bipartite graphs, and so also on the larger class of perfect graphs. An interesting problem which remains open is whether the DC problem is solvable in polynomial time on interval graphs.

References 1. Arnborg, S., Lagergren, J., Seese, D.: Easy problems for tree-decomposable graphs. Journal of Algorithms 12(2), 308–340 (1991) 2. Arumugam, S., Bagga, J., Chandrasekar, K.R.: On dominator colorings in graphs (2010) (manuscript) 3. Bodlaender, H.L.: A linear time algorithm for ﬁnding tree-decompositions of small treewidth. SIAM Journal on Computing 25, 1305–1317 (1996) 4. Bodlaender, H.L., Thomassé, S., Yeo, A.: Kernel Bounds for Disjoint Cycles and Disjoint Paths. In: Fiat, A., Sanders, P. (eds.) ESA 2009. LNCS, vol. 5757, pp. 635–646. Springer, Heidelberg (2009) 5. Borie, R.B., Parker, G.R., Tovey, C.A.: Automatic Generation of Linear-Time Algorithms from Predicate Calculus Descriptions of Problems on Recursively Constructed Graph Families. Algorithmica 7, 555–581 (1992)

30

S. Arumugam et al.

6. Chellali, M., Maﬀray, F.: Dominator colorings in some classes of graphs. Graphs and Combinatorics, 1–11 (2011) 7. Courcelle, B.: The monadic second-order logic of graphs. i. recognizable sets of ﬁnite graphs. Information and Computation 85(1), 12–75 (1990) 8. Courcelle, B.: The expression of graph properties and graph transformations in monadic second-order logic. In: Rozenberg, G. (ed.) Handbook of Graph Grammars and Computing by Graph Transformations: Foundations, ch. 5, vol. 1. World Scientiﬁc (1997) 9. Courcelle, B., Mosbah, M.: Monadic second-order evaluations on treedecomposable graphs. Theoretical Computer Science 109(1-2), 49–82 (1993) 10. Downey, R.G., Fellows, M.R.: Parameterized Complexity. Springer, New York (1999) 11. Downey, R.G., Fellows, M.R., McCartin, C., Rosamond, F.: Parameterized approximation of dominating set problems. Information Processing Letters 109(1), 68–70 (2008) 12. Feige, U.: A threshold of ln n for approximating set cover. Journal of the ACM 45(4), 634–652 (1998) 13. Feige, U., Hajiaghayi, M., Lee, J.R.: Improved approximation algorithms for minimum-weight vertex separators. SIAM Journal on Computing 38(2), 629–657 (2008) 14. Flum, J., Grohe, M.: Parameterized Complexity Theory. Texts in Theoretical Computer Science. An EATCS Series. Springer, Berlin (2006) 15. Fomin, F.V., Golovach, P., Thilikos, D.M.: Contraction Bidimensionality: The Accurate Picture. In: Fiat, A., Sanders, P. (eds.) ESA 2009. LNCS, vol. 5757, pp. 706–717. Springer, Heidelberg (2009) 16. Fomin, F.V., Thilikos, D.M.: Dominating sets in planar graphs: Branch-width and exponential speed-up. SIAM Journal on Computing 36(2), 281–309 (2006) 17. Garey, M.R., Johnson, D.S.: Computers and Intractability: A Guide to the Theory of NP–Completeness. Freeman, San Francisco (1979) 18. Garey, M.R., Johnson, D.S., Stockmeyer, L.: Some simpliﬁed NP-complete graph problems. Theoretical Computer Science 1, 237–267 (1976) 19. Gavril, F.: Algorithms for minimum coloring, maximum clique, minimum covering by cliques, and maximum independent set of a chordal graph. SIAM Journal on Computing 1(2), 180–187 (1972) 20. Gera, R.: On dominator coloring in graphs. In: Graph Theory Notes of New York, pp. 25–30. LII (2007) 21. Gera, R.: On the dominator colorings in bipartite graphs. In: ITNG, pp. 1–6. IEEE (2007) 22. Gera, R., Rasmussen, C., Horton, S.: Dominator colorings and safe clique partitions. Congressus Numerantium 181(7-9), 19–32 (2006) 23. Halldórsson, M.M.: A still better performance guarantee for approximate graph coloring. Information Processing Letters 45(1), 19–23 (1993) 24. Hedetniemi, S., Hedetniemi, S., McRae, A., Blair, J.: Dominator colorings of graphs (2006) (preprint) 25. Johnson, D.S.: Approximation algorithms for combinatorial problems. Journal of Computer and System Sciences 9(3), 256–278 (1974) 26. Lovász, L.: On the ratio of optimal integral and fractional covers. Discrete Mathematics 13, 383–390 (1975) 27. Lund, C., Yannakakis, M.: On the hardness of approximating minimization problems. Journal of the ACM 41(5), 960–981 (1994)

Parameterized Longest Previous Factor Richard Beal and Donald Adjeroh West Virginia University, Lane Department of Computer Science and Electrical Engineering, Morgantown, WV 26506 [email protected], [email protected]

Abstract. The longest previous factor (LPF) problem is deﬁned for traditional strings exclusively from the constant alphabet Σ. A parameterized string (p-string) is a sophisticated string composed of symbols from a constant alphabet Σ and a parameter alphabet Π. We generalize the LPF problem to the parameterized longest previous factor (pLPF) problem deﬁned for p-strings. Subsequently, we present a linear time solution to construct the pLP F array. Given our pLPF algorithm, we show how to construct the pLCP (parameterized longest common preﬁx) array in linear time. Our algorithm is further exploited to construct the standard LP F and LCP arrays all in linear time. Keywords: parameterized suﬃx array, parameterized longest common preﬁx, p-string, p-match, LPF, LCP.

1

Introduction

Given an n-length traditional string W = W [1]W [2]...W [n] from the alphabet Σ, the longest previous factor (LPF) problem is to determine the maximum length of a previously occurring factor for each suﬃx occurring in W . More formally, for any suﬃx u beginning at index i in the string W , the LPF problem is to identify the length of the longest factor between u and another suﬃx v at some position h before i in W : that is, 1 ≤ h < i. The LPF problem, introduced by Crochemore and Ilie [1], yields a data structure convenient for fundamental applications such as string compression [2] and detecting runs [3] within a string. In order to compute the LP F array, it is shown in [1] that the suﬃx array SA is useful to quickly identify the most lexicographically similar suﬃxes that constitute as previous factors for the chosen suﬃx in question. The use of SA expedites the work required to solve the LPF problem and likewise, is the cornerstone to solutions for many problems deﬁned for traditional strings. A generalization of traditional strings over an alphabet Σ is the parameterized string (p-string), introduced by Baker [4]. A p-string is a production of symbols from the alphabets Σ and Π, which represent the constant symbols and parameter symbols respectively. The parameterized pattern matching

This work was partly supported by a grant from the National Historical Publications & Records Commission.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 31–43, 2011. c Springer-Verlag Berlin Heidelberg 2011

32

R. Beal and D. Adjeroh

(p-match) problem is to identify an equivalence between a pair of p-strings S and T when 1) the individual constant symbols match and 2) there exists a bijection between the parameter symbols of S and T . For example, the following p-strings that represent program statements z=y ∗ f /++y; and a=b ∗ f /++b; over the alphabets Σ = {∗, /, +, =, ; } and Π = {a, b, f, y, z} satisfy both conditions and thus, the p-strings p-match. The motivation for addressing a problem in terms of p-strings is the range of problems that a single solution can address, including 1) exact pattern matching when |Π| = 0, 2) mapped matching (m-matching) when |Σ| = 0 [5], and clearly, 3) p-matching when |Σ| > 0 ∧ |Π| > 0. Prominent applications concerned with the p-match problem include detecting plagiarism in academia and industry, reporting similarities in biological sequences [6], discovering cloned code segments in a program [7], and even answering critical legal questions regarding the unauthorized use of intellectual property [8]. In this work, we introduce the parameterized longest previous factor (pLPF) for p-strings analogous to the LPF problem for traditional strings, which can similarly be used to study compression and duplication within p-strings. Given an n-length p-string T = T [1]T [2]...T [n], the pLPF problem is to determine the longest parameterized suﬃx (p-suﬃx) v at position h for a p-suﬃx starting at i in T with 1 ≤ h < i. Our approach uses a parameterized suﬃx array (pSA) [9,10,11,12] for p-strings analogous to the traditional suﬃx array [13]. The major diﬃculty of the pLPF problem is that unlike traditional suﬃxes of a string, the p-suﬃxes are dynamic, varying with the starting position of the p-suﬃx. Thus, traditional LPF solutions cannot be directly applied to the pLPF problem. Main Contributions: We generalize the LPF problem for traditional strings to the parameterized longest previous factor (pLPF) problem deﬁned for pstrings. Then, we present a linear time algorithm for constructing the pLP F data structure. Traditionally, the LPF problem is solved by using the longest common preﬁx (LCP ) array. This was one approach used in [1]. In this work, we show how to go in the reverse direction: that is, given the pLPF solution, we now construct the pLCP array. Further, we identify how to exploit our algorithm for the pLPF problem to construct the LP F and LCP arrays. Our main results are stated in the following theorems: Theorem 1. Given an n-length p-string T , prevT = prev(T ), the prev encoding of T , and pSA, the parameterized suﬃx array for T , the algorithm compute pLPF constructs the pLP F array in O(n) time. Theorem 2. Given an n-length p-string T , prevT = prev(T ), the prev encoding of T , and pSA, the parameterized suﬃx array for T , the compute pLPF algorithm can be used to construct the pLCP array in O(n) time.

2

Background / Related Work

Baker [7] identiﬁes three types of pattern matching: 1) exact matching, 2) parameterized matching (p-match), and 3) matching with modiﬁcations. The ﬁrst p-match breakthroughs, namely, the prev encoding and the parameterized suﬃx

Parameterized Longest Previous Factor

33

tree (p-suﬃx tree) that demands the worst case construction time of O(n(|Π| + log(|Π| + |Σ|))), were introduced by Baker [4]. Like the traditional suﬃx tree [14,15,16], the p-suﬃx tree [4] implementation suﬀers from a large memory footprint. Other solutions that address the p-match problem without the space limitations of the p-suﬃx tree include the parameterized-KMP [5] and parameterized-BM [17], variants of traditional pattern matching approaches. Idury et al. [18] studied the multiple p-match problem using automata. The parameterized suﬃx array (p-suﬃx array) and the parameterized longest common preﬁx (pLCP ) array combination is analogous to the suﬃx array and LCP array for traditional strings [13,14,15,16], which is both time and space eﬃcient for pattern matching. Direct p-suﬃx array and pLCP construction was ﬁrst introduced by Deguchi et al. [10] for binary strings with |Π| = 2, which required O(n) work. Deguchi and colleagues [9] later proposed the ﬁrst approach to psuﬃx sorting and pLCP construction with an arbitrary alphabet size requiring O(n2 ) time in the worst case. We introduce new algorithms in [11,12] to p-suﬃx sort in linear time on average using coding methods from information theory. Table 1. LPF calculation for string W = AAABABAB$ i 1 2 3 4 5 6 7 8 9

SA[i] 9 1 2 7 5 3 8 6 4

W [SA[i]...n] LCP [i] $ 0 AAABABAB$ 0 AABABAB$ 2 AB$ 1 ABAB$ 2 ABABAB$ 4 B$ 0 BAB$ 1 BABAB$ 3

W [i...n] LP F [i] AAABABAB$ 0 AABABAB$ 2 ABABAB$ 1 BABAB$ 0 ABAB$ 4 BAB$ 3 AB$ 2 B$ 1 $ 0

In a novel application of the suﬃx array and the corresponding LCP array, Crochemore and Ilie [1] introduced the longest previous factor (LPF) problem for traditional strings. Table 1 shows an example LPF for a short sequence W = AAABABAB$. For any suﬃx u beginning at index i in string W , the LPF problem is to identify the exact matching longest factor between u and another suﬃx v starting prior to index i in W . We note that this deﬁnition is similar to (though not the same as) the P rior array used in [14]. Crochemore and Ilie [1] exploited the notion that the nearby elements within a suﬃx array are closely related en route to proposing a linear time solution to the LPF problem. They also proposed another linear time algorithm to compute the LP F array by using the LCP structure. The signiﬁcance of an eﬃcient solution to the LPF is that the resulting data structure simpliﬁes computations in various string analysis procedures. Typical examples include computing the LempelZiv factorization [2,19], which is fundamental in string compression algorithms such as the UNIX gzip utility [14,15] and in algorithms for detecting repeats in a

34

R. Beal and D. Adjeroh

string [3]. Our motivation to study the LPF in terms of p-strings is the power of parameterization with relevance to various important applications.

3

Preliminaries

A string on an alphabet Σ is a production T = T [1]T [2]...T [n] from Σ n with n = |T | the length of T . We will use the following string notations: T [i] refers to the ith symbol of string T , T [i...j] refers to the substring T [i]T [i + 1]...T [j], and T [i...n] refers to the ith suﬃx of T : T [i]T [i + 1]...T [n]. Parameterized pattern matching requires the ﬁnite alphabets Σ and Π. Alphabet Σ denotes the set of constant symbols while Π represents the set of parameter symbols. Alphabets are deﬁned such that Σ ∩ Π = ∅. Furthermore, we append the terminal symbol $∈ / Σ ∪ Π to the end of all strings to clearly distinguish between suﬃxes. For practical purposes, we can assume that |Σ| + |Π| ≤ n since otherwise a single mapping can be used to enforce the condition. Deﬁnition 1. Parameterized String (p-string): A p-string is a production T of length n from (Σ ∪ Π)∗ $. Consider the alphabet arrangements Σ = {A, B} and Π = {w, x, y, z}. Example p-strings include S = AxByABxy$, T = AwBzABwz$, and U = AyByAByy$. Deﬁnition 2. ([4,10]) Parameterized Matching (p-match): A pair of pstrings S and T are p-matches with n = |S| if and only if |S| = |T | and each 1 ≤ i ≤ n corresponds to one of the following: 1. S[i], T [i] ∈ (Σ ∪ {$}) ∧ S[i] = T [i] 2. S[i], T [i] ∈ Π ∧ ((a) ∨ (b)) /* parameter bijection */ (a) S[i] = S[j], T [i] = T [j] for any 1 ≤ j < i (b) S[i] = S[i − q] iﬀ T [i] = T [i − q] for any 1 ≤ q < i In our example, we have a p-match between the p-strings S and T since every constant/terminal symbol matches and there exists a bijection of parameter symbols between S and T . U does not satisfy the parameter bijection to p-match with S or T . The process of p-matching leads to deﬁning the prev encoding. Deﬁnition 3. ([4,10]) Previous (prev) Encoding: Given Z as the set of non-negative integers, the function prev : (Σ ∪ Π)∗ $ → (Σ ∪ Z)∗ $ accepts a p-string T of length n and produces a string Q of length n that 1) encodes constant/terminal symbols with the same symbol and 2) encodes parameters to point to previous like-parameters. More formally, Q is constructed of individual Q[i] with ⎧ 1 ≤ i ≤ n where: ⎨ T [i], if T [i] ∈ (Σ ∪ {$}) 0, if T [i] ∈ Π ∧ T [i] = T [j] for any 1 ≤ j < i Q[i] = ⎩ i − k, if T [i] ∈ Π ∧ k = max{j|T [i] = T [j], 1 ≤ j < i}

Parameterized Longest Previous Factor

35

For a p-string T of length n, the above O(n) space prev encoding requires the construction time of order O(n log(min{n, |Π|})), which follows from the discussions of Baker [4,17] and Amir et al. [5] on the dependency of alphabet Π in p-match applications. Given an indexed alphabet and an auxiliary O(|Π|) mapping structure, we can construct prev in O(n) time. Using Deﬁnition 3, our working examples evaluate to prev(S) = A0B0AB54$, prev(T ) = A0B0AB54$, prev(U ) = A0B2AB31$. The relationship between p-strings and the lexicographical ordering of the prev encoding is fundamental to the p-match problem. Deﬁnition 4. prev Lexicographical Ordering: Given the p-strings S and T and two symbols s and t from the encodings prev(S) and prev(T ) respectively, the relationships =, =, refer to lexicographical ordering between s and t. We deﬁne the ordering of symbols from a prev encoding of the production (Σ ∪ Z)∗ $ to be $ < ζ ∈ Z < σ ∈ Σ, where each ζ and σ is lexicographically sorted in their respective alphabets. The relationships =, =, ≺, and

refer to the lexicographical ordering between strings. In the case of prev(S) and prev(T ), prev(S) ≺ prev(T ) when prev(S)[1] = prev(T )[1], prev(S)[2] = prev(T )[2], ..., prev(S)[j −1] = prev(T )[j −1], prev(S)[j] < prev(T )[j] for some j, j ≥ 1. Similarly, we can deﬁne =k , =k , ≺k , and k to refer to the lexicographical relationships between a pair of p-strings considering only the ﬁrst k ≥ 0 symbols. It is shown in [11,12] how to map a symbol in prev to an integer based on the ordering of Deﬁnition 4 and subsequently, call the function in(x, X) to answer alphabet membership questions of the form x ∈ X in constant time. The following proposition essential to the p-matching problem is directly related to the established symbol ordering. Proposition 1. ([4]) Two p-strings S and T p-match when prev(S) = prev(T ). Also, S ≺ T when prev(S) ≺ prev(T ) and S T when prev(S) prev(T ). The example prev encodings show a p-match between S and T since prev(S) = A0B0AB54$ and prev(T ) = A0B0AB54$. Also, U S and U T since prev(U ) = A0B2AB31$ prev(S) = prev(T ) = A0B0AB54$. We use the ordering established in Deﬁnition 4 to deﬁne the parameterized suﬃx array and the parameterized longest common preﬁx array. Deﬁnition 5. Parameterized Suﬃx Array (pSA): The pSA for a p-string T of length n maintains a lexicographical ordering of the indices i representing individual p-suﬃxes prev(T [i...n]) with 1 ≤ i ≤ n, such that prev(T [pSA[q]...n]) ≺ prev(T [pSA[q + 1]...n])∀q, 1 ≤ q < n. Deﬁnition 6. Parameterized Longest Common Preﬁx (pLCP ) Array: The pLCP array for a p-string T of length n maintains the length of the longest common preﬁx between neighboring p-suﬃxes. We deﬁne plcp(α, β) = max{k|prev(α) =k prev(β)}. Then, pLCP [1] = 0 and pLCP [i] = max{k | plcp (T [pSA[i]...n], T [pSA[i − 1]...n])}, 2 ≤ i ≤ n.

36

R. Beal and D. Adjeroh

For the example T = AwBzABwz$ with prev(T ) = A0B0AB54$, we have pSA = {9, 8, 7, 4, 2, 1, 5, 6, 3} and pLCP = {0, 0, 1, 1, 1, 0, 1, 0, 2}. The encoding prev is supplemented by the encoding forw. Deﬁnition 7. ([11,12]) Forward (forw) Encoding: Let the function rev(T ) reverse the p-string T and repl(T, x, y) replace all occurrences in T of the symbol x with y. We deﬁne the function forw for the p-string T of length n as forw(T ) = rev(repl(prev(rev(T )), 0, n)). For a p-string T of length n, the encoding forw 1) encodes constant/terminal symbols with the same symbol and 2) encodes each parameter p with the forward distance to the next occurrence of p or an unreachable forward distance n. Our deﬁnition of forw generates output mirroring the fw encoding used by Deguchi et al. [9,10]. The forw encodings in our example with n = 9 are forw(S) = A5B4AB99$, forw(T ) = A5B4AB99$, forw(U ) = A2B3AB19$. Deﬁnition 8. ([1]) Longest Previous Factor (LP F ): For an n-length traditional string W , the LPF is deﬁned for each index 1 ≤ i ≤ n such that LP F [i] = max({0} ∪ {k | W [i...n] =k W [h...n], 1 ≤ h < i}). The traditional string W = AAABABAB$ yields LP F = {0, 2, 1, 0, 4, 3, 2, 1, 0}.

4

Parameterized LPF

We deﬁne the parameterized longest previous factor (pLPF) problem as follows to generalize the traditional LPF problem to p-strings. Deﬁnition 9. Parameterized Longest Previous Factor (pLP F ): For a pstring T of length n, the pLPF array is deﬁned for each index 1 ≤ i ≤ n to maintain the length of the longest factor between a p-suﬃx and a previous psuﬃx occurring in T . More formally, pLP F [i] = max({0}∪{k | prev(T [i...n]) =k prev(T [h...n]), 1 ≤ h < i}). The pLPF problem requires that we deal with p-suﬃxes, which are suﬃxes encoded with prev. This task is more demanding than the LPF for traditional strings because Lemma 1 indicates that we cannot guarantee the individual suﬃxes of a single prev encoding to be p-suﬃxes. Thus, the changing nature of the prev encoding poses a major challenge to eﬃcient and correct construction of the pLP F array using current algorithms that construct the LP F array for traditional strings. The proof is provided in [12] and omitted for space. Lemma 1. Given a p-string T of length n, the suﬃxes of prev(T ) are not necessarily the p-suﬃxes of T. More formally, if π ∈ Π occurs more than once in T , then ∃i, s.t. prev(T [i...n]) = prev(T )[i...n], 1 ≤ i ≤ n. Consider the p-string T = AAAwBxyyAAAzwwB$ using the previously deﬁned alphabets. Table 2 shows the pLPF computation for the p-string T . We note the intricacies of Lemma 1 since simply using the traditional LPF algorithm 1)

Parameterized Longest Previous Factor

37

Table 2. pLPF calculation for p-string T = AAAwBxyyAAAzwwB$ i 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

pSA[i] 16 6 12 7 13 8 14 4 11 3 10 2 9 1 15 5

pLCP [i] 0 0 3 1 2 1 1 2 0 2 1 3 2 4 0 1

prev(T [pSA[i]...n]) $ 001AAA001B$ 001B$ 01AAA001B$ 01B$ 0AAA001B$ 0B$ 0B001AAA091B$ A001B$ A0B001AAA091B$ AA001B$ AA0B001AAA091B$ AAA001B$ AAA0B001AAA091B$ B$ B001AAA001B$

bef ore< [pSA[i]] -1 -1 6 6 7 7 8 -1 4 -1 3 -1 2 -1 1 1

bef ore> [pSA[i]] 6 4 7 4 8 4 4 3 3 2 2 1 1 -1 5 -1

pLP F [i] 0 2 1 0 0 1 1 1 4 3 2 3 2 2 1 0

with T yields LP F = {0, 2, 1, 0, 0, 0, 0, 1, 3, 2, 1, 0, 1, 2, 1, 0}, 2) with prev(T ) produces LP F = {0, 2, 1, 0, 0, 1, 1, 0, 4, 3, 2, 1, 0, 1, 1, 0}, and 3) with forw(T ) generates LP F = {0, 2, 1, 0, 0, 0, 0, 1, 3, 2, 1, 3, 2, 1, 1, 0}, neither of which is the correct pLP F array. Crochemore and Ilie [1] eﬃciently solve the LPF problem for a traditional string W by exploiting the properties of the suﬃx array SA. They construct the arrays prev< [1...n] and prev> [1...n], which for each i in W maintain the suﬃx h < i positioned respectively before and after suﬃx i in SA; when no such suﬃx exists, the element is denoted by −1. The conceptual idea to compute the prev< and prev> arrays in linear time via deletions in a doubly linked list of the SA was suggested in [1]. The algorithm is given in [12]. Furthermore, we will refer to prev< and prev> as bef ore< and bef ore> respectively, in order to avoid confusion with the prev encoding for p-strings. Then, LP F [i] is the maximum q between W [i...n] =q W [bef ore< [i]...n] and W [i...n] =q W [bef ore> [i]...n]. The magic of a linear time solution to constructing the LP F array is achieved through the computation of an element by extending the previous element, more formally LP F [i] ≥ LP F [i − 1] − 1, which is a variant of the extension property used in LCP construction proven by Kasai et al. [20]. We prove that this same property holds for the pLPF problem deﬁned on p-strings. Lemma 2. The pLP F for a p-string T of length n is such that pLP F [i] ≥ pLP F [i − 1] − 1 with 1 < i ≤ n. Proof. Consider pLP F [i] at i = 1 by which Deﬁnition 9 requires that we ﬁnd a previous factor at 1 ≤ h < 1 that does not exist; i.e., pLP F [1] = 0. At i = 2, indeed pLP F [2] ≥ pLP F [1] − 1 = −1 is clearly true for all succeeding elements

38

R. Beal and D. Adjeroh

Algorithm 1. pLPF computation 1 2 3 4 5 6 7 8 9 10

i n t [ ] compute pLPF ( i n t b e f o r e < [ ] , i n t b e f o r e > [ ] ) { i n t pLPF [ n ] , pLPF< =0 , pLPF> =0 , i , j , k f o r i = 1 to n { j = max{0 ,pLPF< −1} k = max{0 ,pLPF> −1} i f ( b e f o r e < = null ) pLPF< = Λ ( i , b e f o r e < [ i ] , j ) i f ( b e f o r e > = null ) pLPF> = Λ ( i , b e f o r e > [ i ] , k ) pLPF [ i ] = max{pLPF< ,pLPF> } } return pLPF }

Algorithm 2. p-matcher function Λ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

int Λ( int a , int b , int q ) { boolean c = true int x , y i f ( b = −1) return 0 while ( c ∧ ( a+q ) ≤ n ∧ ( b+q ) ≤ n ) { x = prevT [ a+q ] , y = prevT [ b+q ] i f ( in ( x , Σ ) ∧ in ( y , Σ ) ) { i f ( x = y ) q++ else c = false } e l s e i f ( in ( x , Z ) ∧ in ( y , Z ) ) { if (q < x) x = 0 if (q < y) y = 0 i f ( x = y ) q++ else c = false } else c = false } return q }

in which a previous factor does not exist. For arbitrary i = j with 1 < j < n, suppose that the maximum length factor is at g < j and without loss of generality, consider that the ﬁrst q ≥ 2 symbols match so that prev(T [j...n]) =q prev(T [g...n]). Thus, pLP F [j] = q. Shifting the computation to i = j +1, we lose the symbols prev(T [j]) and prev(T [g]) in the p-suﬃxes at j and g respectively. By Proposition 1, prev(T [j...j + q − 1]) = prev(T [g...g + q − 1]) ⇒ prev(T [j]) = prev(T [g]) and as a consequence of the prev encoding in Deﬁnition 3 we have prev(T [i...n]) =q−1 prev(T [g + 1...n]). Since we can guarantee that ∃ a factor with (q − 1) symbols for pLP F [i] or possibly ﬁnd another factor at h with 1 ≤ h < i matching q or more symbols, the lemma holds. Lemma 2 permits us to adapt the algorithm compute LPF given in [1] to p-strings. We introduce compute pLPF in Algorithm 1 to construct the pLP F array, which makes use of the p-matcher Λ in Algorithm 2 to properly handle the sophisticated

Parameterized Longest Previous Factor

39

matching of p-suﬃxes, the dynamic suﬃxes under the prev encoding. The role of Λ is to extend the matches between the p-suﬃxes at a and b beyond the initial q symbols by directly comparing constant/terminal symbols and comparing the dynamically adjusted parameter encodings for each p-suﬃx. Theorem 1. Given an n-length p-string T , prevT = prev(T ), the prev encoding of T , and pSA, the parameterized suﬃx array for T , the algorithm compute pLPF constructs the pLP F array in O(n) time. Proof. It follows from Lemma 2 that our algorithm exploits the properties of pLPF to correctly compute and extend factors, which requires O(n) time. Computing the arrays bef ore< and bef ore> require O(n) processing [12]. What remains now is to show that, between Algorithm 1 and Algorithm 2, the total number of times that the body of the while loop (lines 6-15 in Algorithm 2) will be executed is in O(n). The number of iterations of the while loop is given by the number of matching symbol comparisons, namely the number of increments of the variable q, which identiﬁes the shift required to compare the current symbol. Without loss of generality, suppose that the initial p-suﬃxes at position a and b are the longest suﬃxes at positions 1 and 2 in T of lengths n and (n − 1) respectively. In the worst case, (n − 1) of the symbols will match between these suﬃxes, by which each comparison that clearly requires O(1) work, will increment q. Lemma 2 indicates that succeeding calculations, or calls to Λ, already match at least (q − 1) symbols that are not rematched and rather, the match is extended. Since the decreasing lengths of the succeeding suﬃxes at 3, 4, ..., n cannot extend the current q, no further matching or increments of q are needed. Hence, the while loop iterates a total of O(n) times amortized across all of the n iterations of the for loop in Algorithm 1. Thus, the total work is O(n). Our algorithm compute pLPF is motivated by the compute LPF algorithm in [1]. We also observe that similar pattern matching mechanisms as the one used between the for loop in Algorithm 1 and the while loop in Algorithm 2 exist in standard string processing, for example in computing the border array discussed in [15].

5

From pLPF to pLCP

Deguchi et al. [9,10] studied the problem of constructing the pLCP array given the pSA. They showed that constructing the pLCP array requires a non-trivial modiﬁcation of the traditional LCP construction by Kasai et al. [20]. In [1], the LCP array was used as the basis for constructing the LP F array for traditional strings. Here, we present a simpler algorithm for constructing the pLCP array. In particular, we show that, unlike in [1], it is possible to go the other way around: that is, given the pLPF solution, we now construct the pLCP array. Later, we show that the same pLPF algorithm can be used to construct the LCP array and the LP F array for traditional strings. Crochemore and Ilie [1] identify that the traditional LP F array is a permutation of the well-studied LCP array. We observe the same relationship in terms of the pLP F and pLCP arrays.

40

R. Beal and D. Adjeroh

Proposition 2. The pLP F array is a permutation of pLCP . This observation allows us to view the pLCP array from a diﬀerent perspective. As a novel use of our compute pLPF algorithm, we introduce a way to construct the pLCP array in linear time. The key observation is that we can integrate the fact that the pLCP occurs between neighboring p-suﬃxes and the fact that we preprocess the bef ore< array, which for each i in the p-string T maintains the p-suﬃx h < i positioned prior to the p-suﬃx i in pSA. We can also construct the array af ter< to maintain the p-suﬃx j > i also positioned prior to the p-suﬃx i in pSA. Since h and j are both positioned prior to i in pSA, we can guarantee that either h or j must be the nearest neighbor to i. So, the maximum factor determines the nearest neighbor and thus, pLCP [R[i]], where R is the inverse of pSA (see Algorithm 3). Theorem 2 shows that this computation is performed in linear time. Algorithm 3. pLCP computation 1 2 3 4 5 6 7 8 9

i n t [ ] compute pLCP ( i n t b e f o r e < [ ] , i n t a f t e r < [ ] ) { i n t pLCP [ n ] , M[ n ] , R[ n ] , i f o r i = 1 to n R[ pSA [ i ] ] = i M = compute pLPF ( b e f o r e < , a f t e r < ) f o r i = 1 to n pLCP [R [ i ] ] = M[ i ] return pLCP }

Theorem 2. Given an n-length p-string T , prevT = prev(T ), the prev encoding of T , and pSA, the parameterized suﬃx array for T , the compute pLPF algorithm can be used to construct the pLCP array in O(n) time. Proof. We can clearly relax the p-suﬃx selection restrictions enforced by the problem pLPF in Lemma 2 to exploit the idea of extending factors. Subsequently, only the parameters of Algorithms 1 and 2 impose such restrictions. Let R[1...n] be the rank array, the inverse of pSA. We prove that the pLCP is constructed with compute pLPF(bef ore< , af ter< ). Let bef ore< [1...n] and af ter< [1...n] maintain, for all the i in T , the p-suﬃxes h < i at position R[h] in pSA and j > i at position R[j] in pSA, respectively, that are positioned prior to the p-suﬃx i at position R[i] in pSA; when no such suﬃx exists, the element is denoted by −1. Without loss of generality, suppose that both h and j exist and 2 < i ≤ n, so we have either R[j] = R[i]−1 or R[h] = R[i]−1 as the neighboring p-suﬃx. So, max{plcp(prev(T [h...n]), prev(T [i...n])), plcp(prev(T [j...n]), prev(T [i...n]))} distinguishes which p-suﬃx h or j is closer to i, identifying the nearest neighbor and in turn, pLCP [R[i]]. This statement is utilized in compute pLPF exactly in terms of factors except that the value will be stored in pLCP [i]. So, after the computation using the call to compute pLPF (line 5) in Algorithm 3, rearranging the resulting array using the rank array R (lines 6-7) produces the required

Parameterized Longest Previous Factor

41

pLCP array. We have yet to prove the time complexity. Since the parameter af ter< can be computed in O(n) by deletions and indexing into a doubly linked list similar to bef ore< [12] and since compute pLPF executes in O(n) time via Theorem 1, the theorem holds. Algorithm 4. Improved pLCP computation 1 2 3 4 5 6 7 8 9 10

i n t [ ] compute pLCP ( ) { i n t pLCP [ n ] , M[ n ] , i M[ pSA [ 1 ] ] = −1 f o r i = 2 to n M[ pSA [ i ] ] = pSA [ i −1] M = compute pLPF (M, null ) f o r i = 1 to n pLCP [ i ] = M[ pSA [ i ] ] return pLCP }

For discussion purposes, Algorithm 3 uses a rank array R to index and preprocess the arrays bef ore< and af ter< to determine the neighboring suﬃx, which can be found trivially with a p-suﬃx array, and thus, may be omitted for practical space. The improved solution is shown in Algorithm 4. For further improved space consumption, the implementation of Algorithm 4 may incorporate the LCP indexing contributions of [21]. In passing, we identify that upon the completion of line 6 in Algorithm 4, the M array is the permuted longest common preﬁx (P LCP ) data structure observed in [22] for traditional strings.

6

From pLPF to LPF and LCP

The power of deﬁning the pLPF problem in terms of p-strings is the generalization of a p-string production. We show in Theorems 3 and 4 that our compute pLPF algorithm also computes the traditional LP F and LCP arrays. Theorem 3. Given an n-length traditional string W , the compute pLPF algorithm constructs the LP F array in O(n) time. Proof. Since W [i] ∈ Σ ∀ i, 1 ≤ i < n and W [n] ∈ {$}, then by Deﬁnition 1 we have W ∈ (Σ ∪Π)∗ $, which classiﬁes W as a valid p-string. Given this, Theorem 1 proves that the construction of pLP F for a p-string requires O(n) time. In this special case, W consists of no such symbol π ∈ Π so Lemma 1 identiﬁes that prev(W [i...n]) = prev(W )[i...n] and further W = prev(W ) by Deﬁnition 3, so W [i...n] = prev(W )[i...n], which constrains the pLPF in Deﬁnition 9 to the LPF problem in Deﬁnition 8. Thus, from Theorem 1, compute pLPF computes the LPF of W . Theorem 4. Given an n-length traditional string W , the compute pLCP algorithm constructs the LCP array in O(n) time.

42

R. Beal and D. Adjeroh

Proof. In the same manner as Theorem 3, we may classify W as a valid pstring. Given this, Theorem 2 proves that the construction of pLCP for a pstring requires O(n) time. Mirroring the proof of Theorem 3, we have W [i...n] = prev(W )[i...n], which constrains the pLCP in Deﬁnition 6 to the traditional LCP problem. Thus, from Theorem 2, compute pLCP computes the LCP of W .

7

Conclusion and Discussion

We introduce the parameterized longest previous factor (pLPF) problem for p-strings, which is analogous to the longest previous factor (LPF) problem deﬁned for traditional strings. A linear time algorithm is provided to construct the pLP F array for a given p-string. The advantage of implementing our solution compute pLPF is that the algorithm may be used to compute the arrays pLP F , pLCP , LP F , LCP , or even the permuted LCP [22] in linear time, which are fundamental data structures preprocessed for the eﬃciency of countless pattern matching applications. Each of the proposed algorithms requires O(n) worst case time and O(n) worst case space. Since we provide construction algorithms for several data structures using the pLP F construction as the groundwork, we are faced with the practical limitation that our algorithms are only as eﬃcient as the compute pLPF solution. We acknowledge that it is possible to use the techniques in [22,23,24] to improve the space consumption of the LCP array and similarly, the pLCP data structure, since pLCP is an array of integers analogous to the traditional LCP . Nonetheless, the signiﬁcance of working though the LPF as an intermediate data structure is the straightforward and space eﬃcient algorithm to construct the Lempel-Ziv (LZ) factorization [1,2,19]. Similarly, the pLP F array can easily derive the LZ structure and allow us to study such applications as maximal runs in p-strings extended to source code plagiarism or redundancies in biological sequences.

References 1. Crochemore, M., Ilie, L.: Computing longest previous factor in linear time and applications. Inf. Process. Lett. 106(2), 75–80 (2008) 2. Ziv, J., Lempel, A.: A universal algorithm for sequential data compression. IEEE Trans. Inf. Theory 23(3), 337–343 (1977) 3. Main, M.: Detecting leftmost maximal periodicities. Discrete Appl. Math. 25(1-2), 145–153 (1989) 4. Baker, B.: A theory of parameterized pattern matching: Algorithms and applications. In: STOC 1993, pp. 71–80. ACM, New York (1993) 5. Amir, A., Farach, M., Muthukrishnan, S.: Alphabet dependence in parameterized matching. Inf. Process. Lett. 49, 111–115 (1994) 6. Shibuya, T.: Generalization of a suﬃx tree for RNA structural pattern matching. Algorithmica 39(1), 1–19 (2004) 7. Baker, B.: Finding clones with dup: Analysis of an experiment. IEEE Trans. Software Eng. 33(9), 608–621 (2007) 8. Zeidman, B.: Software v. software. IEEE Spectr. 47, 32–53 (2010)

Parameterized Longest Previous Factor

43

9. Tomohiro, I., Deguchi, S., Bannai, H., Inenaga, S., Takeda, M.: Lightweight Parameterized Suﬃx Array Construction. In: Fiala, J., Kratochv´ıl, J., Miller, M. (eds.) IWOCA 2009. LNCS, vol. 5874, pp. 312–323. Springer, Heidelberg (2009) 10. Deguchi, S., Higashijima, F., Bannai, H., Inenaga, S., Takeda, M.: Parameterized suﬃx arrays for binary strings. In: PSC 2008, Czech Republic, pp. 84–94 (2008) 11. Beal, R., Adjeroh, D.: p-Suﬃx Sorting as Arithmetic Coding. In: Iliopoulos, C.S., Smyth, W.F. (eds.) IWOCA 2011. LNCS, vol. 7056, pp. 44–56. Springer, Heidelberg (2011) 12. Beal, R.: Parameterized Strings: Algorithms and Data Structures. MS Thesis. West Virginia University (2011) 13. Manber, U., Myers, G.: Suﬃx arrays: A new method for on-line string searches. SIAM J. Comput. 22, 935–948 (1993) 14. Gusﬁeld, D.: Algorithms on Strings, Trees and Sequences: Computer Science and Computational Biology. Cambridge University Press, Cambridge (1997) 15. Smyth, W.: Computing Patterns in Strings. Pearson, New York (2003) 16. Adjeroh, D., Bell, T., Mukherjee, A.: The Burrows-Wheeler Transform: Data Compression, Suﬃx Arrays and Pattern Matching. Springer, New York (2008) 17. Baker, B.: Parameterized pattern matching by Boyer-Moore-type algorithms. In: SODA 1995, pp. 541–550. ACM, Philadelphia (1995) 18. Idury, R., Sch¨ aﬀer, A.: Multiple matching of parameterized patterns. Theor. Comput. Sci. 154, 203–224 (1996) 19. Crochemore, M., Ilie, L., Smyth, W.: A simple algorithm for computing the Lempel Ziv factorization. In: DCC 2008, pp. 482–488 (2008) 20. Kasai, T., Lee, G., et al.: Linear-time Longest-common-preﬁx Computation in Sufﬁx Arrays and its Applications. In: Amir, A., Landau, G.M. (eds.) CPM 2001. LNCS, vol. 2089, pp. 181–192. Springer, Heidelberg (2001) 21. Manzini, G.: Two Space Saving Tricks for Linear Time LCP Array Computation. In: Hagerup, T., Katajainen, J. (eds.) SWAT 2004. LNCS, vol. 3111, pp. 372–383. Springer, Heidelberg (2004) 22. K¨ arkk¨ ainen, J., Manzini, G., Puglisi, S.: Permuted Longest-common-preﬁx Array. In: Kucherov, G., Ukkonen, E. (eds.) CPM 2009 Lille. LNCS, vol. 5577, pp. 181– 192. Springer, Heidelberg (2009) 23. Puglisi, S., Turpin, A.: Space-time Tradeoﬀs for Longest-Common-preﬁx Array Computation. In: Hong, S.-H., Nagamochi, H., Fukunaga, T. (eds.) ISAAC 2008. LNCS, vol. 5369, pp. 124–135. Springer, Heidelberg (2008) 24. Fischer, J.: Wee LCP. Inf. Process. Lett. 110(8-9), 317–320 (2010)

p-Suﬃx Sorting as Arithmetic Coding Richard Beal and Donald Adjeroh Lane Department of Computer Science and Electrical Engineering, West Virginia University, Morgantown, WV 26506 [email protected], [email protected]

Abstract. The challenge of direct parameterized suﬃx sorting (p-suﬃx sorting) for a parameterized string (p-string) is the dynamic nature of parameterized suﬃxes (p-suﬃxes). In this work, we propose transformative approaches to direct p-suﬃx sorting by generating and sorting lexicographically numeric ﬁngerprints and arithmetic codes that correspond to individual p-suﬃxes. Our algorithm to p-suﬃx sort via ﬁngerprints is the ﬁrst theoretical linear time algorithm for p-suﬃx sorting for nonbinary parameter alphabets, which assumes that each code is represented by a practical integer. We eliminate the key problems of ﬁngerprints by introducing an algorithm that exploits the ordering of arithmetic codes to sort p-suﬃxes in linear time on average. Keywords: parameterized suﬃx array, parameterized suﬃx sorting, arithmetic coding, ﬁngerprints, p-string, p-match.

1

Introduction

Conventional pattern matching typically involves the matching of traditional strings over an alphabet Σ. Parameterized pattern matching using parameterized strings, introduced by Baker [1], attempts to answer pattern matching questions beyond its classical counterpart. A parameterized string (p-string) is a production of symbols from the alphabets Σ and Π, which represent the constant symbols and parameter symbols respectively. Given a pair of p-strings S and T , the parameterized pattern matching (p-match) problem is to verify whether the individual constant symbols match and whether there exists a bijection between the parameter symbols of S and T . If the two conditions are met, S is said to be a p-match of T . For example, there exists a p-match between the p-strings z=y ∗ f /++y; and a=b ∗ f /++b; that represent program statements over the alphabets Σ = {∗, /, +, =, ; } and Π = {a, b, f, y, z}. Applications inherent to the p-matching problem include detecting plagiarism in academia and industry, reporting similarities in biological sequences [2], discovering cloned code segments in a program to assist with software maintenance [1], and answering critical legal questions regarding the unauthorized use of intellectual property [3].

This work was partly supported by a grant from the National Historical Publications & Records Commission.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 44–56, 2011. c Springer-Verlag Berlin Heidelberg 2011

p-Suﬃx Sorting as Arithmetic Coding

45

Initial solutions to the p-match problem were based on the parameterized suﬃx tree (p-suﬃx tree) [1]. Idury et al. [4] studied the multiple p-match problem using automata. The physical space requirements of the p-suﬃx tree led to algorithms such as parameterized-KMP [5], parameterized-BM [6], and the parameterized suﬃx array (p-suﬃx array) [7,8]. Analogous to standard suﬃx sorting, the problem of parameterized suﬃx sorting (p-suﬃx sorting) is to sort all the n parameterized suﬃxes (p-suﬃxes) of an n-length p-string into a lexicographic order. The major diﬃculty is that unlike traditional suﬃxes of a string, the p-suﬃxes are dynamic, varying with the starting position of the psuﬃx. Thus, standard suﬃx sorting approaches cannot be directly applied to the p-suﬃx sorting problem. Current approaches to directly construct the p-suﬃx array without a p-suﬃx tree for an n-length p-string from an arbitrary alphabet require O(n2 ) time in the worst case [7]. Such demands the need for alternative approaches to direct p-suﬃx sorting. Main Contribution: We construct p-suﬃx arrays by generating and sorting codes that represent the individual p-suﬃxes of a p-string. We propose the ﬁrst theoretical linear time claims to directly p-suﬃx sort p-strings from non-binary parameter alphabets. We state our main result in the following theorem: Theorem 4. Given a p-string T of length n, p-suﬃx-sorting of T can be accomplished in O(n) time on average via parameterized arithmetic coding.

2

Background / Related Work

Baker [1] deﬁnes pattern matching as either: 1) exact matching, 2) parameterizedmatching, or 3) matching with modiﬁcations. A parameterized match (p-match) is a sophisticated matching scheme based on the composition of a parameterized string (p-string). A p-string is composed of symbols from a constant symbol alphabet Σ and a parameter alphabet Π. A pair of p-strings S and T of length n are said to p-match when the constant symbols σ ∈ Σ match and there exists a bijection of parameter symbols π ∈ Π between the pair of p-strings. Baker [1] oﬀered the ﬁrst p-match breakthroughs, namely, the prev encoding to detect a pmatch and the parameterized suﬃx tree (p-suﬃx tree) analogous to the suﬃx tree for traditional strings [9,10,11]. The p-suﬃx tree is built on the prev encodings of the suﬃxes of the p-string, demanding O(n(|Π|+log(|Π|+|Σ|))) construction time in the worst case [1]. Improvements to the p-suﬃx tree construction were introduced by Kosaraju [12]. Other contributions in the area of parameterized suﬃx trees include constructon via randomized algorithms [13,14]. Like the traditional suﬃx tree [9,10,11], the p-suﬃx tree [1] implementation suﬀers from a large memory footprint. Other solutions that address the p-match problem without the space limitations of the p-suﬃx tree include the parameterized-KMP [5] and parameterized-BM [6], variants of traditional pattern matching approaches. The native time and space eﬃciency of the suﬃx array led to the origination of the parameterized suﬃx array (p-suﬃx array). The p-suﬃx array is analogous to the suﬃx array for traditional strings introduced in [15]. Manber and Myers [15] show how to combine the suﬃx array and the LCP (longest common preﬁx)

46

R. Beal and D. Adjeroh

array to competitively search for pattern P = P [1...m] in a text T = T [1...n] in O(m + log n) time. Direct p-suﬃx array construction was ﬁrst introduced by Deguchi et al. [8] for binary strings with |Π| = 2 requiring O(n) construction time through the assistance of a deﬁned fw encoding. Deguchi and colleagues [7] later proposed the ﬁrst approach to direct p-suﬃx sorting with an arbitrary alphabet size requiring O(n2 ) time in the worst case, without the assistance of a p-suﬃx tree. The parameterized longest common preﬁx (pLCP ) array, analogous to the traditional LCP , was also deﬁned and constructed in [7,8]. In this work, we propose eﬃcient methods to the direct p-suﬃx sorting problem that avoid the large memory footprint of the p-suﬃx tree by using ﬁngerprints and coding methods from information theory.

3

Preliminaries

A string on an alphabet Σ is a production T = T [1]T [2]...T [n] from Σ n with n = |T | the length of T . We will use the following string notations: T [i] refers to the ith symbol of string T , T [i...j] refers to the substring T [i]T [i + 1]...T [j], and T [i...n] refers to the ith suﬃx of T : T [i]T [i + 1]...T [n]. The area of parameterized pattern matching deﬁnes the ﬁnite alphabets Σ and Π. Alphabet Σ denotes the set of constant symbols while Π represents the set of parameter symbols. Alphabets are deﬁned such that Σ∩Π = ∅. Furthermore, we append the terminal symbol $ ∈ / Σ ∪Π to the end of all strings to clearly distinguish between suﬃxes. For practical purposes, we can assume that |Σ|+|Π| ≤ n since, otherwise a single mapping can be used to enforce the condition. Deﬁnition 1. Parameterized String (p-string): A p-string is a production T of length n from (Σ ∪ Π)∗ $. Consider the alphabet arrangements Σ = {A, B} and Π = {w, x, y, z}. Example p-strings include S = AxByABxy$, T = AwBzABwz$, and U = AyByAByy$. Deﬁnition 2. ([1,8]) Parameterized Matching (p-match): A pair of pstrings S and T are p-matches with n = |S| if and only if |S| = |T | and each 1 ≤ i ≤ n corresponds to one of the following: 1. S[i], T [i] ∈ (Σ ∪ {$}) ∧ S[i] = T [i] 2. S[i], T [i] ∈ Π ∧ ((a) ∨ (b)) /* parameter bijection */ (a) S[i] = S[j], T [i] = T [j] for any 1 ≤ j < i (b) S[i] = S[i − q] iﬀ T [i] = T [i − q] for any 1 ≤ q < i In our example, we have a p-match between the p-strings S and T since every constant/terminal symbol matches and there exists a bijection of parameter symbols between S and T . U does not satisfy the parameter bijection to p-match with S or T . The process of p-matching leads to deﬁning the prev encoding.

p-Suﬃx Sorting as Arithmetic Coding

47

Deﬁnition 3. ([1,8]) Previous (prev) Encoding: Given Z as the set of nonnegative integers, the function prev : (Σ ∪Π)∗ $ → (Σ ∪Z)∗ $ accepts a p-string T of length n and produces a string Q of length n that 1) encodes constant/terminal symbols with the same symbol and 2) encodes parameters to point to previous like-parameters. More formally, Q is constructed of individual Q[i] with 1 ≤ i ≤ n where: ⎧ ⎨ T [i], if T [i] ∈ (Σ ∪ {$}) 0, if T [i] ∈ Π ∧ T [i] = T [j] for any 1 ≤ j < i Q[i] = ⎩ i − k, if T [i] ∈ Π ∧ k = max{j|T [i] = T [j], 1 ≤ j < i} For a p-string T of length n, the above O(n) space prev encoding demands the worst case construction time O(n log(min{n, |Π|})), which follows from the discussions of Baker [1,6] and Amir et al. [5] on the dependency of alphabet Π in p-match applications. Note that with an indexed alphabet and an auxiliary O(|Π|) mapping structure, we can construct prev in O(n) time. Using Deﬁnition 3, our examples evaluate to prev(S) = A0B0AB54$, prev(T ) = A0B0AB54$, prev(U ) = A0B2AB31$. The relationship between p-strings and the lexicographical ordering of the prev encoding is fundamental to the p-match problem. Deﬁnition 4. prev Lexicographical Ordering: Given the p-strings S and T and two symbols s and t from the encodings prev(S) and prev(T ) respectively, the relationships =, =, refer to lexicographical ordering between s and t. We deﬁne the ordering of symbols from a prev encoding of the production (Σ ∪ Z)∗ $ to be $ < ζ ∈ Z < σ ∈ Σ, where each ζ and σ is lexicographically sorted in their respective alphabets. The relationships =, =, ≺, and

refer to the lexicographical ordering between strings. In the case of prev(S) and prev(T ), prev(S) ≺ prev(T ) when prev(S)[1] = prev(T )[1], prev(S)[2] = prev(T )[2], ..., prev(S)[j −1] = prev(T )[j −1], prev(S)[j] < prev(T )[j] for some j, j ≥ 1. Similarly, we can deﬁne =k , =k , ≺k , and k to refer to the lexicographical relationships between a pair of p-strings considering only the ﬁrst k ≥ 0 symbols. The following proposition essential to the p-matching problem is directly related to the symbol ordering established in Deﬁnition 4. Proposition 1. ([1]) Two p-strings S and T p-match when prev(S) = prev(T ). Also, S ≺ T when prev(S) ≺ prev(T ) and S T when prev(S) prev(T ). The example prev encodings show a p-match between S and T since prev(S) = A0B0AB54$ and prev(T ) = A0B0AB54$. Also, U S and U T since prev(U ) = A0B2AB31$ > prev(S) = prev(T ) = A0B0AB54$. We use the ordering established in Deﬁnition 4 to deﬁne the parameterized suﬃx array. Deﬁnition 5. Parameterized Suﬃx Array (p-suﬃx array): The p-suﬃx array (pSA) for a p-string T of length n maintains a lexicographical ordering of the indices i representing individual p-suﬃxes prev(T [i...n]) with 1 ≤ i ≤ n, such that prev(T [pSA[q]...n]) ≺ prev(T [pSA[q + 1]...n])∀q, 1 ≤ q < n. The act of constructing pSA is referred to as p-suﬃx sorting.

48

R. Beal and D. Adjeroh

In the working example using T , the p-suﬃx array pSA = {9, 8, 7, 4, 2, 1, 5, 6, 3}. The encoding prev is supplemented by the encoding forw. Deﬁnition 6. Forward (forw) Encoding: Let the function rev(T ) reverse the p-string T and repl(T, x, y) replace all occurrences in T of the symbol x with y. We deﬁne the function forw for the p-string T of length n as forw(T ) = rev(repl(prev(rev(T )), 0, n)). Essentially, forw performs the following on a p-string T of length n: 1) encodes constant/terminal symbols with the same symbol and 2) encodes each parameter p with the forward distance to the next occurrence of p or an unreachable forward distance n. Our deﬁnition of the forw encoding generates output mirroring the fw encoding used by Deguchi et al. [7,8]. Let N refer to the set of positive, non-zero integers. The function fw : (Σ ∪ Π)∗ → (Σ ∪ N)∗ produces an output encoding ⎧ G with fw(T ) = G for each 1 ≤ i ≤ n: ⎨ T [i], if T [i] ∈ Σ G[i] = ∞, if T [i] ∈ Π ∧ T [i] = T [j] for any i < j ≤ n ⎩ k − i, if T [i] ∈ Π ∧ k = min{j|T [i] = T [j], i < j ≤ n} The forw encodings in our example with n = 9 are forw(S) = A5B4AB99$, forw(T ) = A5B4AB99$, forw(U ) = A2B3AB19$.

4

p-Suﬃx Sorting via Fingerprints

The magic of sorting the suﬃxes of a string T of length n from an alphabet Σ is rooted in the notion that individual suﬃxes are very closely related. Throughout this work, we are challenged with the reality that the p-suﬃx, more formally prev(T [i...n]), is not na¨ıvely the suﬃx of the prev encoding of T , namely prev(T )[i...n], which is formalized in Lemma 1. (Given space constraints, we omit the proofs of the lemmas, which are included in [16]). Lemma 1. Given a p-string T of length n, the suﬃxes of prev(T) are not necessarily the p-suﬃxes of T. More formally, if π ∈ Π occurs more than once in T , then ∃i, s.t. prev(T [i...n]) = prev(T )[i...n], 1 ≤ i ≤ n. The centerpiece of this work is the idea that we can directly construct the psuﬃx array without the large memory footprint of the p-suﬃx tree by handling the dynamically changing p-suﬃxes, which is fundamentally diﬀerent from the standard suﬃx sorting approaches for traditional strings. To visually identify the diﬀerence between traditional suﬃxes and p-suﬃxes, consider the example T = zAwz$ as a traditional string, in which the suﬃxes are methodically created by removing a symbol: zAwz$ → Awz$ → wz$ → z$ → $ . If we consider the same example T = zAwz$ with Σ = {A} and Π = {w, z}, then the p-suﬃxes deﬁned under the prev encoding are dynamically changing: 0A03$ → A00$ → 00$ → 0$ → $ . Our idea is to modify the traditional Karp and Rabin (KR) ﬁngerprinting scheme presented in [10,11,17] to accommodate the changing nature of p-suﬃxes.

p-Suﬃx Sorting as Arithmetic Coding

49

The KR algorithm generates an integral KR “signature” or “ﬁngerprint” code to represent a string using the lexicographical ordering of symbols [17]. By representing p-suﬃxes through numeric ﬁngerprints we devise a mechanism to retain a “tangible” copy of the changing p-suﬃxes under the prev encoding. In this section, we assume that n is not too large. That is, the KR codes can ﬁt into standard integer representations such as long long integer. We now denote the following variables that are continually reused throughout this section for the working p-string T of length n: prevT = prev(T ), f orwT = forw(T ), max = maxdist(prevT ) (see below), R = |Σ| + max + 2. Our ﬁngerprinting approach relies on a lexicographical ordering implementation of Deﬁnition 4 to appropriately accommodate the prev alphabet Σ ∪ Z ∪ {$}. Our ordering scheme, function map, is formalized in Deﬁnition 7. Deﬁnition 7. Mapping Function: Let max = maxdist(prevT ) = max{prevT [i] | prevT [i] ∈ Z for 1 ≤ i ≤ n}. Let function αi (x, X) return the lexicographical order (1, 2, ..., |X|) of the symbol x in alphabet X. We then deﬁne the function map : (Σ ∪Z∪{$}) → N to map a symbol, say x, in prevT to an integer preserving the ordering of Deﬁnition 4. We also deﬁne the supplement function in(x, X) to determine⎧if x ∈ X instantaneously based on the deﬁnition of map(x). ⎨ 1, if x = $ αi (x, Z) + 1, if x ∈ Z map(x) = ⎩ α ⎧ i (x, Σ) + max + 2, if x ∈ Σ ⎨ true, if X = Z ∧ (1 < map(x) ≤ max + 2) true, if X = (Σ ∪ {$}) ∧ (map(x) = 1 ∨ map(x) > max + 2) in(x, X) = ⎩ f alse, otherwise The function map is fundamental for the parameterized Karp-Rabin ﬁngerprinting (pKR) algorithm, which generates parameterized Karp-Rabin (pKR) codes. Deﬁnition 8. Parameterized Karp-Rabin (pKR) Function: Let prevTi = i k−1 prev(T [i...n]). We deﬁne pKR(i) = × map(prevTi [n − k + 1]) to k=n R return a ﬁngerprint generated for the p-suﬃx beginning at index i. Table 1 shows example ﬁngerprints using our pKR algorithm and also the standard algorithm KR for the string T = AwBzABwz$. This example shows the true power of our pKR algorithm in that the ordering of the computed ﬁngerprints for p-suﬃxes of T yields the correct p-suﬃx array pSA = {9, 8, 7, 4, 2, 1, 5, 6, 3}. We notice that using KR directly produces the array {1, 4, 5, 2, 3, 6, 7, 9, 8}, which is not the correct p-suﬃx array. The execution of function pKR may be na¨ıvely cascaded to produce ﬁngerprints for all n p-suﬃxes at positions 1 ≤ i ≤ n of p-string T requiring O(n2 ) time, which is a theoretical bottleneck. We can intelligently construct pKR codes for the p-suﬃxes of T by taking advantage of the relationship between p-suﬃxes and pKR codes. Consider qi to be the pKR code for the p-suﬃx at position i. The code qi+1 can be used to compute the ﬁngerprint for qi for i ≥ 1 by introducing a new symbol at position i. Lemmas 2 and 3 identify the adjustments that dynamically change the p-suﬃxes between the neighboring p-suﬃxes at i and (i + 1) when considering a symbol introduced at position i.

50

R. Beal and D. Adjeroh

Table 1. Lexicographical ordering of p-suﬃxes with pKR, using T = AwBzABwz$ i 1 2 3 4 5 6 7 8 9

pSA 9 8 7 4 2 1 5 6 3

T [pSA[i]...n] prev(T [pSA[i]...n]) $ $ z$ 0$ wz$ 00$ zABwz$ 0AB04$ wBzABwz$ 0B0AB54$ AwBzABwz$ A0B0AB54$ ABwz$ AB00$ Bwz$ B00$ BzABwz$ B0AB04$

pKR(pSA[i]) 43046721 90876411 96190821 129298356 130740084 358900444 388608030 398108358 401786973

KR(pSA[i]) 43046721 263063295 330556302 129593601 130740084 358900444 391501431 424148967 401819778

Lemma 2. Given p-string T , prevT = prev(T ), and prevT [i + 1...n] = prev(T [i + 1...n]) where T [i] is a constant, terminal, or the only occurrence of parameter T [i] in T [i...n], then prevT [i...n] = prev(T [i...n]) if prevT [i] = prev(T [i]). Lemma 3. Given p-string T , prevT = prev(T ), f orwT = forw(T ), and prevT [i + 1...n] = prev(T [i + 1...n]) where T [i] ∈ Π occurs multiple times in T [i...n], then prevT [i...n] = prev(T [i...n]) after 1) identifying the current parameter as the ﬁrst occurrence of T [i] (prevT [i] = 0) and 2) modifying the future occurrence of T [i] (prevT [i + f orwT [i]] = f orwT [i]). We refer to a code generated by pKR for the p-suﬃx i as qi . The transitions needed to compute a p-suﬃx i from a p-suﬃx (i + 1) formalized in Lemmas 2 and 3 are subsequently the requirements to compute code qi from qi+1 . These transitions are consolidated into δpKR and shown to eﬃciently generate pKR codes. Deﬁnition 9. Function δpKR : Let β = f orwT [i], λ = (map(β) − map(0)) × q +map(prev(T [i]))Rn Rn−β−1 , and B = i+1 . We deﬁne the function δpKR (i, qi+1 ) as R follows to return the code qi via a transition of the provided code qi+1 with the newly added symbol at position i. B, if in(prevT [i], Σ ∪ {$}) ∨ (in(prevT [i], Z) ∧ f orwT [i] ≥ n) δpKR (i, qi+1 ) = B + λ, if in(prevT [i], Z) ∧ f orwT [i] < n Theorem 1. Given a p-string T of length n and precalculated variables prevT and f orwT , function δpKR requires O(n) time to generate ﬁngerprints for all p-suﬃxes in T . Proof. The ﬁngerprints are generated successively by the function calls qn = δpKR (n, 0), qn−1 = δpKR (n − 1, qn),...,q1 = δpKR (1, q2 ). Either case of function δpKR may be computed in O(1) time and is called sequentially a total of n times, once for each of the n p-suﬃxes. The overall time is O(n). We introduce p suffix sort pKR in Algorithm 1 to sort p-suﬃxes via the sorting of ﬁngerprints through the transition function in Deﬁnition 9. Theorem 2 proves the time complexity of Algorithm 1.

p-Suﬃx Sorting as Arithmetic Coding

51

Theorem 2. Given a p-string T of length n, function p suffix sort pKR sorts all the n p-suﬃxes of T in O(n) time. Proof. We assume that the ﬁngerprints for each p-suﬃx are practically represented by an integer code and each use of the code is accomplished in constant time. Thus, Section A) of p suffix sort pKR follows from Theorem 1 to require O(n) time. The radix sorting required in section B) requires O(cn), where c is a constant. The loop in section C) clearly requires O(n) time. Overall, p suffix sort pKR requires O(n) time. The idea used in Algorithm p suffix sort pKR is novel, but assumes that the pKR ﬁngerprints ﬁt into practical integer representations. This assumption is primarily a limitation inherent to ﬁngerprinting. It is well documented that Karp-Rabin integral ﬁngerprints can be large and exceed the extremes of an integer with large strings and vast alphabets. The modulo operation discussed in [10,11,17] is used to handle this problem. However, the modulo operation will not preserve the lexicographical ordering between ﬁngerprints and creates a new problem with respect to suﬃx sorting. Even if we use ﬁngerprints to encode preﬁxes of p-suﬃxes, the codes can still be quite large with collisions. We extend our idea using arithmetic coding to address these limitations. Algorithm 1. p-suﬃx sorting with ﬁngerprints 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

struct pcode { i n t i , long long i n t pKR } i n t [ ] p suffix sort pKR ( char T [ ] ) { pcode code [ n ] , long long i n t pKR=0 i n t pSA [ n ] , k // A) −− g e n e r a t e t h e i n d i v i d u a l prev f i n g e r p r i n t s f o r k=n to 1 { pKR=δpKR ( k , pKR) code [ k ]=( k , pKR) } // B) −− s o r t p−s u f f i x e s radix sort t h e pKR a t t r i b u t e o f each p a i r i n code // C) −− r e t a i n p−s u f f i x a r r a y f o r k=1 to n pSA [ k]= code [ k ] . i return pSA }

5

p-Suﬃx Sorting via Arithmetic Coding

Arithmetic coding compresses a string by recursively dividing up a real number line into intervals that account for the cumulative distribution function (cdf ), which describes the probability space of each symbol. The interval for an arithmetic code AC is (lo, hi), where lo and hi are the low and high boundaries,

52

R. Beal and D. Adjeroh

respectively. Any consistent choice in this region, say tag(s) = s.hi+s.lo , repre2 sents the arithmetic code and preserves the lexicographical ordering of strings. Arithmetic coding is further described in [18,19]. Recently, Adjeroh and Nan [20] used a novel application of Shannon-Fano-Elias codes from information theory to address the traditional suﬃx sorting problem. In the work, they generate arithmetic codes for m-blocks, or m-length preﬁxes of the suﬃxes, to maintain the ordering of m symbols. They show how to eﬃciently transition one AC m-block code at suﬃx i to construct the m-block AC at suﬃx (i + 1) by removing the symbol at i and appending the symbol at (i + m). The transitioning scheme is illustrated in Fig. 1. In terms of suﬃx sorting with arithmetic codes in [20], the suﬃxes are recursively partitioned and the generated m-block arithmetic codes are exploited to induce the ordering of the partitions in linear time. Extending the suﬃx sorting via arithmetic coding algorithm given in [20] to the p-suﬃx sorting problem is not straightforward because of the dynamic relationship between p-suﬃxes, identiﬁed in Lemma 1.

Fig. 1. Transitioning the AC m-block code from a cab → cab → cab d

Given an n-length p-string T , we can create a parameterized arithmetic code pAC via function pAC from Deﬁnition 10 for the m-blocks, or m-length preﬁxes, of the n p-suﬃxes of T . The distribution of symbols will impact the size of the intervals and hence the tag, but this does not change the order of the generated arithmetic codes. Thus, without loss of generality, we assume that each symbol x ∈ (Σ ∪ Z ∪ {$}) in the alphabet of a prev encoding to be equally probable, where p represents the probability of a symbol and the array cdf contains the values of the uniform cdf with respect to the neighboring lexicographical alphabet symbols. The following deﬁnition modiﬁes the traditional AC algorithm to create an m-block arithmetic code for a p-suﬃx at position i in T . Deﬁnition 10. Parameterized Arithmetic Coding (pAC) Function: For an n-length p-string T , the function pAC in Algorithm 2 will generate an arithmetic code interval for the m-block of the p-suﬃx starting at position i. Table 2 shows the pAC codes for m-blocks of m = 2, 3, n of p-string T = AwBzABwz$. We notice that a “collision” occurs for two pAC codes using

p-Suﬃx Sorting as Arithmetic Coding

53

Algorithm 2. Generating pAC for an m-length preﬁx of p-suﬃx i 1 2 3 4 5 6 7 8 9 10

struct AC { long double l o , long double h i } AC pAC ( i n t i , i n t m) { i n t end=min{ i+m−1 ,n } , k char prevT i [ ] = prev (T [ i . . . end ] ) , AC new = ( 0 , 0 ) , o l d =(0 ,1) f o r k=i to end { new . h i=o l d . l o +( o l d . hi−o l d . l o ) ∗ c d f [ map ( prevTi [ k−i + 1 ] ) ] new . l o=o l d . l o +( o l d . hi−o l d . l o ) ∗ c d f [ map ( prevTi [ k−i +1]) −1] o l d=new } return new }

Table 2. Lexicographical ordering of p-suﬃxes with pAC, using T = AwBzABwz$ i pSA T [pSA[i]...n] prev(T [pSA[i]...n]) 1 2 3 4 5 6 7 8 9

9 8 7 4 2 1 5 6 3

$ $ z$ 0$ wz$ 00$ zABwz$ 0AB04$ wBzABwz$ 0B0AB54$ AwBzABwz$ A0B0AB54$ ABwz$ AB00$ Bwz$ B00$ BzABwz$ B0AB04$

tag(pAC(pSA[i], m)) m=2 m=3 m=n 0.055556 0.055556 0.055556 0.117284 0.117284 0.117284 0.129630 0.124143 0.124143 0.203704 0.209191 0.208743 0.216049 0.211934 0.212459 0.796296 0.801783 0.801384 0.882716 0.878601 0.878076 0.907407 0.903292 0.902683 0.907407 0.911523 0.912083

m = 2 since the m-blocks are equivalent. Even though the pAC codes distinctly sort the n p-suﬃxes of T when m approaches n, we highlight that the practical limitation is arithmetic precision. See [18,20] for handling this problem. In order to use the m-block codes, we must generate them eﬃciently. We denote the m-block arithmetic code at p-suﬃx i by pACi . The idea is to ﬁrst use function pAC to compute pAC1 and use this code to generate the remaining (n − 1) codes, namely pAC2 , pAC3 , ..., and pACn . Iteratively, we will need to adjust the arithmetic codes to 1) remove the old symbol and 2) add the new symbol. These cases are described below. The lemmas are similar in nature to Lemmas 2 and 3 and thus, are omitted for space. Case 1: Removing a symbol s from an arithmetic code m-block requires us to simply delete s when s ∈ Σ or s ∈ Π and does not occur in the m-block. When s ∈ Π and occurs later in the m-block, the code must accommodate for both the removed occurrence and the future occurrence of s. − Deﬁnition 11. Remove Symbol δpAC Transition: Given the AC code A at − m-block i with i + m − 1 ≤ n, δpAC supplies the transition to remove the symbol at

54

R. Beal and D. Adjeroh

position i and provide the new code A of the (m-1)-block at p-suﬃx (i + 1). Let β = f orwT [i], j = i + β, e = min{i + m − 1, n}, λ = (map(β) − map(0)) × pβ+1 , and c = cdf [map(prev(T [i])) −1]. ⎧

A.lo−c A.hi−c ⎪ , ,if (in(prevT [i], Z) ∧ j > e)∨ ⎪ ⎨ p p − in(prevT [i], Σ ∪ {$}) δpAC (i, A) =

⎪ ⎪ ⎩ A.lo−λ−c , A.hi−λ−c ,if in(prevT [i], Z) ∧ j ≤ e p

p

Case 2: Adding (i.e. appending) symbol s to an arithmetic code m-block requires us to simply append the code when s ∈ Σ or s ∈ Π and does not occur in the m-block. When s ∈ Π and occurs previously in the m-block, the code must account for the new occurrence in terms of the previous occurrence of s. + Deﬁnition 12. Add Symbol δpAC Transition: Given the AC code A at (m+ 1)-block (i −m+ 1) ≥ 1, δpAC supplies the transition to add the symbol at position i and provide the new code A of the m-block at p-suﬃx (i − m + 1). Let b = max{1, i−m+1}, k = i−prevT [i], Δ = A.hi−A.lo, d = Δ×cdf [map(prev(T [i]))], f = Δ × cdf [map(prev(T [i])) − 1], v = Δ × cdf [map(prevT [i])], and w = Δ × cdf [map(prevT ⎧ [i]) − 1]) ⎨ (A.lo + f, A.lo + d),if (in(prevT [i], Z) ∧ k < b)∨ + in(prevT [i], Σ ∪ {$}) δpAC (i, A) = ⎩ (A.lo + w, A.lo + v),if in(prevT [i], Z) ∧ k ≥ b

With the assistance of Deﬁnitions 11 and 12, we can eﬃciently generate the m-block codes for all n p-suﬃxes of T . Consider the p-string T = zwzABA$, Σ = {A, B}, Π = {w, z}, and m = 4, we successively generate the m-block codes − δpAC

+ δpAC

in the following fashion: 0 0 2 A → 00A → 00A B → · · · . Theorem 3. Given a p-string T of length n and precalculated variables prevT and f orwT , the pAC codes for all the m-length preﬁxes of the p-suﬃxes require O(n) time to generate. Proof. Generating the ﬁrst m-block code pAC1 via pAC1 = pAC(1, m) will require O(m) time. Iteratively, the neighboring pAC codes will be used to create the successive p-suﬃx codes. The ﬁrst extension of code pAC1 to create − pAC2 will require the removal of prevT [1] via a call to pAC2 = δpAC (1, pAC1 ), which is O(1) work, and the addition of symbol prevT [2 + m − 1] via a call to + pAC2 = δpAC (2 + m − 1, pAC2 ), which also demands O(1) work. This process requiring two O(1) steps is needed for the remaining (n − 1) m-block p-suﬃxes of T . The resulting time is O(m + n). Since m ≤ n, the theorem holds. The eﬃcient preprocessing from Theorem 3 leads to our main result: an average case linear time algorithm for direct p-suﬃx sorting for non-binary parameter alphabets. We discuss the intricacies of worst case p-suﬃx array construction in the conclusions as an area for future work.

p-Suﬃx Sorting as Arithmetic Coding

55

Theorem 4. Given a p-string T of length n, p-suﬃx-sorting of T can be accomplished in O(n) time on average via parameterized arithmetic coding. Proof. We can construct prev(T ) in O(n) time given an indexed alphabet and an O(|Π|) auxiliary data structure. The lexicographical ordering of the m-block pAC codes follow from the notion of arithmetic coding and Deﬁnition 7. From Theorem 3, we can create all the m-block pAC codes in O(n) time. Similar to [20], the individual ﬂoating-point codes may be converted to integer

codes tag(pACi )−tag(pACmin ) di in the range [0, c(n − 1)] by di = c(n − 1) tag(pACmax )−tag(pACmin ) , where the constant c > 1 is chosen to best separate the di and values pACmin and pACmax correspond to the minimum and maximum pAC codes, respectively. From [21,22], we know that an n-length general string has a max longest common preﬁx of O(log|Σ| n). Let x ◦ y be the string concatenation of x and y. Then, Q = prev(T [1...n−1])$◦prev(T [2...n−1])$◦...◦prev(T [n−2...n−1])$◦$ contains each individual p-suﬃx of T . Notice that Q is of length |Q| = n(n+1) ∈ O(n2 ) 2 and since all p-suﬃxes are clearly represented, the symbols of Q may be mapped to a traditional string alphabet, allowing us to use the contribution of [21,22] to obtain the length of the maximum longest common preﬁx for an average string, which is of the same order O(log n2 ) ∈ O(log n). Then by choosing m = O(log n) and generating the m-block pAC codes, only the ﬁrst O(n) radix sort of the di codes is required to diﬀerentiate the p-suﬃxes of an average case string, demanding only O(n) operations.

6

Conclusion and Discussion

Approaching the direct p-suﬃx sorting problem by representing p-suﬃxes with ﬁngerprints and arithmetic codes provides new mechanisms to handle the challenges of the p-string. We proposed a theoretical algorithm using ﬁngerprints to p-suﬃx sort an n-length p-string in O(n) time, with n and the alphabet size constrained in practice. Arithmetic codes were then used to propose an algorithm to p-suﬃx sort p-strings in linear time on average. In terms of direct suﬃx sorting, the time/space tradeoﬀ varies with algorithms. For instance, the algorithm in [23] accomplishes in-place suﬃx sorting in super-linear time, using only space for the suﬃx array and text. On a practical note, our algorithms use space and computation to achieve linear time direct construction of the p-suﬃx array, improving on the time required by the approaches introduced in [7]. With respect to space, our algorithms use an array for the prev encoding, which replaces the text, in addition to an array for pairs of elements representing the numeric codes and suﬃx indices. A future reseach problem is to address the worst case performance by identifying the intricate relationship between the dynamic nature of p-suﬃx partitions with induced sorting, the fundamental mechanism in worst case linear time suﬃx sorting of traditional strings [9,20,24,25].

56

R. Beal and D. Adjeroh

References 1. Baker, B.: A theory of parameterized pattern matching: Algorithms and applications. In: STOC 1993, pp. 71–80. ACM, New York (1993) 2. Shibuya, T.: Generalization of a suﬃx tree for RNA structural pattern matching. Algorithmica 39(1), 1–19 (2004) 3. Zeidman, B.: Software v. software. IEEE Spectr. 47, 32–53 (2010) 4. Idury, R., Sch¨ aﬀer, A.: Multiple matching of parameterized patterns. Theor. Comput. Sci. 154, 203–224 (1996) 5. Amir, A., Farach, M., Muthukrishnan, S.: Alphabet dependence in parameterized matching. Inf. Process. Lett. 49, 111–115 (1994) 6. Baker, B.: Parameterized pattern matching by Boyer-Moore-type algorithms. In: SODA 1995, pp. 541–550. ACM, Philadelphia (1995) 7. Tomohiro, I., Deguchi, S., Bannai, H., Inenaga, S., Takeda, M.: Lightweight Parameterized Suﬃx Array Construction. In: Fiala, J., Kratochv´ıl, J., Miller, M. (eds.) IWOCA 2009. LNCS, vol. 5874, pp. 312–323. Springer, Heidelberg (2009) 8. Deguchi, S., Higashijima, F., Bannai, H., Inenaga, S., Takeda, M.: Parameterized suﬃx arrays for binary strings. In: PSC 2008, Czech Republic, pp. 84–94 (2008) 9. Adjeroh, D., Bell, T., Mukherjee, A.: The Burrows-Wheeler Transform: Data Compression, Suﬃx Arrays and Pattern Matching. Springer, New York (2008) 10. Gusﬁeld, D.: Algorithms on Strings, Trees and Sequences: Computer Science and Computational Biology. Cambridge University Press, Cambridge (1997) 11. Smyth, W.: Computing Patterns in Strings. Pearson, New York (2003) 12. Kosaraju, S.: Faster algorithms for the construction of parameterized suﬃx trees. In: FOCS 1995, pp. 631–637. ACM, Washington, DC (1995) 13. Cole, R., Hariharan, R.: Faster suﬃx tree construction with missing suﬃx links. In: STOC 2000, pp. 407–415. ACM, New York (2000) 14. Lee, T., Na, J.C., Park, K.: On-Line Construction of Parameterized Suﬃx Trees. In: Karlgren, J., Tarhio, J., Hyyr¨ o, H. (eds.) SPIRE 2009. LNCS, vol. 5721, pp. 31–38. Springer, Heidelberg (2009) 15. Manber, U., Myers, G.: Suﬃx arrays: A new method for on-line string searches. SIAM J. Comput. 22, 935–948 (1993) 16. Beal, R.: Parameterized Strings: Algorithms and Data Structures. MS Thesis. West Virginia University (2011) 17. Karp, R., Rabin, M.: Eﬃcient randomized pattern-matching algorithms. IBM J. Res. Dev. 31, 249–260 (1987) 18. Moﬀat, A., Neal, R., Witten, I.: Arithmetic coding revisited. ACM Trans. Inf. Syst. 16, 256–294 (1995) 19. Cover, T., Thomas, J.: Elements of Information Theory. Wiley (1991) 20. Adjeroh, D., Nan, F.: Suﬃx sorting via Shannon-Fano-Elias codes. Algorithms 3(2), 145–167 (2010) 21. Karlin, S., Ghandour, G., et al.: New approaches for computer analysis of nucleic acid sequences. PNAS 80(18), 5660–5664 (1983) 22. Devroye, L., Szpankowski, W., Rais, B.: A note on the height of suﬃx trees. SIAM J. Comput. 21, 48–53 (1992) 23. Franceschini, G., Muthukrishnan, S.: In-Place Suﬃx Sorting. In: Arge, L., Cachin, C., Jurdzi´ nski, T., Tarlecki, A. (eds.) ICALP 2007. LNCS, vol. 4596, pp. 533–545. Springer, Heidelberg (2007) 24. K¨ arkk¨ ainen, J., Sanders, P., Burkhardt, S.: Linear work suﬃx array construction. J. ACM. 53, 918–936 (2006) 25. Manzini, G., Ferragina, P.: Engineering a lightweight suﬃx array construction algorithm. Algorithmca 40, 33–50 (2004)

Periods in Partial Words: An Algorithm Francine Blanchet-Sadri1 , Travis Mandel2 , and Gautam Sisodia3 1

2

Department of Computer Science, University of North Carolina, P.O. Box 26170, Greensboro, NC 27402–6170, USA [email protected] Department of Mathematics, The University of Texas at Austin, 1 University Station, C1200, Austin, TX 78712, USA 3 Department of Mathematics, University of Washington, P.O. Box 354350, Seattle, WA 98195-4350, USA

Abstract. Partial words are ﬁnite sequences over a ﬁnite alphabet that may contain some holes. A variant of the celebrated Fine-Wilf theorem shows the existence of a bound L = L(h, p, q) such that if a partial word of length at least L with h holes has periods p and q, then it has period gcd(p, q). In this paper, we associate a graph with each p- and q-periodic word, and study two types of vertex connectivity on such a graph: modiﬁed degree connectivity and r-set connectivity where r = q mod p. As a result, we give an algorithm for computing L(h, p, q) in the general case.

1

Introduction

The problem of computing periods in words, or ﬁnite sequences of symbols from a ﬁnite alphabet, has important applications in several areas including data compression, coding, computational biology, string searching and pattern matching algorithms. Repeated patterns and related phenomena in words have played over the years a central role in the development of combinatorics on words [1], and have been highly valuable tools for the design and analysis of algorithms. In many practical applications, such as DNA sequence analysis, repetitions admit a certain variation between copies of the repeated pattern because of errors due to mutation, experiments, etc. Approximate repeated patterns, or repetitions where errors are allowed, are playing a central role in diﬀerent variants of string searching and pattern matching problems [2]. Partial words, or ﬁnite sequences that may contain some holes, have acquired importance in this context. A (strong) period of a partial word u over an alphabet A is a positive integer p such that u(i) = u(j) whenever u(i), u(j) ∈ A and i ≡ j mod p (in such a case, we call u p-periodic). In other words, p is a period of u if for all positions i and j congruent modulo p, the letters in these positions are the same or at least one of these positions is a hole.

This material is based upon work supported by the National Science Foundation under Grant No. DMS–0452020.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 57–70, 2011. c Springer-Verlag Berlin Heidelberg 2011

58

F. Blanchet-Sadri, T. Mandel, and G. Sisodia

There are many fundamental results on periods of words. Among them is the well-known periodicity result of Fine and Wilf [3], which determines how long a p- and q-periodic word needs to be in order to also be gcd(p, q)-periodic. More precisely, any word having two periods p, q and length at least p + q − gcd(p, q) has also gcd(p, q) as a period. Moreover, the length p + q − gcd(p, q) is optimal since counterexamples can be provided for shorter lengths, that is, there exists an optimal word of length p + q − gcd(p, q) − 1 having p and q as periods but not having gcd(p, q) as period [1]. Extensions of Fine and Wilf’s result to more than two periods have been given. For instance, in [4], Constantinescu and Ilie give an extension for an arbitrary number of periods and prove that their lengths are optimal. Fine and Wilf’s result has been generalized to partial words [5,6,7,8,9,10,11]. Some of these papers are concerned with weak periodicity, a notion not discussed in this paper. The papers that are concerned with strong periodicity refer to the basic fact, proved by Shur and Konovalova (Gamzova) in [10], that for positive integers h, p and q, there exists a positive integer l such that a partial word u with h holes, two periods p and q, and length at least l has period gcd(p, q). The smallest such integer is called the optimal length and it will be denoted by L(h, p, q). They gave a closed formula for the case where h = 2 (the cases h = 0 or h = 1 are implied by the results in [3,5]), while in [9], they gave a formula in the case where p = 2 as well as an optimal asymptotic bound for L(h, p, q) in the case where h is “large.” In [7], Blanchet-Sadri et al. gave closed formulas for the optimal lengths when q is “large,” whose proofs are based on connectivity in the so-called (p, q)-periodic graphs. In this paper, we study two types of vertex connectivity in these graphs: the modiﬁed degree connectivity and r-set connectivity where r = q mod p. Although the graph-theoretical approach is not completely new, the paper gives insights into periodicity in partial words and provides an algorithm for determining L(h, p, q) in all cases. We end this section by reviewing basic concepts on partial words. Fixing a nonempty ﬁnite set of letters or an alphabet A, ﬁnite sequences of letters from A are called (full) words over A. The number of letters in a word u, or length of u, is denoted by |u|. The unique word of length 0, denoted by ε, is called the empty word. The set of all words over A of ﬁnite length is denoted by A∗ . A partial word u of length n over A is a partial function u : {0, . . . , n − 1} → A. For 0 ≤ i < n, if u(i) is deﬁned, then i belongs to the domain of u, denoted by i ∈ D(u), otherwise i belongs to the set of holes of u, denoted by i ∈ H(u). For convenience, we will refer to a partial word over A as a word over the enlarged alphabet A = A ∪ {}, where ∈ A represents a “do not know” symbol or hole.

2

(p, q)-Periodic Graphs

In this section, we discuss the fundamental property of periodicity, the goal of our paper which is to describe an algorithm to compute L(h, p, q) in all cases, and some initial results. We can restrict our attention to the case where p and q are coprime, since it is well-known that the general case can be reduced to the coprime case (see, for example, [5,9]). Also, we assume without loss of generality

Periods in Partial Words: An Algorithm

59

that 1 < p < q. Fine and Wilf show that L(0, p, q) = p + q − gcd(p, q) [3], Berstel and Boasson that L(1, p, q) = p + q [5], and Shur and Konovalova prove L(2, p, q) to be 2p + q − gcd(p, q) [10]. Other results include the following. Theorem 1 ([7,9]). For 0 ≤ m < q, L(nq + m, 2, q) = (2n + 1)q + m + 1. Theorem 2 ([7]). If q > x(p, h) where x(p, h) is p( h2 ) if h is even and p( h+1 ) 2 if h is odd, then p( h+2 if h is even; 2 ) + q − gcd(p, q), L(h, p, q) = h+1 p( 2 ) + q, if h is odd. The problem of ﬁnding L(h, p, q) is equivalent to a problem involving the vertex connectivity of certain graphs, as described in [7], which we now discuss. We can represent the periodic structure of a full word with two periods through a graph associated with the word. The (p, q)-periodic graph of size l is the graph G = (V, E) where V = {0, 1, . . . , l − 1} and for i, j ∈ V , the pair {i, j} ∈ E if and only if i ≡ j mod p or i ≡ j mod q. The degree of a vertex i ∈ V , denoted d(i), is the number of vertices connected to i, that is, l − 1 − i mod p l − 1 − i mod q l − 1 − i mod pq d(i) = + − . p q pq The ﬁrst term gives the number of p-connections, the second term the number of q-connections, and the third term the number of pq-connections.

Fig. 1. The (3, 4)-periodic graph of size 11. The bold connections are q-edges, while the lighter ones are p-edges.

The (p, q)-periodic graph of size l can be thought to represent a full word of length l with periods p and q, with the vertices corresponding to positions of the

60

F. Blanchet-Sadri, T. Mandel, and G. Sisodia

word, and the edges corresponding to the equalities between letters of the word forced by one of the periods. For example, we see that if the (p, q)-periodic graph of size l is connected, then a word of length l with periods p and q is 1-periodic, because there exists a path between every pair of vertices, thus the word is over a singleton alphabet. A graph has vertex connectivity κ if it can be disconnected with a suitable choice of κ vertex removals, but cannot be disconnected by any choice of κ − 1 vertex removals. Note that a hole in a partial word u of length l with periods p and q corresponds to the removal of the associated vertex from the (p, q)-periodic graph of size l. Thus our search for L(h, p, q) (when gcd(p, q) = 1) can be restated in terms of vertex connectivity. Lemma 1. The length L(h, p, q) is the smallest l such that the (p, q)-periodic graph of size l has vertex connectivity at least h + 1. If G = (V, E) is the (p, q)-periodic graph of size l, then the p-class of vertex i is {j ∈ V | j ≡ i mod p}. A p-connection (or p-edge) is an edge {i, j} ∈ E such that i ≡ j mod p. If an edge {i, j} is a p-connection, then i and j are considered p-connected. Similar statements hold for q-classes, q-connections and pq-classes, pq-connections. Throughout the paper, we will ﬁnd it useful to group together p-classes whose smallest elements are congruent modulo r where r = q mod p. We do so by introducing the r-set of vertex i, where i ∈ {0, 1, . . . , r − 1}, which is the set 0≤j

Editorial Board David Hutchison Lancaster University, UK Takeo Kanade Carnegie Mellon University, Pittsburgh, PA, USA Josef Kittler University of Surrey, Guildford, UK Jon M. Kleinberg Cornell University, Ithaca, NY, USA Alfred Kobsa University of California, Irvine, CA, USA Friedemann Mattern ETH Zurich, Switzerland John C. Mitchell Stanford University, CA, USA Moni Naor Weizmann Institute of Science, Rehovot, Israel Oscar Nierstrasz University of Bern, Switzerland C. Pandu Rangan Indian Institute of Technology, Madras, India Bernhard Steffen TU Dortmund University, Germany Madhu Sudan Microsoft Research, Cambridge, MA, USA Demetri Terzopoulos University of California, Los Angeles, CA, USA Doug Tygar University of California, Berkeley, CA, USA Gerhard Weikum Max Planck Institute for Informatics, Saarbruecken, Germany

7056

Costas S. Iliopoulos William F. Smyth (Eds.)

Combinatorial Algorithms 22nd International Workshop, IWOCA 2011 Vancouver, BC, Canada, July 20-22, 2011 Revised Selected Papers

13

Volume Editors Costas S. Iliopoulos King’s College London Department of Informatics Strand, London WC2R 2LS, UK E-mail: [email protected] and Curtin University Digital Ecosystems and Business Intelligence Institute Perth WA 6845, Australia William F. Smyth McMaster University Department of Computing and Software Hamilton, ON L8S 4K1, Canada E-mail: [email protected] and Curtin University Digital Ecosystems and Business Intelligence Institute Perth WA 6845, Australia

ISSN 0302-9743 e-ISSN 1611-3349 ISBN 978-3-642-25010-1 e-ISBN 978-3-642-25011-8 DOI 10.1007/978-3-642-25011-8 Springer Heidelberg Dordrecht London New York Library of Congress Control Number: 2011939494 CR Subject Classiﬁcation (1998): G.2.1, G.2.2, I.1, I.3.5, F.2, E.1, E.4, H.1 LNCS Sublibrary: SL 1 – Theoretical Computer Science and General Issues

© Springer-Verlag Berlin Heidelberg 2011 This work is subject to copyright. All rights are reserved, whether the whole or part of the material is concerned, speciﬁcally the rights of translation, reprinting, re-use of illustrations, recitation, broadcasting, reproduction on microﬁlms or in any other way, and storage in data banks. Duplication of this publication or parts thereof is permitted only under the provisions of the German Copyright Law of September 9, 1965, in its current version, and permission for use must always be obtained from Springer. Violations are liable to prosecution under the German Copyright Law. The use of general descriptive names, registered names, trademarks, etc. in this publication does not imply, even in the absence of a speciﬁc statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use. Typesetting: Camera-ready by author, data conversion by Scientiﬁc Publishing Services, Chennai, India Printed on acid-free paper Springer is part of Springer Science+Business Media (www.springer.com)

Preface

This volume contains the papers presented at IWOCA 11: the 22nd International Workshop on Combinatorial Algorithms The 22nd IWOCA was held July 20–22, 2011 on the green and spacious campus of the University of Victoria (UVic), itself located on green and spacious Vancouver Island, oﬀ the coast of British Columbia, a few scenic kilometers by ferry from the city of Vancouver. The meeting was sponsored and supported ﬁnancially by the Paciﬁc Institute for the Mathematical Sciences (PIMS); hosted by the UVic Department of Computer Science. The Local Arrangements Committee, cochaired by Wendy Myrvold and Venkatesh Srinivasan, did an outstanding job; the Program Committee was cochaired by Costas Iliopoulos and Bill Smyth; the intricacies of EasyChair were handled by German Tischler. IWOCA descends from the original Australasian Workshop on Combinatorial Algorithms, ﬁrst held in 1989, then renamed “International” in 2007 in response to consistent interest and support from researchers outside the Australasian region. The workshop’s permanent website can be accessed at iwoca.org, where links to previous meetings, as well as to IWOCA 2011, can be found. The IWOCA 2011 call for papers was distributed around the world, resulting in 71 submitted papers. The EasyChair system was used to facilitate management of submissions and refereeing, with three referees selected from the 40member Program Committee assigned to each paper. A total of 30 papers were accepted, subject to revision, for presentation at the workshop. The workshop also featured a problem session, chaired — in the absence of IWOCA Problems Cochairs Yuqing Lin and Zsuzsanna Liptak — by UVic graduate student Alejandro Erickson. Four invited talks were given by Tetsuo Asano on “Nearest Larger Neighbors Problem and Memory-Constrained Algorithms,” Pavol Hell on “Graph Partitions,” J. Ian Munro on “Creating a Partial Order and Finishing the Sort, with Graph Entropy” and Cenk Sahinalp on “Algorithmic Methods for Structural Variation Detection Among Multiple High-Throughput Sequenced Genomes.” The 51 registered participants at IWOCA 2011 hold appointments at institutions in 15 diﬀerent countries on four continents (Asia, Australia, Europe, North America). The nations represented were: Australia (2), Canada (28), China (1), Czech Republic (2), Denmark (1), France (1), Germany (3), India (2), Israel (1), Iran (1), Italy (1), Japan (1), Russia (1), Taiwan (1), USA (5). Atypical for IWOCA, the contributed talks were split into concurrent streams, A (Combinatorics) and B (Graph Theory). This strategy allowed 30-minute talks and so encouraged a relaxed atmosphere; still, one was often forced to choose between two attractive alternatives. Stream A included such topic areas as combinatorics on words, string algorithms, codes, Venn diagrams, set partitions;

VI

Preface

Stream B dealt with several graph theory areas of current interest: Hamiltonian & Eulerian properties, graph drawing, coloring, dominating sets, spanning trees, and others. We wish to thank the authors for their contributions: the quality of their papers made IWOCA exceptional this year. We would also like to thank the referees for their thorough, constructive and helpful comments and suggestions on the manuscripts. August 2011

Costas S. Iliopoulos Bill F. Smyth

Organization

Program Committee Faisal Abu-Khzam Amihood Amir Subramanian Arumugam Hideo Bannai Ljiljana Brankovic Gerth Stølting Brodal Charles Colbourn Maxime Crochemore Diane Donovan Alan Frieze Dalibor Froncek Roberto Grossi Sylvie Hamel Jan Holub Seok-Hee Hong Costas Iliopoulos Ralf Klasing Rao Kosaraju Marcin Kubica Anna Lubiw Mirka Miller Laurent Mouchard Ian Munro Wendy Myrvold Kunsoo Park Simon Puglisi Rajeev Raman Frank Ruskey Jeﬀrey Shallit Michiel Smid Bill Smyth Iain Stewart Gabor Tardos German Tischler

Lebanese American University, Lebanon Bar-Ilan University and Johns Hopkins University, Israel/USA Kalasalingam University, India Kyushu University, Japan University of Newcastle, UK Aarhus University, Dem Arizona State University, USA King’s College London, UK and Universit´e Paris-Est, France University of Queensland, Australia Carnegie Mellon University, USA University of Minnesota Duluth, USA Universit` a di Pisa, Italy University of Montreal, Canada Czech Technical University in Prague, Czech Republic University of Sydney, Australia King’s College London, UK LaBRI - CNRS, France Johns Hopkins University, USA Warsaw University, Poland University of Waterloo, Canada University of Newcastle, UK University of Rouen, France University of Waterloo, Canada University of Victoria, Canada Seoul National University, Korea Royal Melbourne Institute of Technology, Australia University of Leicester, UK University of Victoria, Canada University of Waterloo, Canada Carleton University, Canada McMaster University, Canada Durham University, UK Simon Fraser University, Canada King’s College London, UK

VIII

Organization

Alexander Tiskin Eli Upfal Lynette Van Zijl Koichi Wada Sue Whitesides Christos Zaroliagis

University of Warwick, UK Brown University, USA Stellenbosch University, South Africa Nagoya Institute of Technology, Japan University of Victoria, Canada CTI University of Patras, Greece

Additional Reviewers Barbay, J´er´emy Battaglia, Giovanni Beveridge, Andrew Blin, Guillaume Boeckenhauer, Hans-Joachim Broersma, Hajo Cadilhac, Micha¨el Chauve, Cedric Cooper, Colin Cordasco, Gennaro Erickson, Alejandro Erlebach, Thomas Fotakis, Dimitris Foucaud, Florent Franceschini, Gianni Frieze, Alan Golovach, Petr Greene, John Gupta, Anupam Hahn, Gena Hoﬀmann, Michael Huang, Jing Izumi, Taisuke Izumi, Tomoko Kalvoda, Tomas Katayama, Yoshiaki Klouda, Karel Kontogiannis, Spyros Korf, Richard Kyncl, Jan

Langiu, Alessio Loh, Po-Shen Macgillivray, Gary Mamakani, Khalegh Marshall, Kim Martin, Barnaby Mcfarland, Robert Merlini, Donatella Mertzios, George B. Moemke, Tobias Ono, Hirotaka Phanalasy, Oudone Pineda-Villavicencio, Guillermo Pissis, Solon Prencipe, Giuseppe Puglisi, Simon Radoszewski, Jakub Radzik, Tomasz Razgon, Igor Rylands, Leanne Sau, Ignasi Steinhofel, Kathleen Teska, Jakub Theodoridis, Evangelos Tsichlas, Kostas Vandin, Fabio Vialette, St´ephane Wallis, Wal Yamashita, Yasushi Yuster, Raphael

Table of Contents

Weighted Improper Colouring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Julio Araujo, Jean-Claude Bermond, Fr´ed´eric Giroire, Fr´ed´eric Havet, Dorian Mazauric, and Remigiusz Modrzejewski

1

Algorithmic Aspects of Dominator Colorings in Graphs . . . . . . . . . . . . . . . S. Arumugam, K. Raja Chandrasekar, Neeldhara Misra, Geevarghese Philip, and Saket Saurabh

19

Parameterized Longest Previous Factor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Richard Beal and Donald Adjeroh

31

p-Suﬃx Sorting as Arithmetic Coding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Richard Beal and Donald Adjeroh

44

Periods in Partial Words: An Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . Francine Blanchet-Sadri, Travis Mandel, and Gautam Sisodia

57

The 1-Neighbour Knapsack Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Glencora Borradaile, Brent Heeringa, and Gordon Wilfong

71

A Golden Ratio Parameterized Algorithm for Cluster Editing . . . . . . . . . . Sebastian B¨ ocker

85

Stable Sets of Threshold-Based Cascades on the Erd˝os-R´enyi Random Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ching-Lueh Chang and Yuh-Dauh Lyuu

96

How Not to Characterize Planar-Emulable Graphs . . . . . . . . . . . . . . . . . . . Markus Chimani, Martin Derka, Petr Hlinˇen´y, and Matˇej Klus´ aˇcek

106

Testing Monotone Read-Once Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . Dmitry V. Chistikov

121

Complexity of Cycle Transverse Matching Problems . . . . . . . . . . . . . . . . . . Ross Churchley, Jing Huang, and Xuding Zhu

135

Eﬃcient Conditional Expectation Algorithms for Constructing Hash Families . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Charles J. Colbourn

144

2-Layer Right Angle Crossing Drawings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Emilio Di Giacomo, Walter Didimo, Peter Eades, and Giuseppe Liotta

156

X

Table of Contents

Hamiltonian Orthogeodesic Alternating Paths . . . . . . . . . . . . . . . . . . . . . . . Emilio Di Giacomo, Luca Grilli, Marcus Krug, Giuseppe Liotta, and Ignaz Rutter

170

Ranking and Loopless Generation of k-ary Dyck Words in Cool-lex Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stephane Durocher, Pak Ching Li, Debajyoti Mondal, and Aaron Williams

182

Two Constant-Factor-Optimal Realizations of Adaptive Heapsort . . . . . . Stefan Edelkamp, Amr Elmasry, and Jyrki Katajainen

195

A Unifying Property for Distribution-Sensitive Priority Queues . . . . . . . . Amr Elmasry, Arash Farzan, and John Iacono

209

Enumerating Tatami Mat Arrangements of Square Grids . . . . . . . . . . . . . . Alejandro Erickson and Mark Schurch

223

Quasi-Cyclic Codes over F13 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . T. Aaron Gulliver

236

Acyclic Colorings of Graph Subdivisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . Debajyoti Mondal, Rahnuma Islam Nishat, Sue Whitesides, and Md. Saidur Rahman

247

Kinetic Euclidean Minimum Spanning Tree in the Plane . . . . . . . . . . . . . . Zahed Rahmati and Alireza Zarei

261

Generating All Simple Convexly-Drawable Polar Symmetric 6-Venn Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Khalegh Mamakani, Wendy Myrvold, and Frank Ruskey

275

The Rand and Block Distances of Pairs of Set Partitions . . . . . . . . . . . . . . Frank Ruskey and Jennifer Woodcock

287

On Minimizing the Number of Label Transitions around a Vertex of a Planar Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ˇ Bojan Mohar and Petr Skoda

300

A New View on Rural Postman Based on Eulerian Extension and Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Manuel Sorge, Ren´e van Bevern, Rolf Niedermeier, and Mathias Weller

310

Hamilton Cycles in Restricted Rotator Graphs . . . . . . . . . . . . . . . . . . . . . . . Brett Stevens and Aaron Williams

324

Eﬃcient Codon Optimization with Motif Engineering . . . . . . . . . . . . . . . . . Anne Condon and Chris Thachuk

337

Table of Contents

XI

An Algorithm for Road Coloring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A.N. Trahtman

349

Complexity of the Cop and Robber Guarding Game . . . . . . . . . . . . . . . . . . ˇamal, Rudolf Stolaˇr, and Tomas Valla Robert S´

361

Improved Steiner Tree Algorithms for Bounded Treewidth . . . . . . . . . . . . . Markus Chimani, Petra Mutzel, and Bernd Zey

374

Author Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

387

Weighted Improper Colouring Julio Araujo1,2 , Jean-Claude Bermond1, Fr´ed´eric Giroire1 , Fr´ed´eric Havet1 , Dorian Mazauric1 , and Remigiusz Modrzejewski1 2

1 Mascotte, joint project I3S(CNRS/Univ. de Nice)/INRIA, France ParGO Research Group - Universidade Federal do Cear´a - UFC, Brazil

Abstract. In this paper, we study a colouring problem motivated by a practical frequency assignment problem and up to our best knowledge new. In wireless networks, a node interferes with the other nodes the level of interference depending on numerous parameters: distance between the nodes, geographical topography, obstacles, etc. We model this with a weighted graph G where the weights on the edges represent the noise (interference) between the two endnodes. The total interference in a node is then the sum of all the noises of the nodes emitting on the same frequency. A weighted t-improper k-colouring of G is a k-colouring of the nodes of G (assignment of k frequencies) such that the interference at each node does not exceed some threshold t. The Weighted Improper Colouring problem, that we consider here consists in determining the weighted t-improper chromatic number defined as the minimum integer k such that G admits a weighted t-improper k-colouring. We also consider the dual problem, denoted the Threshold Improper Colouring problem, where given a number k of colours (frequencies) we want to determine the minimum real t such that G admits a weighted t-improper k-colouring. We show that both problems are NP-hard and first present general upper bounds; in particular we show a generalisation of Lov´asz’s Theorem for the weighted t-improper chromatic number. We then show how to transform an instance of the Threshold Improper Colouring problem into another equivalent one where the weights are either 1 or M, for a sufficient big value M. Motivated by the original application, we study a special interference model on various grids (square, triangular, hexagonal) where a node produces a noise of intensity 1 for its neighbours and a noise of intensity 1/2 for the nodes that are at distance 2. Consequently, the problem consists of determining the weighted t-improper chromatic number when G is the square of a grid and the weights of the edges are 1, if their end nodes are adjacent in the grid, and 1/2 otherwise. Finally, we model the problem using linear integer programming, propose and test heuristic and exact Branch-and-Bound algorithms on random cell-like graphs, namely the Poisson-Voronoi tessellations.

1 Introduction Let G = (V, E) be a graph. A k-colouring of G is a function c : V → {1, . . . , k}. The colouring c is proper if uv ∈ E implies c(u) = c(v). The chromatic number of G, denoted by χ(G), is the minimum integer k such that G admits a proper k-colouring. The goal

This work was partially supported by r´egion PACA, ANR Blanc AGAPE and ANR International Taiwan GRATEL.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 1–18, 2011. c Springer-Verlag Berlin Heidelberg 2011

2

J. Araujo et al.

of the V ERTEX C OLOURING problem is to determine χ(G) for a given graph G. It is a well-known NP-hard problem [11]. A k-colouring c is l-improper if |{v ∈ N(u) | c(v) = c(u)}| ≤ l for all u ∈ V . Given a non-negative integer l, the l-improper chromatic number of a graph G, denoted by χl (G), is the minimum integer k such that G has an l-improper k-colouring. For given graph G and integer l, the I MPROPER C OLOURING problem consists in determining χl (G) [14, 6] and is also NP-hard. Indeed, if l = 0, observe that χ0 (G) = χ(G). Consequently, V ERTEX C OLOURING is a particular case of I MPROPER C OLOURING. In this work we define and study a new variation of the improper colouring problem for edge-weighted graphs. Given an edge-weighted graph G = (V, E, w), w : E → R∗+ , a threshold t ∈ R+ , and a colouring c, we note the interference of a vertex w in this colouring as: Iu (G, w, c) =

∑

w(u, v).

{v∈N(u)|c(v)=c(u)}

We say that c is a weighted t-improper k-colouring of G if c is a k-colouring of G such that Iu (G, w, c) ≤ t, for all u ∈ V . Given a threshold t ∈ R∗+ , the minimum integer k such that the graph G admits a weighted t-improper k-colouring is the weighted t-improper chromatic number of G, denoted by χt (G, w). Given an edge-weighted graph G = (V, E, w) and a threshold t ∈ R∗+ , determining χt (G, w) is the goal of the W EIGHTED I MPROPER C OLOUR ING problem. Note that if t = 0 then χ0 (G, w) = χ(G), and if w(e) = 1 for all e ∈ E, then χl (G, w) = χl (G) for any positive integer l. Therefore, the W EIGHTED I MPROPER C OLOURING problem is clearly NP-hard since it generalises V ERTEX C OLOURING and I MPROPER C OLOURING . On the other hand, we define the minimum k-threshold of G, denoted by ωk (G, w) as the minimum real t such that G admits a weighted t-improper k-colouring. Then, for a given edge-weighted graph G = (V, E, w) and a positive integer k, the T HRESHOLD I MPROPER C OLOURING problem consists of determining ωk (G, w). Motivation. Our initial motivation to these problems was the design of satellite antennas for multi-spot MFTDMA satellites [2]. In this technology, satellites transmit signals to areas on the ground called spots. These spots form a grid-like structure which is modelled by an hexagonal cell graph. To each spot is assigned a radio channel or colour. Spots are interfering with other spots having the same channel and a spot can use a colour only if the interference level does not exceed a given threshold t. The level of interference between two spots depends on their distance. The authors of [2] introduced a factor of mitigation γ and the interferences of remote spots are reduced by a factor 1 − γ. When the interference level is too low, the nodes are considered to not interfere anymore. Considering such types of interferences, where nodes at distance at most i interfere, leads to the study of the i-th power of the graph modelling the network and a case of special interest is the power of grid graphs (see Section 3). Related Work. Our problems are particular cases of the FREQUENCY A SSIGNMENT P ROBLEM (FAP). FAP has several variations that were already studied in the literature (see [1] for a survey). In most of these variations, the main constraint to be satisfied is that if two vertices (mobile phones, antennas, spots, etc.) are close, then the difference

Weighted Improper Colouring

3

between the frequencies that are assigned to them must be greater than some function that usually depends on their distance. There is a strong relationship between most of these variations and the L(p1 , . . . , pd )LABELLING PROBLEM [15]. In this problem, the goal is to find a colouring of the vertices of a given graph G in such a way that the difference between the colours assigned to vertices at distance i must be at least pi , for every i = 1, . . . , d. For some other variations, for each non-satisfied interference constraint a penalty must be paid. In particular, the goal of the M INIMUM I NTERFERENCE A SSIGNMENT P ROBLEM (MI-FAP) is to minimise the total penalties that must be paid, when the number of frequencies to be assigned is given. This problem can also be studied for only co-channel interferences, in which the penalties are applied only if the two vertices have the same frequency. However, MI-FAP under these constraints does not correspond to W EIGHTED I MPROPER C OLOURING, because we consider the co-channel interference, i.e. penalties, just between each vertex and its neighbourhood. The two closest related works we found in the literature are [13] and [7]. However, they both apply penalties over co-channel interference, but also to the adjacent channel interference, i.e. when the colours of adjacent vertices differ by one unit. Moreover, their results are not similar to ours. In [13], they propose an enumerative algorithm for the problem, while in [7] a Branch-and-Cut method is proposed and applied over some instances. Results In this article, we study both parameters χt (G, w) and ωk (G, w). We first show that T HRESHOLD I MPROPER COLOURING is NP-hard. Then we present general upper bounds; in particular we show a generalisation of Lov´asz’ Theorem for χt (G, w). We then show how to transform an instance into an equivalent one where the weights are either 1 or M, for a sufficient big value M. Motivated by the original application, we study a special interference model on various grids (square, triangular, hexagonal) where a node produces a noise of intensity 1 for its neighbours and a noise of intensity 1/2 for the nodes that are at distance 2. Consequently, the problem consists of determining χt (G, w) and ωk (G, w), when G is the square of a grid and the weights of the edges are 1, if their end nodes are adjacent in the grid, and 1/2 otherwise. Finally, we propose a heuristic and a Branch-and-Bound algorithm to solve the T HRESHOLD I MPROPER COLOURING for general graphs. We compare them to an integer programming formulation on random cell-like graphs, namely Voronoi diagrams of

Fig. 1. Construction of G(I,t) from an instance (I,t) of the PARTITION P ROBLEM

4

J. Araujo et al.

random points of the plan. These graphs are classically used in the literature to model telecommunication networks [4, 8, 9].

2 General Results In this section, we present some results for W EIGHTED I MPROPER COLOURING and T HRESHOLD I MPROPER COLOURING for general graphs and general interference models. 2.1 NP-Completeness of T HRESHOLD I MPROPER

COLOURING

In this section, we prove that the decision problem associated to T HRESHOLD I M PROPER COLOURING is NP-complete already for k = 2. Theorem 1. The following problem is NP-complete. Instance: An edge-weighted graph G = (V, E, w), w : E → R∗+ , a threshold t ∈ R+ . Question: Does G have a weighted t-improper 2-colouring? Proof. Given a 2-colouring c of G, one can test in O (|E|)-time if c is weighted t-improper by just checking, for each vertex v, if Iv (G, w, c) ≤ t. Consequently, this problem is in NP. Now we reduce the PARTITION problem [11] which is NP-complete, to it. In the PARTITION problem, given a set of p positive integers I = {i1 , . . . , i p } and a threshold t, we want to decide if there is a partition of the elements of I into two sets A and B such that ∑ia ∈A ia ≤ t and ∑ib ∈B ib ≤ t. We consider that i j ≤ t, for all j ∈ {1, . . . , p}, and that p t ≤ ∑ j=1 i j , otherwise the answer for this problem is trivially no and yes, respectively. Given an instance (I,t) of the PARTITION P ROBLEM, let G(I,t) be a graph whose vertex set is V (G(I,t)) = {v j | j ∈ {1, . . . , p}}∪{a, b} and whose edge set is E(G(I,t)) = p {(a, b)} ∪ {(a, v j ), (b, v j ) | j ∈ {1, . . . , p}} (see Figure 1). Define M = 1 + ∑ j=1 i j . Let w : E(G(I,t)) → {i1 , . . . , i p , M} be a weight function for the edges of G(I,t) defined in the following way: w(a, b) = M and w(a, v j ) = w(b, v j ) = i j , for every j ∈ {1, . . . p}. We claim that (I,t) is a yes answer for the PARTITION P ROBLEM if, and only if, G(I,t) admits a weighted t-improper 2-colouring. If (I,t) is a yes instance, let (A, B) be a partitioning such that ∑ia ∈A ia ≤ t and ∑ib ∈B ib ≤ t. We claim that the following colouring c is a weighted t-improper 2-colouring of G(I,t): 1 i f v ∈ {a} ∪ {v j | i j ∈ A}; c(v) = 2 otherwise. To verify this fact, observe that Ia (G, w, c) = ∑i j ∈A i j ≤ t, that Ib (G, w, c) = ∑i j ∈B i j ≤ t and that Iv j (G, w, c) = i j ≤ t, for each j ∈ {1 . . . , p}. Conversely, consider that G(I,t) admits a weighted t-improper 2-colouring c. Remark that a and b must receive different colours since the weight of the edge (a, b) is M > t. Thus, assume that c(a) = 1 and that c(b) = 2. Let A be the subset of integers i j , j ∈ {1, . . . , p}, such that c(v j ) = 1 and B = I\A = {i j | c(v j ) = 2}. Observe that the sum of elements in A (resp. B) is equal to Ia (G, w, c) (resp. Ib (G, w, c)) and they are both smaller or equal to t, since c is a weighted t-improper 2-colouring.

Weighted Improper Colouring

5

2.2 Bounds Upper Bound for W EIGHTED I MPROPER C OLOURING. It is a folklore result χ(G) ≤ Δ(G) + 1, for any graph G. Lov´asz [12] extended this result for I MPROPER C OLOURING problem. He proved that χl (G) ≤ Δ(G)+1 l+1 . In what follows, we show an extension of these results to W EIGHTED I MPROPER C OLOURING. Given an edge-weighted graph G = (V, E, w), w : E → R∗+ , and v ∈ V , let dw (v) = ∑u∈N(v) w(u, v). Denote by Δ(G, w) = maxv∈V dw (v). Given a k-colouring c : i V → {1, . . . , k} of G, we denote dw,c (v) = ∑{u∈N(v)|c(u)=i} w(u, v), for every vertex v ∈ V c(v)

and colour i = 1, . . . , k. Note that dw,c (v) = Iv (G, w, c). Finally, we denote gcd(w) the greatest common divisor of the weights of w. We use here the generalisation of the gcd to non-integer numbers (e.g. in Q) where a number x is said to divide a number y if the fraction y/x is an integer. The important property of gcd(w) is that the difference between two interferences is a multiple of gcd(w); in particular, if for two vertices v i (v) > d j (u), then d i (v) ≥ d j (u) + gcd(w). and u, dw,c w,c w,c w,c If t is not a multiple of the gcd(w), that is, there exists an integer a ∈ Z such that a gcd(w) < t < (a + 1)gcd(w), then χtw (G) = χwa gcd(w) (G). Theorem 2. Given an edge-weighted graph G = (V, E, w), w : E → Q∗+ , and a threshold t multiple of gcd(w), then the following inequality holds: Δ(G, w) + gcd(w) χt (G, w) ≤ . t + gcd(w) Proof. We say that a k-colouring c of G is well-balanced if c satisfies the following property: j

Property 1. For any vertex v ∈ V , Iv (G, w, c) ≤ dw,c (v), for every j = 1, . . . , k. If k = 1 there is nothing to prove. Then, we prove that for any k ≥ 2, there exists a wellbalanced k-colouring of G. To prove this fact one may just colour G arbitrarily with k colours and then repeat the following procedure: if there exists a vertex v coloured i i (v) > d j (v), then recolour v with colour j. Observe that and a colour j such that dw,c w,c this procedure neither increases (we just move a vertex from one colour to another) nor decreases (a vertex without neighbour on its colour is never moved) the number of colours within this process. Let W be the sum of the weights of the edges having j the same colour in their endpoints. In this transformation, W has increased by dw,c (v) i (v) (edges that previously had colours i and j in their endpoints), but decreased by dw,c (edges that previously had colour i in both of their endpoints). So, W has decreased by j i dw,c (v) − dw,c (v) ≥ gcd(w). As W ≤ |E| maxe∈E w(e) is finite, this procedure finishes and produces a well-balanced k-colouring of G. Observe that in any well-balanced k-colouring c of a graph G, the following holds: dw (v) =

∑

u∈N(v)

c(v)

w(u, v) ≥ kdw,c (v).

(1)

Let k∗ = Δ(G,w)+gcd(w) ≥ 2 and c∗ be a well-balanced k∗ -colouring of G. We claim t+gcd(w) that c∗ is a weighted t-improper k∗ -colouring of G.

6

J. Araujo et al.

By contradiction, suppose that there is a vertex v in G such that c∗ (v) = i and that j is well-balanced, dw,c (v) > t, for all j = 1, . . . , k∗ . By the definition j of gcd(w) and as t is a multiple of gcd(w), it leads to dw,c (v) ≥ t + gcd(w) for all j = 1, . . . , k∗ . Combining this inequality with Inequality (1), we obtain:

i (v) > t. Since c∗ dw,c

Δ(G, w) ≥ dw (v) ≥ k∗ (t + gcd(w)), giving

Δ(G, w) ≥ Δ(G, w) + gcd(w),

a contradiction. The result follows. Note that when all weights are equal to one, we obtain the bound for the improper colouring derived in [12]. u

w’(u,v)=w(u,v)−1

1 Ku

u’

v

1 Kv

v’

Fig. 2. Construction of Gi+1 from Gi using edge (u, v) with k = 4. Dashed edges represent edges with infinite weights.

Brooks [5] proved that for a connected graph G, χ(G) = Δ(G) + 1 if, and only if, G is complete or an odd cycle. One could wonder for which edge-weighted graphs the bound we provide is tight. However, Correa et al. [6] already showed that it is NP-complete to determine if the improper chromatic number of a graph G attains the upper bound of Lov´asz, which is a particular case of W EIGHTED I MPROPER COLOURING and the bound we provided. Upper Bound for T HRESHOLD I MPROPER C OLOURING. Let G = (V, E, w), w : E → R∗+ , be an edge-weighted graph and k be a positive integer. Observe that, for the minimum k-threshold of G, ωk (G, w) ≤ Δ(G, w) ≤

∑

w(e).

e∈E(G)

In what follows, we improve this trivial upper bound. Let V = {u ∈ V, d(u) ≥ k} be the set of vertices with degree at least k. Set G = G − V . Lemma 1. ωk (G, w) = ωk (G , w) Proof. If there is a weighted t-improper k-colouring of G , then it is easy to get a weighted t-improper k-colouring of G choosing, for each vertex u ∈ V \ V , a colour different from the colours of its neighbours. It is always possible because d(u) ≤ k − 1. Conversely, if there is a weighted t-improper k-colouring of G, then there is a weighted t-improper k-colouring of G by choosing, for every v ∈ V , cG (v) = cG (v).

Weighted Improper Colouring

7

For the rest of the section, we only consider edge-weighted graphs with minimum dek−1 gree at least k. For each v ∈ V , let Emin (v) be the set of d(v) − (k − 1) least weighted edges incident to v. Theorem 3. Let G = (V, E, w), w : E → R∗+ , be an edge-weighted graph and k be a positive integer. Then, k−1 ωk (G, w) ≤ max w(Emin (v)), v∈V

where

k−1 (v)) w(Emin

= ∑e∈E k−1 (v) w(e). min

k−1 Proof. Let Gk−1 min = G[E\{ v∈V Emin (v)}]. Observe that the maximum degree of a verk−1 tex in Gk−1 min ≤ k − 1. Consequently, Gmin admits a proper k-colouring c of its vertices. Observe that the maximum interference of a vertex v in G when G is coloured by the k−1 colouring c is at most maxv∈V w(Emin (v)) and the result follows.

2.3 Transformation In this section, we prove that the T HRESHOLD I MPROPER C OLOURING problem can be transformed into a problem mixing proper and improper colouring. More precisely, we prove the following: Theorem 4. Let G0 = (V0 , E0 , w0 ) be an edge-weighted graph such that, for every e ∈ E, w(e) ∈ Z∗+ , and k be a positive integer. We can construct a graph G∗ = (V ∗ , E ∗ , w∗ ) such that w∗ (e) ∈ {1, M} for any e ∈ E(G∗ ), satisfying ωk (G0 , w0 ) = ωk (G∗ , w∗ ), where M = 1 + ∑e∈E(G) w0 (e). Proof. Consider the function f (G, w) = ∑{e∈E(G)|w(e)=M} (w(e) − 1). If f (G, w) = 0, all edges have weight either 1 or M and G has the desired property. In this case, G∗ = G. Otherwise, we construct a graph G and a function w such that ωk (G , w ) = ωk (G, w), but f (G , w ) = f (G, w) − 1. By repeating this operation f (G0 , w0 ) times we get the required graph G∗ . In case f (G, w) > 0, there exists an edge e = (u, v) ∈ E(G) such that 2 ≤ w(e) < M. G is obtained from G by adding two complete graphs on k − 1 vertices K u and K v and two new vertices u and v . We join u and u to all the vertices of K u and v and v to all the vertices of K v . We assign weight M to all these edges. Note that, u and u (v and v ) always have the same colour, namely the remaining colour not used in K u (resp. K v ). We also add two edges uv and u v both of weight 1. The edges of G keep their weight in G , except the edge e = uv whose weight is decreased by one unit, i.e., w (e) = w(e) − 1. Thus, f (G ) = f (G) − 1 as we added only edges of weights 1 and M and we decreased the weight of e by one unit. Now consider a weighted t-improper k-colouring c of G. We produce a weighted timproper k-colouring c to colour G as follows: we keep the colours of all the vertices in G, we assign to u (v ) the same colour as u (resp., v), and we assign to K u (K v ) the k − 1 colours different from the one used in u (resp. v).

8

J. Araujo et al.

Conversely, from any weighted improper k-colouring c of G , we get a weighted improper k-colouring c of G by just keeping the colours of the vertices that belong to G. For such colourings c and c we have that Ix (G, w, c) = Ix (G , w , c ), for any vertex x of G different from u and v. For x ∈ K u ∪ K v , Ix (G , w , c ) = 0. The neighbours of u with the same colour as u in G are the same as in G, except possibly v which has the same colour of u if, and only if, v has the same colour of u. Let ε = 1 if v has the same colour as u, otherwise ε = 0. As the weight of (u, v) decreases by one and we add the edge (u, v ) of weight 1 in G , we get Iu (G , w , c ) = Iu (G, w, c) − ε + w (u, v )ε = Iu (G, w, c). Similarly, Iv (G , w , c ) = Iv (G, w, c). Finally, Iu (G , w , c ) = Iv (G , w , c ) = ε. But Iu (G , w , c ) ≥ (w(u, v) − 1)ε and so Iu (G , w , c ) ≤ Iu (G , w , c ) and Iv (G , w , c ) ≤ Iv (G , w , c ). In summary, we have max Ix (G , w , c ) = max Ix (G, w, c) x

x

and therefore ωk (G, w) = ωk (G , w ). In the worst case, the number of vertices of G∗ is n + m(wmax − 1)2k and the number of edges of G∗ is m + m(wmax − 1)[(k + 4)(k − 1) + 2] with n = |V (G)|, m = |E(G)| and wmax = maxe∈E(G) w(e). In conclusion, this construction allows to transform the T HRESHOLD I MPROPER C OLOURING problem into a problem mixing proper and improper colouring. Therefore the problem consists in finding the minimum l such that a (non-weighted) l-improper k-colouring of G∗ exists with the constraint that some subgraphs of G∗ must admit a proper colouring. The equivalence of the two problems is proved here only for integers weights, but it is possible to adapt the transformation to prove it for rational weights.

3 Squares of Particular Graphs As mentioned in the introduction, W EIGHTED I MPROPER COLOURING is motivated by networks of antennas similar to grids [2]. In these networks, the noise generated by an antenna undergoes an attenuation with the distance it travels. It is often modelled by a decreasing function of d, typically 1/d α or 1/(2d−1). Here we consider a simplified model where the noise between two neighbouring antennas is normalised to 1, between antennas at distance two is 1/2 and 0 when the distance is strictly greater than 2. Studying this model of interference corresponds to study the W EIGHTED I MPROPER COLOURING of the square of the graph G, the graph obtained from G by joining every pair of vertices at distance 2, and to assign weights w2 (e) = 1, if e ∈ E(G), and w2 (e) = 1/2, if e ∈ E(G2 ) − E(G). Observe that in this case the interesting threshold values are the non-negative multiples of 1/2. In Figure 3 are given some examples of colouring for the square grid. In Figure 3(a) each vertex x has neither a neighbour nor a vertex at distance 2 coloured with its own colour, so Ix (G2 , w2 , c) = 0. In Figure 3(b) each vertex x has exactly one vertex of the same colour at distance 2, so Ix (G2 , w2 , c) = 1/2.

Weighted Improper Colouring

9

For any t ∈ R+ , we determine the weighted t-improper chromatic number for the square of infinite paths, square grids, hexagonal grids and triangular grids under the interference model w2 . We also present lower and upper bounds for χt (T 2 , w2 ), for any tree T and any threshold t. 3.1 Infinite Paths and Trees In this section, we characterise the weighted t-improper chromatic number of the square of an infinite path, for all positive real t. Moreover, we present lower and upper bounds for χt (T 2 , w2 ), for a given tree T . Theorem 5. Let P = (V, E) be an infinite path. Then, ⎧ ⎪ ⎨3, if 0 ≤ t < 1; χt (P2 , w2 ) = 2, if 1 ≤ t < 3; ⎪ ⎩ 1, if 3 ≤ t. Proof. Let V = {vi | i ∈ Z} and E = {(vi−1 , vi ) | i ∈ Z}. Each vertex of P has two neighbours and two vertices at distance two. Consequently, the first case t ≥ 3 is trivial. There is a 2-colouring c of (P2 , w2 ) with maximum interference 1 by just colouring vi with colour i mod 2. So χt (P2 , w2 ) ≤ 2 if t ≥ 1. We claim that there is no weighted 0.5improper 2-colouring of (P2 , w2 ). By contradiction, suppose that c is such a colouring. If c(vi ) = 0, for some i ∈ Z, then c(vi−1 ) = c(vi+1 ) = 1 and c(vi−2 ) = c(vi+2 ) = 0. This is a contradiction because vi would have interference 1. Finally, the colouring c(vi ) = i mod 3, for every i ∈ Z, is a feasible weighted 0improper 3-colouring. )− t )−1 Theorem 6. Let T = (V, E) be a tree. Then, Δ(T2t+1

+1 ≤ χt (T 2 , w2 ) ≤ Δ(T 2t+1 +2.

Proof. The lower bound is obtained by two simple observations. First, χt (H, w) ≤ χt (G, w), for any H ⊆ G. Let T be a tree and v be a node of maximum degree in T . Then, observe that the weighted t-improper chromatic number of the subgraph of T 2 )− t induced by v and its neighbourhood is at least Δ(T2t+1

+ 1. The colour of v can be assigned to at most t vertices on its neighbourhood. Any other colour used in the neighbourhood of v cannot appear in more than 2t + 1 vertices because each pair of vertices in the neighbourhood of v is at distance two. Let us look now at the upper bound. Choose any node r ∈ V to be its root. Colour r with colour 1. Then, by a pre-order traversal in the tree, for each visited node v colour )−1 all the children of v with the Δ(T 2t+1 colours different from the ones assigned to v and to its parent. This is a feasible weighted t-improper k-colouring of T 2 , with k ≤ )−1 Δ(T 2t+1 + 2, since each vertex interferes with at most 2t vertices at distance two which are children of its parent. 3.2 Grids In this section, we show the optimal values of χt (G2 , w2 ), whenever G is an infinite square, or hexagonal or triangular grid, for all the possible values of t. The proofs of the theorems presented in this section can be found in the research report [3].

10

J. Araujo et al.

(a)

(b)

(c)

(d)

Fig. 3. Optimal colorings of G2 , for square grid G. Weighted 0-improper 5-colouring of G2 in Figure 3(a), weighted 0.5-improper 4-colouring of G2 in Figure 3(b) and weighted 3-improper 2-colouring of G2 in 3(c). Figure 3(d) shows that there is no weighted 0.5-improper 3-colouring of G2 .

Square Grid. The square grid is the graph in which the vertices are all integer linear combinations ae1 + be2 of the two vectors e1 = (1, 0) and e2 = (0, 1), for any a, b ∈ Z. Each vertex (a, b) has four neighbours: its down neighbour (a − 1, b), its top neighbour (a + 1, b), its right neighbour (a, b + 1) and its left neighbour (a, b − 1). Theorem 7. If G is an infinite square grid, then ⎧ ⎪ ⎪ ⎪5, if t = 0; ⎪ ⎪ ⎪ ⎨4, if t = 0.5; 2 χt (G , w2 ) = 3, if 1 ≤ t < 3; ⎪ ⎪ ⎪2, if 3 ≤ t < 8; ⎪ ⎪ ⎪ ⎩1, if 8 ≤ t. Proof. If t = 0, then the colour of vertex (a, b) must be different from the ones used on its four neighbours. Moreover, all the neighbours have different colours, as each pair of neighbours is at distance two. Consequently, at least 5 colours are needed. Figure 3(a) gives a a weighted 0-improper 5-colouring of G2 . When t = 0.5, we claim that at least four colours are needed to colour G2 . The proof is by contradiction. Suppose that there exists a weighted 0.5-improper 3-colouring of it. Let (a, b) be a vertex coloured 0. No neighbour is coloured 0, otherwise (a, b) has interference 1. If three neighbours have the same colour, then each of them will have

Weighted Improper Colouring

11

interference 1. So two of its neighbours have to be coloured 1 and the two other ones 2 (see Figure 3(d)). Consider now the four nodes (a−1, b−1), (a−1, b+1), (a+1, b−1) and (a + 1, b + 1). For all configurations, at least two of these 4 vertices have to be coloured 0. But then (a, b) will have interference at least 1, a contradiction. A weighted 0.5-improper 4-colouring of G2 is shown in Figure 3(b). If t = 1, there exists a weighted 1-improper 3-colouring of G2 given by the following construction: for 0 ≤ j ≤ 2, let A j = {(0, j) + a(3e2 ) + b(e1 + e2 ) | ∀a, b ∈ Z}. For 0 ≤ j ≤ 2, assign the colour j to all the vertices in A j . Now we prove by contradiction that for t = 2.5 we still need at least three colours in a weighted 2.5-improper colouring of G2 . Consider a weighted 2.5-improper 2-colouring of G2 and let (a, b) be a vertex coloured 0. Vertex (a, b) has at most two neighbours of colour 0, otherwise it will have interference 3. We distinguish three cases: 1. Exactly one of its neighbours is coloured 0; let (a, b − 1) be this vertex. Then, the three other neighbours are coloured 1. Consider the two set of vertices {(a − 1, b − 1), (a − 1, b + 1), (a − 2, b)} and {(a + 1, b − 1), (a + 1, b + 1), (a + 2, b)}; each of them has at least two vertices coloured 0, otherwise the vertex (a, b + 1) or (a, b − 1) will have interference 3. But then (a, b) having 4 vertices at distance 2 coloured 0 has interference 3, a contradiction. 2. Two neighbours of (a, b) are coloured 0. (a) These two neighbours are opposite, say (a, b − 1) and (a, b + 1). Consider again the two sets {(a − 1, b − 1), (a − 1, b + 1), (a − 2, b)} and {(a + 1, b − 1), (a + 1, b + 1), (a + 2, b)}; they both contain at least one vertex of colour 0 and therefore (a, b) will have interference 3, a contradiction. (b) The two neighbours of colour 0 are of the form (a, b − 1) and (a − 1, b). Consider the two sets of vertices {(a + 1, b − 1), (a + 1, b + 1), (a + 2, b)} and {(a + 1, b + 1), (a − 1, b + 1), (a, b + 2)}; these two sets contain at most one vertex of colour 0, otherwise (a, b) will have interference 3. So vertices (a + 1, b − 1), (a + 2, b), (a, b + 2) and (a − 1, b + 1) are of colour 1. Vertex (a + 1, b + 1) is of colour 0, otherwise (a + 1, b) has interference 3. But then (a, b − 2) and (a − 1, b − 1) are of colour 1, otherwise (a, b) will have interference 3. Thus, vertex (a, b − 1) has exactly one neighbour coloured 0 and we are again in Case 1. 3. All neighbours of (a, b) are coloured 1. If any of this neighbours has itself a neighbour (distinct from (a, b)) of colour 1, we are in case 1 or 2 for this neighbour. Therefore, all vertices at distance two from (a, b) have colour 0 and the interference in (a, b) is 4, a contradiction. A weighted 3-improper 2-colouring of G2 is given in Figure 3(c). Finally, since each vertex has 4 neighbours and 8 vertices at distance two, there is no weighted 7.5-improper 1-colouring of G2 and, whenever t ≥ 8, one colour suffices. Hexagonal Grid. To define the hexagonal grid graph, there are many ways to define the system of coordinates. Here, we use grid coordinates as shown in Figure 4. The hexagonal grid graph is then the graph whose vertex set is the pairs of integers (a, b) ∈ Z2 and where each vertex (a, b) has 3 neighbours: (a − 1, b), (a + 1, b), and (a, b + 1) if a + b is odd, or (a, b − 1) otherwise.

12

J. Araujo et al.

0

0

2 3

1

3

1

2

0

2 0

2 3

3

1 3

1 0

2

3

0

1

1

2

Fig. 4. Optimal construction with t = 0, k = 4. Left: Graph with coordinates. Right: Corresponding hexagonal grid in the euclidean space.

0 0

2 1

0

2

2

1

0

0

1 2

0

2

1

0 1

1

0

2

1 0

0

0 1

1 0

1

1 0

1

2

0 1

1 0 0

0

2

0 1

1

1

1 0

1 0

1

(a) t = 1, k = 3

(b) t = 2, k = 2

Fig. 5. Optimal constructions for the hexagonal grid

Theorem 8. If G is an infinite hexagonal grid, then ⎧ 4, ⎪ ⎪ ⎪ ⎨ 3, χt (G2 , w2 ) = ⎪ 2, ⎪ ⎪ ⎩ 1,

if 0 ≤ t < 1; if 1 ≤ t < 2; if 2 ≤ t < 6; if 6 ≤ t.

Triangular Grid. The triangular grid is graph whose vertices are all the integer linear √ combinations ae1 + be2 of the two vectors e1 = ( 23 , 12 ) and e2 = (0, 1). Thus we may identify the vertices with the ordered pairs (a, b) of integers. Each vertex v = (a, b) has six neighbours: its left neighbour (a, b − 1), its right neighbour (a, b + 1), its left-up neighbour (a + 1, b − 1), its right-up neighbour (a + 1, b + 1), its left-down neighbour (a − 1, b − 1) and its right-down neighbour (a − 1, b + 1).

Weighted Improper Colouring

6-

(b) Weighted 0.5-improper colouring of G2 .

(a) Weighted 0-improper 7-colouring of G2 .

13

(c) Weighted 1.5-improper colouring of G2 .

4-

Fig. 6. Constructions for the triangular grid

Theorem 9. If G is an infinite triangular grid, then ⎧ 7, ⎪ ⎪ ⎪ ⎪ ⎪ 6, ⎪ ⎪ ⎪ ⎪ ⎪ ⎨5, χt (G2 , w2 ) = 4, ⎪ ⎪ ⎪3, ⎪ ⎪ ⎪ ⎪ ⎪ 2, ⎪ ⎪ ⎩ 1,

if t = 0; if t = 0.5; if t = 1; if 1.5 ≤ t < 3; if 3 ≤ t < 5; if 5 ≤ t < 12; if 12 ≤ t.

For determining the lower bounds for the cases in which χt (G2 , w2 ) is equal to 2 and 3, the proofs involved too many subcases to be readable. Then, we used CPLEX with the integer programming formulations we present in Section 4 to validate them.

4 Integer Programs, Algorithms and Results In this section, we look at how to solve the W EIGHTED I MPROPER COLOURING and T HRESHOLD I MPROPER COLOURING for realistic instances. We consider PoissonVoronoi tesselations as they are good models of antennas networks [4, 8, 9]. We present integer programming models for both problems. Then, we introduce two algorithmic approaches for T HRESHOLD I MPROPER COLOURING: a simple greedy heuristic and a Branch-and-Bound algorithm.

14

J. Araujo et al.

4.1 Integer Programs and Algorithms Integer Programming Models. Given an edge-graph G = (V, E, w), w : E → R∗+ , and a positive real threshold t, we model W EIGHTED I MPROPER C OLOURING by using two kinds of variables. Variable xip indicate if vertex i is coloured p and variable c p indicate if colour p is used, for every 1 ≤ i ≤ n and 1 ≤ p ≤ l, where l is an upper bound for the number of colours needed in an optimal weighted t-improper colouring of G (see Section 2). The model follows: min subject to

∑p cp ∑ j=i w(i, j)x j p ≤ t + M(1 − xip) (∀i ∈ V, ∀p ∈ {1, . . . , l}) c p ≥ xip (∀i ∈ V, ∀p ∈ {1, . . . , l}) (∀i ∈ V ) ∑ p xip = 1 xip ∈ {0, 1} (∀i ∈ V, ∀p ∈ {1, . . . , l}) c p ∈ {0, 1} (∀p ∈ {1, . . . , l})

where M is a large integer. For instance, it is sufficient to choose M > ∑(u,v)∈E w(u, v). For T HRESHOLD I MPROPER C OLOURING , given an edge-weighted graph G = (V, E, w), w : E → R∗+ , and a positive integer k, the model we consider is: min subject to

t ∑ j=i w(i, j)x j p ≤ t + M(1 − xip) (∀i ∈ V, ∀p ∈ {1, . . . , k}) (∀i ∈ V ) ∑ p xip = 1 xip ∈ {0, 1} (∀i ∈ V, ∀p ∈ {1, . . . , k})

Levelling Heuristic. We develop a heuristic to solve T HRESHOLD I MPROPER COLOUR ING. The idea is to try to level the distribution of interference over the vertices. Each vertex is coloured one after the other by the colour minimising the local interference. More precisely this is achieved by considering for the nodes not yet coloured the “current interference” i.e. the interference induced by the already coloured vertices. Precisely, consider a vertex v not yet coloured and a colour i ∈ {1, . . . , k}. We define as: the potential interference Iv,i Iv,i =

∑

w(u, v),

{u∈N(v)∩Vi |c(u)=i}

where Vi is the set of vertices that have already been assigned a colour. The order in which vertices are coloured is decided according to the total potential interference, de . The algorithm finds a feasible colouring in the first step and tries fined as Iv = ∑ki=1 Iv,i to improve it for p runs, where p is part of the input. – The interference target is set tt = M; – while the number of runs is smaller than p; • all potential interferences are set to zero; • while there are still vertices to colour: ∗ choose a vertex v randomly among the uncoloured vertices that have the maximum total potential interference;

Weighted Improper Colouring

15

: ∗ try each colour i in the order of increasing potential interference Iv,i · if colouring v with i does not result in interference greater than tt for v or any of its neighbours, colour v with i, else try a new colour; · if all colours resulted in excessive interferences, start new run. • If all the vertices were successfully coloured, set tt = maxv∈V,i∈{1,...,k} Iv (G, w, c) − gcd(w) and store the colouring as the best found.

As a randomised greedy colouring heuristic, it has to be run multiple times to achieve satisfactory results. This is not a practical issue due to low computational cost of each run. The local immutable colouring decision is taken in time O(k). Then, after each such decision, the interference has to be propagated, which takes time linear in the vertex degree. This gives a computational complexity bound O(knΔ). Branch-and-Bound Algorithm. We also implemented a simple Branch-and-Bound algorithm inspired by the above heuristic. The order in which vertices are coloured is produced by a similar procedure to the one used in the above heuristic. In order to compute this order, we start by marking a random vertex and setting is as the first in a to colour list. Then, as long as there are unmarked vertices, we keep choosing a random vertex u among the unmarked vertices with biggest ∑v∈N(u)∩Vm w(u, v), where Vm is the set of already marked vertices. Then we mark u and append it to the to order. A basic Branch-and-Bound colours vertices in the obtained order. Potential interference, as defined for the heuristic, is tracked with the additional step of decreasing the values when backing from a colouring. Colours are tried in the order of increasing potential interference. Thanks to that it produces results similar to the heuristic in a short time. On the other hand it is guaranteed to find the optimal solution in a finite time. In the following, we compare the performance of these ILP models with the Levelling heuristic and the Branch-and-Bound algorithm . 4.2 Results In this section, we look at the performances of the methods to solve the T HRESHOLD I MPROPER COLOURING. We consider Delaunay graphs (dual of Voronoi diagram) for a set of random points. This kind of graph is a natural approximation of a network of irregular cells. The interference model is the one described in Section 3: adjacent nodes interfere by 1 and nodes at distance two interfere by 1/2. Figure 7 shows a performance comparison of the above-mentioned algorithms. For all the plots, each data point represents an average over ten different graphs. The same graph is used for all values of colours and time limit. Therefore sub-figures 7(b) and 7(c) plot how results for a given problem instance get enhanced with increasing time limits. Plots 7(e) and 7(f) show decreasing interference along increasing the number of colours allowed. Finally plot 7(d) shows how well all the programs scale with increasing graph sizes. One immediate observation about both the heuristic and Branch-and-Bound algorithm is that they provide solutions in relatively short time. Despite their naive implementation in a high-level programming language, they tend to find near-optimal results in matter of seconds even for graphs of thousands of vertices. On the other hand, with

16

J. Araujo et al. Delaunay graph, n=2000 vertices, k=5 colors

t - interference found

35

Branch & Bound Heuristic IP

30 25 20 15 10 5 0

0

100

200

300

400

500

600

700

l - Time limit [seconds]

(a) Example Delaunay graph, dotted lines delimit corresponding Voronoi diagram cells Delaunay graph, n=2000 vertices, k=2 colors

30 25 20 15 10 5 0

200

300

400

500

600

20 15 10 5 0

500

1000

1500

2000

(c) Over time

(d) Over size

25 20 15 10 5 4

25

n - number of vertices

Branch & Bound Heuristic IP

2

Branch & Bound Heuristic IP

30

l - Time limit [seconds]

30

0

35

0

700

Delaunay graph, N=2000 vertices, L=60 sec

35

t – interference found

100

Delaunay graph, k=2 colors, l=60 sec

40

t - interference found

Branch & Bound Heuristic IP

6

8

10

k – number of colors

(e) Over colours

12

14

t – interference found

t - interference found

35

0

(b) Over time

180 160 140 120 100 80 60 40 20 0

2500

3000

¨ ´ Erdos-R enyi graph, N=500 vertices, L=120 sec

Branch & Bound Heuristic IP

2

4

6

8

10

12

14

k – number of colors

(f) Over colours

Fig. 7. Results comparison for Levelling heuristic, Branch-and-Bound algorithm and Integer Programme

limited time, they fail to improve up to optimal results, especially with a low number of allowed colours. Although it is easy to envision an implementation faster by orders of magnitude, this may still give little improvement — once a near-optimal solution is found, the Branch-and-Bound algorithm does not improve for a very long time (an example near-optimal solution found in around three minutes was not improved in over six days). ILP solvers with good Branch-and-Cut implementations do not suffer from this problem. However, they can not take advantage of any specialised knowledge of the problem, only the basic integer programmming representation. Thus it takes much more time to produce first good results. Despite taking advantage of multi-core processing,

Weighted Improper Colouring

17

CPLEX — ILP solver used in this work, does not scale with increasing graph sizes as well as our simple algorithms. Furthermore, Figure 7(e) reveals one problem specific to integer programming. When increasing the number of allowed colours, obtaining small interferences gets easier. But this introduces additional constraints in the linear program, thus increasing the complexity for a solver. Above observations are valid only for the very particular case of the simple interference function and very sparse graphs. The average degree in Delaunay graph converges to 6. Proposed algorithms also work quite well for denser graphs. Figure 7(f) plots interferences for different numbers of colours allowed found by the programs for an Erd¨os-R´enyi graph with n=500 and p=0.1. This gives us an average degree of 50. Both Branch-and-Bound and heuristic programs achieve acceptable, and nearly identical, results. But the large number of constraints makes the linear program nearly inefficient.

5 Conclusion, Open Problems and Future Directions In this paper, we introduced and studied a new colouring problem, W EIGHTED I M PROPER COLOURING . This problem is motivated by the design of telecommunication antenna network in which the interferences between two vertices depends on different factors and can take various values. For each vertex, the sum of the interference it receives should be less than a given threshold value. We first give general bounds on the weighted-improper chromatic number. We then study the particular case of square, triangular and hexagonal grids. For these graphs, we provide their weighted-improper chromatic number for all possible values of t. Finally, we propose a heuristic and a Branch-and-Bound algorithm to find good solutions of the problem. We compare their results with the one of an integer program on cell-like networks, Poisson Voronoi tessellations. Open Problems and Future Directions. Many problems remain to be solved : – For the study of the grid graphs, we considered a specific function where vertex at distance one interfere by 1 and vertices at distance 2 by 1/2. Other weight functions should be considered. e.g. 1/d 2 or 1/(2d−1 ), where d is the distance between vertices. – Other families of graphs could be considered, for example hypercubes. – Let G = (V, E, w) be an edge-weighted graph where the weights are all equal to 1 or M. Let GM be the subgraph of G induced by the edges of weight M; is it true that if Δ(GM ) 0 are respective thresholds below which these problems cannot be approximated eﬃciently (unless NP has slightly super-polynomial time algorithm [12] or unless P=NP [27]). Dominating Set and Coloring have a number of applications and this has led to the algorithmic study of numerous variants of these problems. Among the most well known ones are Connected Dominating Set, Independent Dominating Set, Perfect Code, List Coloring, Edge Coloring, Acyclic Edge Coloring and Choosability. Since both the problem and its variants are computationally hard problems, most of the research centers around algorithms in special classes of graphs like interval graphs, chordal graphs, planar graphs and H-minor free graphs. In this paper we initiate a systematic algorithmic study on the Dominator Coloring (DC) problem that has a ﬂavor of both these classical problems. A dominator coloring of a graph G is an assignment of colors to the vertices of G such that it is a proper coloring (no edge is monochromatic) and every vertex dominates all vertices of at least one color class. The minimum number of colors required for a dominator coloring of G is called the dominator chromatic number of G and is denoted by χd (G). The problem we study is formally deﬁned as follows. Dominator Coloring (DC) Input: A graph G and an integer k ≥ 1. Parameter: k. Question: Does there exist a dominator coloring of G using at most k colors? Gera et al. [22] introduced the concept of dominator chromatic number, and a number of basic combinatorial and algorithmic results on DC have been obtained [20,21,22,24]. For example, it was observed by Gera et al. [22] that DC is NP-complete on general graphs by a simple reduction from 3-Coloring. More precisely, for any ﬁxed k ≥ 4, it is NP-complete to decide if a graph admits a dominator coloring with at most k colors [22]. In a recent paper Chellali and Maﬀray [6] show that unlike 3-Coloring, one can decide in polynomial time if a graph has dominator chromatic number 3. Furthermore, they show that the problem is polynomial time solvable on P4 free graphs, and leave as a “challenging open problem” whether the problem can be solved in polynomial time on chordal graphs. In this paper we do a thorough algorithmic study of this problem, analyzing both the classical complexity and the parameterized complexity. We begin by showing that unless P=NP, DC cannot be solved in polynomial time on bipartite, planar, or split graphs. The ﬁrst two arguments are simple but make use of an unusual sequence of observations. The NP-completeness reduction on split graphs is quite involved. Since split graphs form a subclass of chordal graphs, this answers, in the negative, the open problem posed by Chellali and Maﬀray.

Algorithmic Aspects of Dominator Colorings in Graphs

21

We complement our hardness results by showing that the problem is “ﬁxed parameter tractable" on several of the graph classes mentioned above. Informally, a parameterization of a problem assigns an integer k to each input instance and a parameterized problem is fixed-parameter tractable (FPT) if there is an algorithm that solves the problem in time f (k) · |I|O(1) , where |I| is the size of the input and f is an arbitrary computable function that depends only on the parameter k. We refer the interested reader to standard texts [10,14] on parameterized complexity. We show that DC is FPT on planar graphs, apex minor free graphs, split graphs and chordal graphs.

2

Preliminaries

All graphs in this article are ﬁnite and undirected, with neither loops nor multiple edges. n denotes the number of vertices in a graph, and m the number of edges. A subset D ⊆ V of the vertex set V of a graph G is said to be a dominating set of G if every vertex in V \ D is adjacent to some vertex in D. The domination number γ(G) of G is the size of a smallest dominating set of G. A proper coloring of graph G is an assignment of colors to the vertices of G such that the two end vertices of any edge have diﬀerent colors. The chromatic number χ(G) of G is the minimum number of colors required in a proper coloring of G. A clique is a graph in which there is an edge between every pair of vertices. The clique number ω(G) of G is the size of a largest clique which is a subgraph of G. We make use of the following known results. Theorem 1. [20] Let G be a connected graph. Then max{χ(G), γ(G)} ≤ χd (G) ≤ χ(G) + γ(G). Definition 1. A tree decomposition of a (undirected) graph G = (V, E) is a pair (X, U ) where U = (W, F ) is a tree, and X = ({Xi | i ∈ W }) is a collection of subsets of V such that 1. i∈W Xi = V , 2. for each edge vw ∈ E, there is an i ∈ W such that v, w ∈ Xi , and 3. for each v ∈ V, the set of vertices {i | v ∈ Xi } forms a subtree of U . The width of (X, U ) is maxi∈W {|Xi | − 1}. The treewidth tw(G) of G is the minimum width over all the tree decompositions of G. Both our FPT algorithms make use of the fact that the DC problem can be expressed in Monadic Second Order Logic (MSOL) on graphs. The syntax of MSOL on graphs includes the logical connectives ∨, ∧, ¬, ⇔, ⇒, variables for vertices, edges, sets of vertices and sets of edges, the quantiﬁers ∀, ∃ that can be applied to these variables, and the following ﬁve binary relations: (1) u ∈ U where u is a vertex variable and U is a vertex set variable; (2) d ∈ D where d is an edge variable and D is an edge set variable; (3) inc(d, u), where d is an edge variable, u is a vertex variable, and the interpretation is that the edge d is incident on the vertex u; (4) adj(u, v), where u and v are vertex variables

22

S. Arumugam et al.

and the interpretation is that u and v are adjacent; (5) equality of variables representing vertices, edges, sets of vertices and sets of edges. Many common graph and set-theoretic notions can be expressed in MSOL [5,8]. In particular, let V1 , V2 , . . . , Vk be a set of subsets of the vertex set V (G) of a graph G. Then the following notions can be expressed in MSOL: – V1 , V2 , . . . , Vk is a partition of V (G): P art(V (G); V1 , V2 , . . . , Vk ) ≡ ∀v ∈ V (G)[(v ∈ V1 ∨ v ∈ V2 ∨ · · · ∨ v ∈ Vk ) ∧ (¬(v ∈ V1 ∩ V2 )) ∧ (¬(v ∈ V1 ∩ V3 )) ∧ · · · ∧ (¬(v ∈ Vk−1 ∩ Vk ))] ∧ (∃v ∈ V (G)[v ∈ V1 ]) ∧ (∃v ∈ V (G)[v ∈ V2 ]) ∧ · · · ∧ (∃v ∈ V (G)[v ∈ Vk ]) – Vi is an independent set in G: IndSet(Vi ) ≡ ∀u ∈ Vi [∀v ∈ Vi [¬adj(u, v)]] – Vertex v dominates all vertices in the set Vi : Dom(v, Vi ) ≡ ∀w ∈ Vi [¬(w = v) =⇒ adj(v, w)] For a graph G and a positive integer k, we use ϕ(G, k) to denote an MSOL formula which states that G has a dominator coloring with at most k colors: ϕ(G, k) ≡ ∃V1 , V2 , . . . , Vk ⊆ V (G)[P art(V (G); V1 , V2 , . . . , Vk ) ∧

(1)

IndSet(V1 ) ∧ IndSet(V2 ) ∧ · · · ∧ IndSet(Vk ) ∧ ∀v ∈ V (G)[Dom(v, V1 ) ∨ Dom(v, V2 ) ∨ · · · ∨ Dom(v, Vk )]] The following well known result states that every optimization problem expressible in MSOL has a linear time algorithm on graphs of bounded treewidth. Proposition 1. [1,3,5,7,9] Let ϕ be a property that is expressible in Monadic Second Order Logic. For any fixed positive integer t, there is an algorithm that, given a graph G of treewidth at most t as input, finds a largest (alternatively, smallest) set S of vertices of G that satisfies ϕ in time f (t, |ϕ|)|V (G)| for a computable function f (). Since the size |ϕ(G, k)| of the MSOL expression 1 is a function of k, we have Theorem 2. Given a graph G of treewidth t and a positive integer k as inputs, the Dominator Coloring problem can be solved in f (t, k)|V (G)| time for a computable function f (). The operation of contracting an edge {u, v} of a graph consists of replacing the two vertices u, v with a single vertex which is adjacent to all the former neighbours of u and v. A graph H is said to be a contraction of a graph G if H can be obtained from G by contracting zero or more edges of G. H is said to be a minor of G if H is a contraction of some subgraph of G. A graph G is said to be apex graph if there exists a vertex in G whose removal from G yields a planar

Algorithmic Aspects of Dominator Colorings in Graphs

23

Fig. 1. The graph Γ6

graph. A family F of graphs is said to be apex minor free if there is a speciﬁc apex graph H such that no graph in F has H as a minor. For instance, planar graphs are apex minor free since they exclude the apex graph K5 as a minor. The treewidth of an apex minor free graph can be approximated to within a constant factor in polynomial time: Proposition 2. [13, Theorem 6.4] For any graph H, there is a constant wH and a polynomial time algorithm which finds a tree decomposition of width at most wH t for any H-minor-free graph G of treewidth t. For ∈ N, Γ is deﬁned [15] to be the graph obtained from the × -grid by (1) triangulating the internal faces such that all the internal vertices become of degree 6 and all non-corner external vertices are of degree 4, and (2) adding edges from one corner of degree two to all vertices of the external face. Figure 1 depicts Γ6 . Fomin et al. showed that any apex minor free graph of large treewidth contains a proportionately large Γ as a contraction. More precisely: Proposition 3. [15, Theorem 1] For any apex graph H, there is a constant cH such that every connected graph G which excludes H as a minor and has treewidth at least cH contains Γ as a contraction.

3

Hardness Results

In this section we show that DC is NP-hard on very restricted classes of graphs. The only known hardness result for this problem is that it is NP-complete on general graphs [22]. In fact even determining whether there exists a dominator coloring of G using at most 4 colors is NP-complete. The proof is obtained by a reduction from 3-Coloring – checking whether an input graph is 3-colorable or not – to DC. Given an instance G to 3-Coloring, an instance G for DC is obtained by adding a new vertex (universal vertex) and making it adjacent to every vertex of G. Now one can easily argue that G is 3 colorable if and only if G has dominator coloring of size at most 4. Notice, however, that this simple reduction cannot be used to show that DC is NP-complete on restricted graph classes like planar graphs or split graphs or chordal graphs. We start with a few simple claims that we will make use of later.

24

S. Arumugam et al.

Lemma 1. Let G = (V, E) be a graph. Given a proper a-coloring C of G and a dominating set D of G with |D| = b, we can find, in O(|V | + |E|) time, a dominator coloring of G with at most a + b colors. Proof. Let C = {V1 , V2 , . . . , Va } be a proper coloring of G and let D be a dominating set with |D| = b. Then C = {{v} : v ∈ D} ∪ {Vi ∩ (V − D) : Vi ∈ C} is a dominator coloring of G with at most a + b colors. Corollary 1. [ ]1 If there exists an α-approximation algorithm for the chromatic number problem and a β-approximation algorithm for the domination number problem, then there exists an (α + β)-approximation algorithm for the dominator chromatic number problem. Lemma 2. [ ] Let F be a class of graphs on which the Dominating Set problem is NP-complete. If the disjoint union of any two graphs in F is also in F, then there is no polynomial time algorithm that finds a constant additive approximation for the Dominating Set problem on F , unless P = N P. Corollary 2. [ ] Dominator Coloring on planar graphs cannot be solved in polynomial time, unless P = N P. Corollary 3. [ ] Dominator Coloring on bipartite graphs cannot be solved in polynomial time, unless P = N P. 3.1

NP-Hardness of DC on Split Graphs

We now proceed to prove that the DC problem is NP-complete for split graphs. Our starting point is the following known characterization: Theorem 3. [2] Let G be a split graph with split partition (K, I) and |K| = ω(G), where K is a clique and I an independent set. Then χd (G) = ω or ω + 1. Further χd (G) = ω if and only if there exists a dominating set D of G such that D ⊆ K and every vertex v in I is nonadjacent to at least one vertex in K \ D. We exploit this characterization, and prove NP-completeness on split graphs by demonstrating the NP-completeness of the problem of checking if there exists a dominating set D of G such that D ⊆ K and every vertex v in I is nonadjacent to at least one vertex in K \D. We call this problem Split Graph Domination. For showing Split Graph Domination NP-complete, we will need to deﬁne an intermediate problem called Partition Satisfiability, and demonstrate that it is NP-complete. We will then show that DC is NP-hard on split graphs by establishing a reduction from Partition Satisfiability. Let φ be a CNF formula. Then we use C(φ) to denote the set of clauses of φ. If C is a clause of φ, then we use ν(C) to denote the set of variables that appear in C. A clause is said to be all-positive (negative) if all the literals that appear in it are positive (negative). 1

Due to space constraints, proofs of results marked with a [] have been deferred to a longer version of the paper.

Algorithmic Aspects of Dominator Colorings in Graphs

25

Definition 2 (Partition Normal Form). A CNF formula φ over the variable set V is said to be in partition normal form if C(φ) admits a partition into two parts CP (φ) and CN (φ) and there exists a bijection f : CP (φ) → CN (φ) such that for every C ∈ CP (φ) the following conditions are satisfied: (1) ν(C) ∪ ν(f (C)) = V and (2) ν(C) ∩ ν(f (C)) = ∅. Any clause in CP (φ) is required to be an all-positive clause and any clause in CN (φ) is required to be an all-negative clause. We are now ready to describe the problem Partition Satisfiability. Partition Satisfiability Input: A formula φ in CNF, over variables in V , given in partition normal form. Question: Is φ satisﬁable? We establish the NP-completeness of Partition Satisfiability by a reduction from Disjoint Factors: Disjoint Factors Input: A word w over an alphabet Σ. Question: For every a ∈ Σ, does there exist a substring wa of w that begins and ends in a, such that for every a, b ∈ Σ, wa and wb do not overlap in w? The problem of Disjoint Factors is known to be NP-complete [4]. Substrings that begin and end with the same letter a are referred to as a-factors. Lemma 3. Partition Satisfiability is NP-complete. Proof. Let w = w1 w2 . . . wn be an instance of Disjoint Factors over the alphabet Σ = {a1 , . . . , ak }. For 1 ≤ i < j ≤ n and 1 ≤ l ≤ k, we call the triplet (i, j, l) valid if the substring wi . . . wj is an al -factor. Let F denote the set of valid triplets. We construct an instance of Partition Satisfiability as follows: For every valid triplet (i, j, l), introduce the variable Pl (i, j). For every 1 ≤ l ≤ k, introduce the clause: ⎛ ⎞ Cl := ⎝ Pl (i, j)⎠ . {i,j : (i,j,l)∈F }

Let φFACTOR be the conjunction of the clauses thus formed: φFACTOR := C1 ∧ C2 ∧ . . . ∧ Ck . Further, for every i1 , j1 and i2 , j2 such that 1 ≤ i1 < j1 ≤ n and 1 ≤ i2 < j2 ≤ n, and [i1 , j1 ] ∩ [i2 , j2 ] = ∅, and there exist l1 , l2 ; 1 ≤ l1 , l2 ≤ k, such that (i1 , j1 , l1 ) ∈ F and (i2 , j2 , l2 ) ∈ F , we introduce the following clause:

26

S. Arumugam et al.

C := Pl1 (i1 , j1 ) ∨ Pl2 (i2 , j2 ) Let D denote the set of clauses described above. Further, let φDISJOINT be the conjunction of these clauses: φDISJOINT := C∈D C. Claim. The formula: φ := φDISJOINT ∧ φFACTOR is satisﬁable if and only if (w, Σ) is a YES-instance of Disjoint Factors. Proof. (⇒) Let χ be a satisfying assignment of φ. For all l, 1 ≤ l ≤ k, there exists at least one pair (i, j), 1 ≤ i < j ≤ n, such that χ sets Pl (i, j) to 1. Indeed, if not, χ would fail to satisfy the clause Cl . Now, note that wi . . . wj is a al -factor, since the variable Pl (i, j) corresponds to a valid triplet. We pick wi . . . wj as the factor for al (if Pl (i, j) is set to 1 by χ for more than one pair (i, j), then any one of these pairs will serve our purpose). It only remains to be seen that for r, s ∈ Σ, if wi1 . . . wj1 is chosen as a ar -factor, and wi2 . . . wj2 is chosen as a as -factor, then wi1 . . . wj1 and wi2 . . . wj2 do not overlap in w. This is indeed the case, for if they did overlap, then it is easily checked that χ would fail to satisfy the clause: Pr (i1 , j1 ) ∨ Ps (i2 , j2 ) . (⇐) If (w, Σ) is a YES-instance of Disjoint Factors, then for every l, 1 ≤ l ≤ k, there exist i, j; 1 ≤ i < j ≤ n, such that (i, j, l) ∈ F . We claim that setting all the “corresponding” Pl (i, j) variables to 1 is a satisfying assignment for φ. Indeed, every Cl is satisﬁed because there exists an al -factor for every l. Further, it is routine to verify that all clauses in D are satisﬁed because the chosen factors do not overlap in w. Now, it remains to construct from φ an equivalent formula ψ that is in partition normal form. To this end, we will use two new variables, {x, y}. Recall that we use V to denote the set of variables that appear in φ. For every clause Cl , deﬁne the clause Cˆl as: Cˆl := x ∨ y ∨ z ∈ V \ν(Cl ) z . ˆ as: Cˆ := x ∨ y ∨ Similarly, for every clause C ∈ D, deﬁne C z ∈ V \ν(C) z . Let ψ be conjunction of φ with the newly described clauses: obtained by the ˆl ∧

ˆ . ψ := φ ∧ C C 1≤l≤k C∈D Clearly, ψ is in partition normal form. The following partition of the clauses of ψ: CP = {Cl : 1 ≤ l ≤ k} ∪ {Cˆ : C ∈ D} and CN = {Cˆl : 1 ≤ l ≤ k} ∪ {C : C ∈ D} is a partition into all-positive and all-negative clauses. The ˆ = C, for C ∈ D is bijection f deﬁned as: f (Cl ) = Cˆl , for 1 ≤ l ≤ k and f (C) easily seen to be a bijection with the properties demanded by the deﬁnition of the partition normal form. We now arrive at our concluding claim: Claim. φ is satisﬁable if and only if ψ is satisﬁable. Proof. (⇒) Let χ be a satisfying assignment for φ. Extend φ to the new variables {x, y} as follows: χ(x) = 1 and χ(y) = 0. It is easy to see that χ is satisfying for ψ. (⇐) This direction is immediate, as C(φ) ⊆ C(ψ).

Algorithmic Aspects of Dominator Colorings in Graphs

27

The proof that Partition Satisfiability is NP-hard follows when we put the two claims together: by appending the construction of ψ from φ to the formula φ obtained from the Disjoint Factors instance, we obtain an equivalent instance of Partition Satisfiability. This concludes the proof. We note that membership in NP is trivial — an assignment to the variables is clearly a certiﬁcate that can be veriﬁed in linear time. The lemma follows. Recall the Split Graph Domination problem that we introduced in the beginning of this section: Split Graph Domination Input: Split graph G with split partition (K, I) and |K| = ω. Question: Does there exist a dominating set D of G such that D ⊆ K and every vertex v in I is nonadjacent to at least one vertex in K \ D ? We now turn to a proof that Split Graph Domination is NP-complete. Theorem 4. Split Graph Domination is NP-complete. Proof. It is straightforward to see that Split Graph Domination is in NP. We now prove that it is NP-hard by a reduction from Partition Satisfiability. Given an instance φ (over the variables V ) of Partition Satisfiability, we construct a split graph G with split partition (K, I) as follows. Introduce, for every variable in V , a vertex in K and for every all-positive clause of φ, a vertex in I: K = {v[x] : x ∈ V }, I = {u[C] : C ∈ CP (φ)}. A pair of vertices v[x] and u[C] are adjacent if the variable x belongs to the clause C, that is, x ∈ ν(C). We also make all vertices in K pairwise adjacent and all vertices in I pairwise independent. This completes the construction. Suppose φ admits a satisfying truth assignment χ. Let D = {v[x] ∈ K : χ(x) = 1}. We now prove that this choice of D is a split dominating set. Consider u[C] ∈ I. There exists at least one x ∈ V such that x ∈ ν(C) and χ(x) = 1. Thus the corresponding vertex v[x] ∈ D, and u[C] is dominated. Further, consider the all-negative clause Cˆ corresponding to C, that contains every variable in V that is not in ν(C). Since χ is a satisfying assignment, there is at least one y ∈ V \ ν(C) such that χ(y) = 0. Clearly, v[y] ∈ / D, and v[y] is not adjacent to u[C]. Conversely, suppose there exists a dominating set D ⊆ K such that each u[C] in I is nonadjacent to at least one vertex in K \ D. Consider the following truth assignment χ for φ: χ(x) = 1 if, and only if, v[x] ∈ K ∩ D. We now prove that χ is a satisfying assignment. Consider any all-positive clause C. Since u[C] was dominated by D, there exists a variable x ∈ ν(C) such that v[x] ∈ D, and thus ˆ Since K \D contains χ(x) = 1. Consider the corresponding all-negative clause C. at least one non-neighbor of v[x], there exists a y ∈ / ν(C) such that χ(y) = 0. ˆ Recall that the assignment χ(y) = 0 Note that y ∈ / ν(C) implies that y ∈ ν(C). ˆ since Cˆ is an all-negative clause. is then satisfying for C, From Theorem 3 and Theorem 4 we get

28

S. Arumugam et al.

Theorem 5. DC when restricted to split graphs is NP-complete.

4

Parameterized Algorithms

In this section we investigate the ﬁxed-parameter tractability of the DC problem in certain graph classes. Recall that it is NP-complete to decide if a graph admits a dominator coloring with at most 4 colors [22]. It follows that in general graphs, the DC problem cannot be solved even in time ng(k) for any function g(k) — that is, DC does not belong to the complexity class XP — unless P=NP. Hence DC is not FPT in general graphs unless P=NP. As we show below, however, the problem is FPT in two important classes of graphs, namely apex-minorfree graphs (which include planar graphs as a special case) and chordal graphs. Recall that it is NP-complete to decide if a planar graph admits a proper 3coloring [18]. As a consequence, the Graph Coloring problem parameterized by the number of colors is not even in XP in planar graphs. Our result for planar graphs thus brings out a marked diﬀerence in the parameterized complexity of these two problems when restricted to planar graphs. Apex Minor Free Graphs. We now show that the Dominator Coloring problem is FPT on apex minor free graphs. This implies, as a special case, that the problem is FPT on planar graphs. We ﬁrst show that if the treewidth of the input apex minor free graph is large, then the graph has no dominator coloring with a small number of colors. Theorem 6. [ ] For any apex graph H, there is a constant dH such that any √ connected graph G which excludes H as a minor and has treewidth at least dH k has no dominator coloring with at most k colors. Let (G, k) be an instance of the Dominator Coloring problem, where G √ excludes the apex graph H as a minor. Let t = wH dH k where dH , wH are the constants of Theorem 6 and Proposition 2, respectively. To solve the problem on this instance, we invoke the approximation subroutine implied by Proposition 2 on the graph G. If this subroutine returns a tree decomposition with treewidth more than t, then we return NO as the answer. Otherwise we solve the problem using the algorithm of Theorem 2, and so we have: Theorem 7. [ ] The Dominator Coloring problem is fixed parameter tractable on apex minor free graphs. Chordal Graphs and Split Graphs. We now show that the Dominator Coloring problem is FPT on chordal graphs. For a special class of chordal graphs, namely split graphs, we give an FPT algorithm which runs in time single-exponential in the parameter. Theorem 8. The Dominator Coloring problem is fixed parameter tractable on chordal graphs. Proof. Let (G, k) be an instance of the Dominator Coloring problem, where G is chordal. The algorithm ﬁrst ﬁnds a largest clique in G. If the number of

Algorithmic Aspects of Dominator Colorings in Graphs

29

vertices in this clique is more than k, then it returns NO as the answer. Otherwise it invokes the algorithm of Theorem 2 as a subroutine to solve the problem. To see that this algorithm is correct, observe that if G contains a clique C with more than k vertices, then χ(G) > k since it requires more than k colors to properly color the subgraph C itself. It follows from Theorem 1 that χd (G) > k, and so it is correct to return NO. A largest clique in a chordal graph can be found in linear time [19]. If the largest clique in G has size no larger than k, then — as is well known — the treewidth of G is at most k − 1, and so the subroutine from Theorem 2 runs in at most f ((k − 1), k)|V (G)| = g(k)|V (G)| time. Thus the algorithm solves the problem in FPT time. The Dominator Coloring problem can be solved in “fast” FPT time on split graphs: Theorem 9. [ ] The Dominator Coloring problem can be solved in O(2k ·n2 ) time on a split graph on n vertices.

5

Conclusion and Scope

We derived several algorithmic results about the Dominator Coloring (DC) problem. We showed that the DC problem remains hard on several graph classes, including bipartite graphs, planar graphs, and split graphs. In the process we also answered, in the negative, an open problem by Chellali and Maﬀray [6] about the polynomial time solvability of DC on chordal graphs. Finally, we showed that though the problem cannot be solved in polynomial time on the aforementioned graph classes, it is FPT on apex minor free graphs and on chordal graphs. From Theorem 1 and from the fact that ﬁnding a constant additive approximation for the Dominating Set problem is W[2]-hard [11], it follows that the DC problem is W[2]-hard on bipartite graphs, and so also on the larger class of perfect graphs. An interesting problem which remains open is whether the DC problem is solvable in polynomial time on interval graphs.

References 1. Arnborg, S., Lagergren, J., Seese, D.: Easy problems for tree-decomposable graphs. Journal of Algorithms 12(2), 308–340 (1991) 2. Arumugam, S., Bagga, J., Chandrasekar, K.R.: On dominator colorings in graphs (2010) (manuscript) 3. Bodlaender, H.L.: A linear time algorithm for ﬁnding tree-decompositions of small treewidth. SIAM Journal on Computing 25, 1305–1317 (1996) 4. Bodlaender, H.L., Thomassé, S., Yeo, A.: Kernel Bounds for Disjoint Cycles and Disjoint Paths. In: Fiat, A., Sanders, P. (eds.) ESA 2009. LNCS, vol. 5757, pp. 635–646. Springer, Heidelberg (2009) 5. Borie, R.B., Parker, G.R., Tovey, C.A.: Automatic Generation of Linear-Time Algorithms from Predicate Calculus Descriptions of Problems on Recursively Constructed Graph Families. Algorithmica 7, 555–581 (1992)

30

S. Arumugam et al.

6. Chellali, M., Maﬀray, F.: Dominator colorings in some classes of graphs. Graphs and Combinatorics, 1–11 (2011) 7. Courcelle, B.: The monadic second-order logic of graphs. i. recognizable sets of ﬁnite graphs. Information and Computation 85(1), 12–75 (1990) 8. Courcelle, B.: The expression of graph properties and graph transformations in monadic second-order logic. In: Rozenberg, G. (ed.) Handbook of Graph Grammars and Computing by Graph Transformations: Foundations, ch. 5, vol. 1. World Scientiﬁc (1997) 9. Courcelle, B., Mosbah, M.: Monadic second-order evaluations on treedecomposable graphs. Theoretical Computer Science 109(1-2), 49–82 (1993) 10. Downey, R.G., Fellows, M.R.: Parameterized Complexity. Springer, New York (1999) 11. Downey, R.G., Fellows, M.R., McCartin, C., Rosamond, F.: Parameterized approximation of dominating set problems. Information Processing Letters 109(1), 68–70 (2008) 12. Feige, U.: A threshold of ln n for approximating set cover. Journal of the ACM 45(4), 634–652 (1998) 13. Feige, U., Hajiaghayi, M., Lee, J.R.: Improved approximation algorithms for minimum-weight vertex separators. SIAM Journal on Computing 38(2), 629–657 (2008) 14. Flum, J., Grohe, M.: Parameterized Complexity Theory. Texts in Theoretical Computer Science. An EATCS Series. Springer, Berlin (2006) 15. Fomin, F.V., Golovach, P., Thilikos, D.M.: Contraction Bidimensionality: The Accurate Picture. In: Fiat, A., Sanders, P. (eds.) ESA 2009. LNCS, vol. 5757, pp. 706–717. Springer, Heidelberg (2009) 16. Fomin, F.V., Thilikos, D.M.: Dominating sets in planar graphs: Branch-width and exponential speed-up. SIAM Journal on Computing 36(2), 281–309 (2006) 17. Garey, M.R., Johnson, D.S.: Computers and Intractability: A Guide to the Theory of NP–Completeness. Freeman, San Francisco (1979) 18. Garey, M.R., Johnson, D.S., Stockmeyer, L.: Some simpliﬁed NP-complete graph problems. Theoretical Computer Science 1, 237–267 (1976) 19. Gavril, F.: Algorithms for minimum coloring, maximum clique, minimum covering by cliques, and maximum independent set of a chordal graph. SIAM Journal on Computing 1(2), 180–187 (1972) 20. Gera, R.: On dominator coloring in graphs. In: Graph Theory Notes of New York, pp. 25–30. LII (2007) 21. Gera, R.: On the dominator colorings in bipartite graphs. In: ITNG, pp. 1–6. IEEE (2007) 22. Gera, R., Rasmussen, C., Horton, S.: Dominator colorings and safe clique partitions. Congressus Numerantium 181(7-9), 19–32 (2006) 23. Halldórsson, M.M.: A still better performance guarantee for approximate graph coloring. Information Processing Letters 45(1), 19–23 (1993) 24. Hedetniemi, S., Hedetniemi, S., McRae, A., Blair, J.: Dominator colorings of graphs (2006) (preprint) 25. Johnson, D.S.: Approximation algorithms for combinatorial problems. Journal of Computer and System Sciences 9(3), 256–278 (1974) 26. Lovász, L.: On the ratio of optimal integral and fractional covers. Discrete Mathematics 13, 383–390 (1975) 27. Lund, C., Yannakakis, M.: On the hardness of approximating minimization problems. Journal of the ACM 41(5), 960–981 (1994)

Parameterized Longest Previous Factor Richard Beal and Donald Adjeroh West Virginia University, Lane Department of Computer Science and Electrical Engineering, Morgantown, WV 26506 [email protected], [email protected]

Abstract. The longest previous factor (LPF) problem is deﬁned for traditional strings exclusively from the constant alphabet Σ. A parameterized string (p-string) is a sophisticated string composed of symbols from a constant alphabet Σ and a parameter alphabet Π. We generalize the LPF problem to the parameterized longest previous factor (pLPF) problem deﬁned for p-strings. Subsequently, we present a linear time solution to construct the pLP F array. Given our pLPF algorithm, we show how to construct the pLCP (parameterized longest common preﬁx) array in linear time. Our algorithm is further exploited to construct the standard LP F and LCP arrays all in linear time. Keywords: parameterized suﬃx array, parameterized longest common preﬁx, p-string, p-match, LPF, LCP.

1

Introduction

Given an n-length traditional string W = W [1]W [2]...W [n] from the alphabet Σ, the longest previous factor (LPF) problem is to determine the maximum length of a previously occurring factor for each suﬃx occurring in W . More formally, for any suﬃx u beginning at index i in the string W , the LPF problem is to identify the length of the longest factor between u and another suﬃx v at some position h before i in W : that is, 1 ≤ h < i. The LPF problem, introduced by Crochemore and Ilie [1], yields a data structure convenient for fundamental applications such as string compression [2] and detecting runs [3] within a string. In order to compute the LP F array, it is shown in [1] that the suﬃx array SA is useful to quickly identify the most lexicographically similar suﬃxes that constitute as previous factors for the chosen suﬃx in question. The use of SA expedites the work required to solve the LPF problem and likewise, is the cornerstone to solutions for many problems deﬁned for traditional strings. A generalization of traditional strings over an alphabet Σ is the parameterized string (p-string), introduced by Baker [4]. A p-string is a production of symbols from the alphabets Σ and Π, which represent the constant symbols and parameter symbols respectively. The parameterized pattern matching

This work was partly supported by a grant from the National Historical Publications & Records Commission.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 31–43, 2011. c Springer-Verlag Berlin Heidelberg 2011

32

R. Beal and D. Adjeroh

(p-match) problem is to identify an equivalence between a pair of p-strings S and T when 1) the individual constant symbols match and 2) there exists a bijection between the parameter symbols of S and T . For example, the following p-strings that represent program statements z=y ∗ f /++y; and a=b ∗ f /++b; over the alphabets Σ = {∗, /, +, =, ; } and Π = {a, b, f, y, z} satisfy both conditions and thus, the p-strings p-match. The motivation for addressing a problem in terms of p-strings is the range of problems that a single solution can address, including 1) exact pattern matching when |Π| = 0, 2) mapped matching (m-matching) when |Σ| = 0 [5], and clearly, 3) p-matching when |Σ| > 0 ∧ |Π| > 0. Prominent applications concerned with the p-match problem include detecting plagiarism in academia and industry, reporting similarities in biological sequences [6], discovering cloned code segments in a program [7], and even answering critical legal questions regarding the unauthorized use of intellectual property [8]. In this work, we introduce the parameterized longest previous factor (pLPF) for p-strings analogous to the LPF problem for traditional strings, which can similarly be used to study compression and duplication within p-strings. Given an n-length p-string T = T [1]T [2]...T [n], the pLPF problem is to determine the longest parameterized suﬃx (p-suﬃx) v at position h for a p-suﬃx starting at i in T with 1 ≤ h < i. Our approach uses a parameterized suﬃx array (pSA) [9,10,11,12] for p-strings analogous to the traditional suﬃx array [13]. The major diﬃculty of the pLPF problem is that unlike traditional suﬃxes of a string, the p-suﬃxes are dynamic, varying with the starting position of the p-suﬃx. Thus, traditional LPF solutions cannot be directly applied to the pLPF problem. Main Contributions: We generalize the LPF problem for traditional strings to the parameterized longest previous factor (pLPF) problem deﬁned for pstrings. Then, we present a linear time algorithm for constructing the pLP F data structure. Traditionally, the LPF problem is solved by using the longest common preﬁx (LCP ) array. This was one approach used in [1]. In this work, we show how to go in the reverse direction: that is, given the pLPF solution, we now construct the pLCP array. Further, we identify how to exploit our algorithm for the pLPF problem to construct the LP F and LCP arrays. Our main results are stated in the following theorems: Theorem 1. Given an n-length p-string T , prevT = prev(T ), the prev encoding of T , and pSA, the parameterized suﬃx array for T , the algorithm compute pLPF constructs the pLP F array in O(n) time. Theorem 2. Given an n-length p-string T , prevT = prev(T ), the prev encoding of T , and pSA, the parameterized suﬃx array for T , the compute pLPF algorithm can be used to construct the pLCP array in O(n) time.

2

Background / Related Work

Baker [7] identiﬁes three types of pattern matching: 1) exact matching, 2) parameterized matching (p-match), and 3) matching with modiﬁcations. The ﬁrst p-match breakthroughs, namely, the prev encoding and the parameterized suﬃx

Parameterized Longest Previous Factor

33

tree (p-suﬃx tree) that demands the worst case construction time of O(n(|Π| + log(|Π| + |Σ|))), were introduced by Baker [4]. Like the traditional suﬃx tree [14,15,16], the p-suﬃx tree [4] implementation suﬀers from a large memory footprint. Other solutions that address the p-match problem without the space limitations of the p-suﬃx tree include the parameterized-KMP [5] and parameterized-BM [17], variants of traditional pattern matching approaches. Idury et al. [18] studied the multiple p-match problem using automata. The parameterized suﬃx array (p-suﬃx array) and the parameterized longest common preﬁx (pLCP ) array combination is analogous to the suﬃx array and LCP array for traditional strings [13,14,15,16], which is both time and space eﬃcient for pattern matching. Direct p-suﬃx array and pLCP construction was ﬁrst introduced by Deguchi et al. [10] for binary strings with |Π| = 2, which required O(n) work. Deguchi and colleagues [9] later proposed the ﬁrst approach to psuﬃx sorting and pLCP construction with an arbitrary alphabet size requiring O(n2 ) time in the worst case. We introduce new algorithms in [11,12] to p-suﬃx sort in linear time on average using coding methods from information theory. Table 1. LPF calculation for string W = AAABABAB$ i 1 2 3 4 5 6 7 8 9

SA[i] 9 1 2 7 5 3 8 6 4

W [SA[i]...n] LCP [i] $ 0 AAABABAB$ 0 AABABAB$ 2 AB$ 1 ABAB$ 2 ABABAB$ 4 B$ 0 BAB$ 1 BABAB$ 3

W [i...n] LP F [i] AAABABAB$ 0 AABABAB$ 2 ABABAB$ 1 BABAB$ 0 ABAB$ 4 BAB$ 3 AB$ 2 B$ 1 $ 0

In a novel application of the suﬃx array and the corresponding LCP array, Crochemore and Ilie [1] introduced the longest previous factor (LPF) problem for traditional strings. Table 1 shows an example LPF for a short sequence W = AAABABAB$. For any suﬃx u beginning at index i in string W , the LPF problem is to identify the exact matching longest factor between u and another suﬃx v starting prior to index i in W . We note that this deﬁnition is similar to (though not the same as) the P rior array used in [14]. Crochemore and Ilie [1] exploited the notion that the nearby elements within a suﬃx array are closely related en route to proposing a linear time solution to the LPF problem. They also proposed another linear time algorithm to compute the LP F array by using the LCP structure. The signiﬁcance of an eﬃcient solution to the LPF is that the resulting data structure simpliﬁes computations in various string analysis procedures. Typical examples include computing the LempelZiv factorization [2,19], which is fundamental in string compression algorithms such as the UNIX gzip utility [14,15] and in algorithms for detecting repeats in a

34

R. Beal and D. Adjeroh

string [3]. Our motivation to study the LPF in terms of p-strings is the power of parameterization with relevance to various important applications.

3

Preliminaries

A string on an alphabet Σ is a production T = T [1]T [2]...T [n] from Σ n with n = |T | the length of T . We will use the following string notations: T [i] refers to the ith symbol of string T , T [i...j] refers to the substring T [i]T [i + 1]...T [j], and T [i...n] refers to the ith suﬃx of T : T [i]T [i + 1]...T [n]. Parameterized pattern matching requires the ﬁnite alphabets Σ and Π. Alphabet Σ denotes the set of constant symbols while Π represents the set of parameter symbols. Alphabets are deﬁned such that Σ ∩ Π = ∅. Furthermore, we append the terminal symbol $∈ / Σ ∪ Π to the end of all strings to clearly distinguish between suﬃxes. For practical purposes, we can assume that |Σ| + |Π| ≤ n since otherwise a single mapping can be used to enforce the condition. Deﬁnition 1. Parameterized String (p-string): A p-string is a production T of length n from (Σ ∪ Π)∗ $. Consider the alphabet arrangements Σ = {A, B} and Π = {w, x, y, z}. Example p-strings include S = AxByABxy$, T = AwBzABwz$, and U = AyByAByy$. Deﬁnition 2. ([4,10]) Parameterized Matching (p-match): A pair of pstrings S and T are p-matches with n = |S| if and only if |S| = |T | and each 1 ≤ i ≤ n corresponds to one of the following: 1. S[i], T [i] ∈ (Σ ∪ {$}) ∧ S[i] = T [i] 2. S[i], T [i] ∈ Π ∧ ((a) ∨ (b)) /* parameter bijection */ (a) S[i] = S[j], T [i] = T [j] for any 1 ≤ j < i (b) S[i] = S[i − q] iﬀ T [i] = T [i − q] for any 1 ≤ q < i In our example, we have a p-match between the p-strings S and T since every constant/terminal symbol matches and there exists a bijection of parameter symbols between S and T . U does not satisfy the parameter bijection to p-match with S or T . The process of p-matching leads to deﬁning the prev encoding. Deﬁnition 3. ([4,10]) Previous (prev) Encoding: Given Z as the set of non-negative integers, the function prev : (Σ ∪ Π)∗ $ → (Σ ∪ Z)∗ $ accepts a p-string T of length n and produces a string Q of length n that 1) encodes constant/terminal symbols with the same symbol and 2) encodes parameters to point to previous like-parameters. More formally, Q is constructed of individual Q[i] with ⎧ 1 ≤ i ≤ n where: ⎨ T [i], if T [i] ∈ (Σ ∪ {$}) 0, if T [i] ∈ Π ∧ T [i] = T [j] for any 1 ≤ j < i Q[i] = ⎩ i − k, if T [i] ∈ Π ∧ k = max{j|T [i] = T [j], 1 ≤ j < i}

Parameterized Longest Previous Factor

35

For a p-string T of length n, the above O(n) space prev encoding requires the construction time of order O(n log(min{n, |Π|})), which follows from the discussions of Baker [4,17] and Amir et al. [5] on the dependency of alphabet Π in p-match applications. Given an indexed alphabet and an auxiliary O(|Π|) mapping structure, we can construct prev in O(n) time. Using Deﬁnition 3, our working examples evaluate to prev(S) = A0B0AB54$, prev(T ) = A0B0AB54$, prev(U ) = A0B2AB31$. The relationship between p-strings and the lexicographical ordering of the prev encoding is fundamental to the p-match problem. Deﬁnition 4. prev Lexicographical Ordering: Given the p-strings S and T and two symbols s and t from the encodings prev(S) and prev(T ) respectively, the relationships =, =, refer to lexicographical ordering between s and t. We deﬁne the ordering of symbols from a prev encoding of the production (Σ ∪ Z)∗ $ to be $ < ζ ∈ Z < σ ∈ Σ, where each ζ and σ is lexicographically sorted in their respective alphabets. The relationships =, =, ≺, and

refer to the lexicographical ordering between strings. In the case of prev(S) and prev(T ), prev(S) ≺ prev(T ) when prev(S)[1] = prev(T )[1], prev(S)[2] = prev(T )[2], ..., prev(S)[j −1] = prev(T )[j −1], prev(S)[j] < prev(T )[j] for some j, j ≥ 1. Similarly, we can deﬁne =k , =k , ≺k , and k to refer to the lexicographical relationships between a pair of p-strings considering only the ﬁrst k ≥ 0 symbols. It is shown in [11,12] how to map a symbol in prev to an integer based on the ordering of Deﬁnition 4 and subsequently, call the function in(x, X) to answer alphabet membership questions of the form x ∈ X in constant time. The following proposition essential to the p-matching problem is directly related to the established symbol ordering. Proposition 1. ([4]) Two p-strings S and T p-match when prev(S) = prev(T ). Also, S ≺ T when prev(S) ≺ prev(T ) and S T when prev(S) prev(T ). The example prev encodings show a p-match between S and T since prev(S) = A0B0AB54$ and prev(T ) = A0B0AB54$. Also, U S and U T since prev(U ) = A0B2AB31$ prev(S) = prev(T ) = A0B0AB54$. We use the ordering established in Deﬁnition 4 to deﬁne the parameterized suﬃx array and the parameterized longest common preﬁx array. Deﬁnition 5. Parameterized Suﬃx Array (pSA): The pSA for a p-string T of length n maintains a lexicographical ordering of the indices i representing individual p-suﬃxes prev(T [i...n]) with 1 ≤ i ≤ n, such that prev(T [pSA[q]...n]) ≺ prev(T [pSA[q + 1]...n])∀q, 1 ≤ q < n. Deﬁnition 6. Parameterized Longest Common Preﬁx (pLCP ) Array: The pLCP array for a p-string T of length n maintains the length of the longest common preﬁx between neighboring p-suﬃxes. We deﬁne plcp(α, β) = max{k|prev(α) =k prev(β)}. Then, pLCP [1] = 0 and pLCP [i] = max{k | plcp (T [pSA[i]...n], T [pSA[i − 1]...n])}, 2 ≤ i ≤ n.

36

R. Beal and D. Adjeroh

For the example T = AwBzABwz$ with prev(T ) = A0B0AB54$, we have pSA = {9, 8, 7, 4, 2, 1, 5, 6, 3} and pLCP = {0, 0, 1, 1, 1, 0, 1, 0, 2}. The encoding prev is supplemented by the encoding forw. Deﬁnition 7. ([11,12]) Forward (forw) Encoding: Let the function rev(T ) reverse the p-string T and repl(T, x, y) replace all occurrences in T of the symbol x with y. We deﬁne the function forw for the p-string T of length n as forw(T ) = rev(repl(prev(rev(T )), 0, n)). For a p-string T of length n, the encoding forw 1) encodes constant/terminal symbols with the same symbol and 2) encodes each parameter p with the forward distance to the next occurrence of p or an unreachable forward distance n. Our deﬁnition of forw generates output mirroring the fw encoding used by Deguchi et al. [9,10]. The forw encodings in our example with n = 9 are forw(S) = A5B4AB99$, forw(T ) = A5B4AB99$, forw(U ) = A2B3AB19$. Deﬁnition 8. ([1]) Longest Previous Factor (LP F ): For an n-length traditional string W , the LPF is deﬁned for each index 1 ≤ i ≤ n such that LP F [i] = max({0} ∪ {k | W [i...n] =k W [h...n], 1 ≤ h < i}). The traditional string W = AAABABAB$ yields LP F = {0, 2, 1, 0, 4, 3, 2, 1, 0}.

4

Parameterized LPF

We deﬁne the parameterized longest previous factor (pLPF) problem as follows to generalize the traditional LPF problem to p-strings. Deﬁnition 9. Parameterized Longest Previous Factor (pLP F ): For a pstring T of length n, the pLPF array is deﬁned for each index 1 ≤ i ≤ n to maintain the length of the longest factor between a p-suﬃx and a previous psuﬃx occurring in T . More formally, pLP F [i] = max({0}∪{k | prev(T [i...n]) =k prev(T [h...n]), 1 ≤ h < i}). The pLPF problem requires that we deal with p-suﬃxes, which are suﬃxes encoded with prev. This task is more demanding than the LPF for traditional strings because Lemma 1 indicates that we cannot guarantee the individual suﬃxes of a single prev encoding to be p-suﬃxes. Thus, the changing nature of the prev encoding poses a major challenge to eﬃcient and correct construction of the pLP F array using current algorithms that construct the LP F array for traditional strings. The proof is provided in [12] and omitted for space. Lemma 1. Given a p-string T of length n, the suﬃxes of prev(T ) are not necessarily the p-suﬃxes of T. More formally, if π ∈ Π occurs more than once in T , then ∃i, s.t. prev(T [i...n]) = prev(T )[i...n], 1 ≤ i ≤ n. Consider the p-string T = AAAwBxyyAAAzwwB$ using the previously deﬁned alphabets. Table 2 shows the pLPF computation for the p-string T . We note the intricacies of Lemma 1 since simply using the traditional LPF algorithm 1)

Parameterized Longest Previous Factor

37

Table 2. pLPF calculation for p-string T = AAAwBxyyAAAzwwB$ i 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

pSA[i] 16 6 12 7 13 8 14 4 11 3 10 2 9 1 15 5

pLCP [i] 0 0 3 1 2 1 1 2 0 2 1 3 2 4 0 1

prev(T [pSA[i]...n]) $ 001AAA001B$ 001B$ 01AAA001B$ 01B$ 0AAA001B$ 0B$ 0B001AAA091B$ A001B$ A0B001AAA091B$ AA001B$ AA0B001AAA091B$ AAA001B$ AAA0B001AAA091B$ B$ B001AAA001B$

bef ore< [pSA[i]] -1 -1 6 6 7 7 8 -1 4 -1 3 -1 2 -1 1 1

bef ore> [pSA[i]] 6 4 7 4 8 4 4 3 3 2 2 1 1 -1 5 -1

pLP F [i] 0 2 1 0 0 1 1 1 4 3 2 3 2 2 1 0

with T yields LP F = {0, 2, 1, 0, 0, 0, 0, 1, 3, 2, 1, 0, 1, 2, 1, 0}, 2) with prev(T ) produces LP F = {0, 2, 1, 0, 0, 1, 1, 0, 4, 3, 2, 1, 0, 1, 1, 0}, and 3) with forw(T ) generates LP F = {0, 2, 1, 0, 0, 0, 0, 1, 3, 2, 1, 3, 2, 1, 1, 0}, neither of which is the correct pLP F array. Crochemore and Ilie [1] eﬃciently solve the LPF problem for a traditional string W by exploiting the properties of the suﬃx array SA. They construct the arrays prev< [1...n] and prev> [1...n], which for each i in W maintain the suﬃx h < i positioned respectively before and after suﬃx i in SA; when no such suﬃx exists, the element is denoted by −1. The conceptual idea to compute the prev< and prev> arrays in linear time via deletions in a doubly linked list of the SA was suggested in [1]. The algorithm is given in [12]. Furthermore, we will refer to prev< and prev> as bef ore< and bef ore> respectively, in order to avoid confusion with the prev encoding for p-strings. Then, LP F [i] is the maximum q between W [i...n] =q W [bef ore< [i]...n] and W [i...n] =q W [bef ore> [i]...n]. The magic of a linear time solution to constructing the LP F array is achieved through the computation of an element by extending the previous element, more formally LP F [i] ≥ LP F [i − 1] − 1, which is a variant of the extension property used in LCP construction proven by Kasai et al. [20]. We prove that this same property holds for the pLPF problem deﬁned on p-strings. Lemma 2. The pLP F for a p-string T of length n is such that pLP F [i] ≥ pLP F [i − 1] − 1 with 1 < i ≤ n. Proof. Consider pLP F [i] at i = 1 by which Deﬁnition 9 requires that we ﬁnd a previous factor at 1 ≤ h < 1 that does not exist; i.e., pLP F [1] = 0. At i = 2, indeed pLP F [2] ≥ pLP F [1] − 1 = −1 is clearly true for all succeeding elements

38

R. Beal and D. Adjeroh

Algorithm 1. pLPF computation 1 2 3 4 5 6 7 8 9 10

i n t [ ] compute pLPF ( i n t b e f o r e < [ ] , i n t b e f o r e > [ ] ) { i n t pLPF [ n ] , pLPF< =0 , pLPF> =0 , i , j , k f o r i = 1 to n { j = max{0 ,pLPF< −1} k = max{0 ,pLPF> −1} i f ( b e f o r e < = null ) pLPF< = Λ ( i , b e f o r e < [ i ] , j ) i f ( b e f o r e > = null ) pLPF> = Λ ( i , b e f o r e > [ i ] , k ) pLPF [ i ] = max{pLPF< ,pLPF> } } return pLPF }

Algorithm 2. p-matcher function Λ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

int Λ( int a , int b , int q ) { boolean c = true int x , y i f ( b = −1) return 0 while ( c ∧ ( a+q ) ≤ n ∧ ( b+q ) ≤ n ) { x = prevT [ a+q ] , y = prevT [ b+q ] i f ( in ( x , Σ ) ∧ in ( y , Σ ) ) { i f ( x = y ) q++ else c = false } e l s e i f ( in ( x , Z ) ∧ in ( y , Z ) ) { if (q < x) x = 0 if (q < y) y = 0 i f ( x = y ) q++ else c = false } else c = false } return q }

in which a previous factor does not exist. For arbitrary i = j with 1 < j < n, suppose that the maximum length factor is at g < j and without loss of generality, consider that the ﬁrst q ≥ 2 symbols match so that prev(T [j...n]) =q prev(T [g...n]). Thus, pLP F [j] = q. Shifting the computation to i = j +1, we lose the symbols prev(T [j]) and prev(T [g]) in the p-suﬃxes at j and g respectively. By Proposition 1, prev(T [j...j + q − 1]) = prev(T [g...g + q − 1]) ⇒ prev(T [j]) = prev(T [g]) and as a consequence of the prev encoding in Deﬁnition 3 we have prev(T [i...n]) =q−1 prev(T [g + 1...n]). Since we can guarantee that ∃ a factor with (q − 1) symbols for pLP F [i] or possibly ﬁnd another factor at h with 1 ≤ h < i matching q or more symbols, the lemma holds. Lemma 2 permits us to adapt the algorithm compute LPF given in [1] to p-strings. We introduce compute pLPF in Algorithm 1 to construct the pLP F array, which makes use of the p-matcher Λ in Algorithm 2 to properly handle the sophisticated

Parameterized Longest Previous Factor

39

matching of p-suﬃxes, the dynamic suﬃxes under the prev encoding. The role of Λ is to extend the matches between the p-suﬃxes at a and b beyond the initial q symbols by directly comparing constant/terminal symbols and comparing the dynamically adjusted parameter encodings for each p-suﬃx. Theorem 1. Given an n-length p-string T , prevT = prev(T ), the prev encoding of T , and pSA, the parameterized suﬃx array for T , the algorithm compute pLPF constructs the pLP F array in O(n) time. Proof. It follows from Lemma 2 that our algorithm exploits the properties of pLPF to correctly compute and extend factors, which requires O(n) time. Computing the arrays bef ore< and bef ore> require O(n) processing [12]. What remains now is to show that, between Algorithm 1 and Algorithm 2, the total number of times that the body of the while loop (lines 6-15 in Algorithm 2) will be executed is in O(n). The number of iterations of the while loop is given by the number of matching symbol comparisons, namely the number of increments of the variable q, which identiﬁes the shift required to compare the current symbol. Without loss of generality, suppose that the initial p-suﬃxes at position a and b are the longest suﬃxes at positions 1 and 2 in T of lengths n and (n − 1) respectively. In the worst case, (n − 1) of the symbols will match between these suﬃxes, by which each comparison that clearly requires O(1) work, will increment q. Lemma 2 indicates that succeeding calculations, or calls to Λ, already match at least (q − 1) symbols that are not rematched and rather, the match is extended. Since the decreasing lengths of the succeeding suﬃxes at 3, 4, ..., n cannot extend the current q, no further matching or increments of q are needed. Hence, the while loop iterates a total of O(n) times amortized across all of the n iterations of the for loop in Algorithm 1. Thus, the total work is O(n). Our algorithm compute pLPF is motivated by the compute LPF algorithm in [1]. We also observe that similar pattern matching mechanisms as the one used between the for loop in Algorithm 1 and the while loop in Algorithm 2 exist in standard string processing, for example in computing the border array discussed in [15].

5

From pLPF to pLCP

Deguchi et al. [9,10] studied the problem of constructing the pLCP array given the pSA. They showed that constructing the pLCP array requires a non-trivial modiﬁcation of the traditional LCP construction by Kasai et al. [20]. In [1], the LCP array was used as the basis for constructing the LP F array for traditional strings. Here, we present a simpler algorithm for constructing the pLCP array. In particular, we show that, unlike in [1], it is possible to go the other way around: that is, given the pLPF solution, we now construct the pLCP array. Later, we show that the same pLPF algorithm can be used to construct the LCP array and the LP F array for traditional strings. Crochemore and Ilie [1] identify that the traditional LP F array is a permutation of the well-studied LCP array. We observe the same relationship in terms of the pLP F and pLCP arrays.

40

R. Beal and D. Adjeroh

Proposition 2. The pLP F array is a permutation of pLCP . This observation allows us to view the pLCP array from a diﬀerent perspective. As a novel use of our compute pLPF algorithm, we introduce a way to construct the pLCP array in linear time. The key observation is that we can integrate the fact that the pLCP occurs between neighboring p-suﬃxes and the fact that we preprocess the bef ore< array, which for each i in the p-string T maintains the p-suﬃx h < i positioned prior to the p-suﬃx i in pSA. We can also construct the array af ter< to maintain the p-suﬃx j > i also positioned prior to the p-suﬃx i in pSA. Since h and j are both positioned prior to i in pSA, we can guarantee that either h or j must be the nearest neighbor to i. So, the maximum factor determines the nearest neighbor and thus, pLCP [R[i]], where R is the inverse of pSA (see Algorithm 3). Theorem 2 shows that this computation is performed in linear time. Algorithm 3. pLCP computation 1 2 3 4 5 6 7 8 9

i n t [ ] compute pLCP ( i n t b e f o r e < [ ] , i n t a f t e r < [ ] ) { i n t pLCP [ n ] , M[ n ] , R[ n ] , i f o r i = 1 to n R[ pSA [ i ] ] = i M = compute pLPF ( b e f o r e < , a f t e r < ) f o r i = 1 to n pLCP [R [ i ] ] = M[ i ] return pLCP }

Theorem 2. Given an n-length p-string T , prevT = prev(T ), the prev encoding of T , and pSA, the parameterized suﬃx array for T , the compute pLPF algorithm can be used to construct the pLCP array in O(n) time. Proof. We can clearly relax the p-suﬃx selection restrictions enforced by the problem pLPF in Lemma 2 to exploit the idea of extending factors. Subsequently, only the parameters of Algorithms 1 and 2 impose such restrictions. Let R[1...n] be the rank array, the inverse of pSA. We prove that the pLCP is constructed with compute pLPF(bef ore< , af ter< ). Let bef ore< [1...n] and af ter< [1...n] maintain, for all the i in T , the p-suﬃxes h < i at position R[h] in pSA and j > i at position R[j] in pSA, respectively, that are positioned prior to the p-suﬃx i at position R[i] in pSA; when no such suﬃx exists, the element is denoted by −1. Without loss of generality, suppose that both h and j exist and 2 < i ≤ n, so we have either R[j] = R[i]−1 or R[h] = R[i]−1 as the neighboring p-suﬃx. So, max{plcp(prev(T [h...n]), prev(T [i...n])), plcp(prev(T [j...n]), prev(T [i...n]))} distinguishes which p-suﬃx h or j is closer to i, identifying the nearest neighbor and in turn, pLCP [R[i]]. This statement is utilized in compute pLPF exactly in terms of factors except that the value will be stored in pLCP [i]. So, after the computation using the call to compute pLPF (line 5) in Algorithm 3, rearranging the resulting array using the rank array R (lines 6-7) produces the required

Parameterized Longest Previous Factor

41

pLCP array. We have yet to prove the time complexity. Since the parameter af ter< can be computed in O(n) by deletions and indexing into a doubly linked list similar to bef ore< [12] and since compute pLPF executes in O(n) time via Theorem 1, the theorem holds. Algorithm 4. Improved pLCP computation 1 2 3 4 5 6 7 8 9 10

i n t [ ] compute pLCP ( ) { i n t pLCP [ n ] , M[ n ] , i M[ pSA [ 1 ] ] = −1 f o r i = 2 to n M[ pSA [ i ] ] = pSA [ i −1] M = compute pLPF (M, null ) f o r i = 1 to n pLCP [ i ] = M[ pSA [ i ] ] return pLCP }

For discussion purposes, Algorithm 3 uses a rank array R to index and preprocess the arrays bef ore< and af ter< to determine the neighboring suﬃx, which can be found trivially with a p-suﬃx array, and thus, may be omitted for practical space. The improved solution is shown in Algorithm 4. For further improved space consumption, the implementation of Algorithm 4 may incorporate the LCP indexing contributions of [21]. In passing, we identify that upon the completion of line 6 in Algorithm 4, the M array is the permuted longest common preﬁx (P LCP ) data structure observed in [22] for traditional strings.

6

From pLPF to LPF and LCP

The power of deﬁning the pLPF problem in terms of p-strings is the generalization of a p-string production. We show in Theorems 3 and 4 that our compute pLPF algorithm also computes the traditional LP F and LCP arrays. Theorem 3. Given an n-length traditional string W , the compute pLPF algorithm constructs the LP F array in O(n) time. Proof. Since W [i] ∈ Σ ∀ i, 1 ≤ i < n and W [n] ∈ {$}, then by Deﬁnition 1 we have W ∈ (Σ ∪Π)∗ $, which classiﬁes W as a valid p-string. Given this, Theorem 1 proves that the construction of pLP F for a p-string requires O(n) time. In this special case, W consists of no such symbol π ∈ Π so Lemma 1 identiﬁes that prev(W [i...n]) = prev(W )[i...n] and further W = prev(W ) by Deﬁnition 3, so W [i...n] = prev(W )[i...n], which constrains the pLPF in Deﬁnition 9 to the LPF problem in Deﬁnition 8. Thus, from Theorem 1, compute pLPF computes the LPF of W . Theorem 4. Given an n-length traditional string W , the compute pLCP algorithm constructs the LCP array in O(n) time.

42

R. Beal and D. Adjeroh

Proof. In the same manner as Theorem 3, we may classify W as a valid pstring. Given this, Theorem 2 proves that the construction of pLCP for a pstring requires O(n) time. Mirroring the proof of Theorem 3, we have W [i...n] = prev(W )[i...n], which constrains the pLCP in Deﬁnition 6 to the traditional LCP problem. Thus, from Theorem 2, compute pLCP computes the LCP of W .

7

Conclusion and Discussion

We introduce the parameterized longest previous factor (pLPF) problem for p-strings, which is analogous to the longest previous factor (LPF) problem deﬁned for traditional strings. A linear time algorithm is provided to construct the pLP F array for a given p-string. The advantage of implementing our solution compute pLPF is that the algorithm may be used to compute the arrays pLP F , pLCP , LP F , LCP , or even the permuted LCP [22] in linear time, which are fundamental data structures preprocessed for the eﬃciency of countless pattern matching applications. Each of the proposed algorithms requires O(n) worst case time and O(n) worst case space. Since we provide construction algorithms for several data structures using the pLP F construction as the groundwork, we are faced with the practical limitation that our algorithms are only as eﬃcient as the compute pLPF solution. We acknowledge that it is possible to use the techniques in [22,23,24] to improve the space consumption of the LCP array and similarly, the pLCP data structure, since pLCP is an array of integers analogous to the traditional LCP . Nonetheless, the signiﬁcance of working though the LPF as an intermediate data structure is the straightforward and space eﬃcient algorithm to construct the Lempel-Ziv (LZ) factorization [1,2,19]. Similarly, the pLP F array can easily derive the LZ structure and allow us to study such applications as maximal runs in p-strings extended to source code plagiarism or redundancies in biological sequences.

References 1. Crochemore, M., Ilie, L.: Computing longest previous factor in linear time and applications. Inf. Process. Lett. 106(2), 75–80 (2008) 2. Ziv, J., Lempel, A.: A universal algorithm for sequential data compression. IEEE Trans. Inf. Theory 23(3), 337–343 (1977) 3. Main, M.: Detecting leftmost maximal periodicities. Discrete Appl. Math. 25(1-2), 145–153 (1989) 4. Baker, B.: A theory of parameterized pattern matching: Algorithms and applications. In: STOC 1993, pp. 71–80. ACM, New York (1993) 5. Amir, A., Farach, M., Muthukrishnan, S.: Alphabet dependence in parameterized matching. Inf. Process. Lett. 49, 111–115 (1994) 6. Shibuya, T.: Generalization of a suﬃx tree for RNA structural pattern matching. Algorithmica 39(1), 1–19 (2004) 7. Baker, B.: Finding clones with dup: Analysis of an experiment. IEEE Trans. Software Eng. 33(9), 608–621 (2007) 8. Zeidman, B.: Software v. software. IEEE Spectr. 47, 32–53 (2010)

Parameterized Longest Previous Factor

43

9. Tomohiro, I., Deguchi, S., Bannai, H., Inenaga, S., Takeda, M.: Lightweight Parameterized Suﬃx Array Construction. In: Fiala, J., Kratochv´ıl, J., Miller, M. (eds.) IWOCA 2009. LNCS, vol. 5874, pp. 312–323. Springer, Heidelberg (2009) 10. Deguchi, S., Higashijima, F., Bannai, H., Inenaga, S., Takeda, M.: Parameterized suﬃx arrays for binary strings. In: PSC 2008, Czech Republic, pp. 84–94 (2008) 11. Beal, R., Adjeroh, D.: p-Suﬃx Sorting as Arithmetic Coding. In: Iliopoulos, C.S., Smyth, W.F. (eds.) IWOCA 2011. LNCS, vol. 7056, pp. 44–56. Springer, Heidelberg (2011) 12. Beal, R.: Parameterized Strings: Algorithms and Data Structures. MS Thesis. West Virginia University (2011) 13. Manber, U., Myers, G.: Suﬃx arrays: A new method for on-line string searches. SIAM J. Comput. 22, 935–948 (1993) 14. Gusﬁeld, D.: Algorithms on Strings, Trees and Sequences: Computer Science and Computational Biology. Cambridge University Press, Cambridge (1997) 15. Smyth, W.: Computing Patterns in Strings. Pearson, New York (2003) 16. Adjeroh, D., Bell, T., Mukherjee, A.: The Burrows-Wheeler Transform: Data Compression, Suﬃx Arrays and Pattern Matching. Springer, New York (2008) 17. Baker, B.: Parameterized pattern matching by Boyer-Moore-type algorithms. In: SODA 1995, pp. 541–550. ACM, Philadelphia (1995) 18. Idury, R., Sch¨ aﬀer, A.: Multiple matching of parameterized patterns. Theor. Comput. Sci. 154, 203–224 (1996) 19. Crochemore, M., Ilie, L., Smyth, W.: A simple algorithm for computing the Lempel Ziv factorization. In: DCC 2008, pp. 482–488 (2008) 20. Kasai, T., Lee, G., et al.: Linear-time Longest-common-preﬁx Computation in Sufﬁx Arrays and its Applications. In: Amir, A., Landau, G.M. (eds.) CPM 2001. LNCS, vol. 2089, pp. 181–192. Springer, Heidelberg (2001) 21. Manzini, G.: Two Space Saving Tricks for Linear Time LCP Array Computation. In: Hagerup, T., Katajainen, J. (eds.) SWAT 2004. LNCS, vol. 3111, pp. 372–383. Springer, Heidelberg (2004) 22. K¨ arkk¨ ainen, J., Manzini, G., Puglisi, S.: Permuted Longest-common-preﬁx Array. In: Kucherov, G., Ukkonen, E. (eds.) CPM 2009 Lille. LNCS, vol. 5577, pp. 181– 192. Springer, Heidelberg (2009) 23. Puglisi, S., Turpin, A.: Space-time Tradeoﬀs for Longest-Common-preﬁx Array Computation. In: Hong, S.-H., Nagamochi, H., Fukunaga, T. (eds.) ISAAC 2008. LNCS, vol. 5369, pp. 124–135. Springer, Heidelberg (2008) 24. Fischer, J.: Wee LCP. Inf. Process. Lett. 110(8-9), 317–320 (2010)

p-Suﬃx Sorting as Arithmetic Coding Richard Beal and Donald Adjeroh Lane Department of Computer Science and Electrical Engineering, West Virginia University, Morgantown, WV 26506 [email protected], [email protected]

Abstract. The challenge of direct parameterized suﬃx sorting (p-suﬃx sorting) for a parameterized string (p-string) is the dynamic nature of parameterized suﬃxes (p-suﬃxes). In this work, we propose transformative approaches to direct p-suﬃx sorting by generating and sorting lexicographically numeric ﬁngerprints and arithmetic codes that correspond to individual p-suﬃxes. Our algorithm to p-suﬃx sort via ﬁngerprints is the ﬁrst theoretical linear time algorithm for p-suﬃx sorting for nonbinary parameter alphabets, which assumes that each code is represented by a practical integer. We eliminate the key problems of ﬁngerprints by introducing an algorithm that exploits the ordering of arithmetic codes to sort p-suﬃxes in linear time on average. Keywords: parameterized suﬃx array, parameterized suﬃx sorting, arithmetic coding, ﬁngerprints, p-string, p-match.

1

Introduction

Conventional pattern matching typically involves the matching of traditional strings over an alphabet Σ. Parameterized pattern matching using parameterized strings, introduced by Baker [1], attempts to answer pattern matching questions beyond its classical counterpart. A parameterized string (p-string) is a production of symbols from the alphabets Σ and Π, which represent the constant symbols and parameter symbols respectively. Given a pair of p-strings S and T , the parameterized pattern matching (p-match) problem is to verify whether the individual constant symbols match and whether there exists a bijection between the parameter symbols of S and T . If the two conditions are met, S is said to be a p-match of T . For example, there exists a p-match between the p-strings z=y ∗ f /++y; and a=b ∗ f /++b; that represent program statements over the alphabets Σ = {∗, /, +, =, ; } and Π = {a, b, f, y, z}. Applications inherent to the p-matching problem include detecting plagiarism in academia and industry, reporting similarities in biological sequences [2], discovering cloned code segments in a program to assist with software maintenance [1], and answering critical legal questions regarding the unauthorized use of intellectual property [3].

This work was partly supported by a grant from the National Historical Publications & Records Commission.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 44–56, 2011. c Springer-Verlag Berlin Heidelberg 2011

p-Suﬃx Sorting as Arithmetic Coding

45

Initial solutions to the p-match problem were based on the parameterized suﬃx tree (p-suﬃx tree) [1]. Idury et al. [4] studied the multiple p-match problem using automata. The physical space requirements of the p-suﬃx tree led to algorithms such as parameterized-KMP [5], parameterized-BM [6], and the parameterized suﬃx array (p-suﬃx array) [7,8]. Analogous to standard suﬃx sorting, the problem of parameterized suﬃx sorting (p-suﬃx sorting) is to sort all the n parameterized suﬃxes (p-suﬃxes) of an n-length p-string into a lexicographic order. The major diﬃculty is that unlike traditional suﬃxes of a string, the p-suﬃxes are dynamic, varying with the starting position of the psuﬃx. Thus, standard suﬃx sorting approaches cannot be directly applied to the p-suﬃx sorting problem. Current approaches to directly construct the p-suﬃx array without a p-suﬃx tree for an n-length p-string from an arbitrary alphabet require O(n2 ) time in the worst case [7]. Such demands the need for alternative approaches to direct p-suﬃx sorting. Main Contribution: We construct p-suﬃx arrays by generating and sorting codes that represent the individual p-suﬃxes of a p-string. We propose the ﬁrst theoretical linear time claims to directly p-suﬃx sort p-strings from non-binary parameter alphabets. We state our main result in the following theorem: Theorem 4. Given a p-string T of length n, p-suﬃx-sorting of T can be accomplished in O(n) time on average via parameterized arithmetic coding.

2

Background / Related Work

Baker [1] deﬁnes pattern matching as either: 1) exact matching, 2) parameterizedmatching, or 3) matching with modiﬁcations. A parameterized match (p-match) is a sophisticated matching scheme based on the composition of a parameterized string (p-string). A p-string is composed of symbols from a constant symbol alphabet Σ and a parameter alphabet Π. A pair of p-strings S and T of length n are said to p-match when the constant symbols σ ∈ Σ match and there exists a bijection of parameter symbols π ∈ Π between the pair of p-strings. Baker [1] oﬀered the ﬁrst p-match breakthroughs, namely, the prev encoding to detect a pmatch and the parameterized suﬃx tree (p-suﬃx tree) analogous to the suﬃx tree for traditional strings [9,10,11]. The p-suﬃx tree is built on the prev encodings of the suﬃxes of the p-string, demanding O(n(|Π|+log(|Π|+|Σ|))) construction time in the worst case [1]. Improvements to the p-suﬃx tree construction were introduced by Kosaraju [12]. Other contributions in the area of parameterized suﬃx trees include constructon via randomized algorithms [13,14]. Like the traditional suﬃx tree [9,10,11], the p-suﬃx tree [1] implementation suﬀers from a large memory footprint. Other solutions that address the p-match problem without the space limitations of the p-suﬃx tree include the parameterized-KMP [5] and parameterized-BM [6], variants of traditional pattern matching approaches. The native time and space eﬃciency of the suﬃx array led to the origination of the parameterized suﬃx array (p-suﬃx array). The p-suﬃx array is analogous to the suﬃx array for traditional strings introduced in [15]. Manber and Myers [15] show how to combine the suﬃx array and the LCP (longest common preﬁx)

46

R. Beal and D. Adjeroh

array to competitively search for pattern P = P [1...m] in a text T = T [1...n] in O(m + log n) time. Direct p-suﬃx array construction was ﬁrst introduced by Deguchi et al. [8] for binary strings with |Π| = 2 requiring O(n) construction time through the assistance of a deﬁned fw encoding. Deguchi and colleagues [7] later proposed the ﬁrst approach to direct p-suﬃx sorting with an arbitrary alphabet size requiring O(n2 ) time in the worst case, without the assistance of a p-suﬃx tree. The parameterized longest common preﬁx (pLCP ) array, analogous to the traditional LCP , was also deﬁned and constructed in [7,8]. In this work, we propose eﬃcient methods to the direct p-suﬃx sorting problem that avoid the large memory footprint of the p-suﬃx tree by using ﬁngerprints and coding methods from information theory.

3

Preliminaries

A string on an alphabet Σ is a production T = T [1]T [2]...T [n] from Σ n with n = |T | the length of T . We will use the following string notations: T [i] refers to the ith symbol of string T , T [i...j] refers to the substring T [i]T [i + 1]...T [j], and T [i...n] refers to the ith suﬃx of T : T [i]T [i + 1]...T [n]. The area of parameterized pattern matching deﬁnes the ﬁnite alphabets Σ and Π. Alphabet Σ denotes the set of constant symbols while Π represents the set of parameter symbols. Alphabets are deﬁned such that Σ∩Π = ∅. Furthermore, we append the terminal symbol $ ∈ / Σ ∪Π to the end of all strings to clearly distinguish between suﬃxes. For practical purposes, we can assume that |Σ|+|Π| ≤ n since, otherwise a single mapping can be used to enforce the condition. Deﬁnition 1. Parameterized String (p-string): A p-string is a production T of length n from (Σ ∪ Π)∗ $. Consider the alphabet arrangements Σ = {A, B} and Π = {w, x, y, z}. Example p-strings include S = AxByABxy$, T = AwBzABwz$, and U = AyByAByy$. Deﬁnition 2. ([1,8]) Parameterized Matching (p-match): A pair of pstrings S and T are p-matches with n = |S| if and only if |S| = |T | and each 1 ≤ i ≤ n corresponds to one of the following: 1. S[i], T [i] ∈ (Σ ∪ {$}) ∧ S[i] = T [i] 2. S[i], T [i] ∈ Π ∧ ((a) ∨ (b)) /* parameter bijection */ (a) S[i] = S[j], T [i] = T [j] for any 1 ≤ j < i (b) S[i] = S[i − q] iﬀ T [i] = T [i − q] for any 1 ≤ q < i In our example, we have a p-match between the p-strings S and T since every constant/terminal symbol matches and there exists a bijection of parameter symbols between S and T . U does not satisfy the parameter bijection to p-match with S or T . The process of p-matching leads to deﬁning the prev encoding.

p-Suﬃx Sorting as Arithmetic Coding

47

Deﬁnition 3. ([1,8]) Previous (prev) Encoding: Given Z as the set of nonnegative integers, the function prev : (Σ ∪Π)∗ $ → (Σ ∪Z)∗ $ accepts a p-string T of length n and produces a string Q of length n that 1) encodes constant/terminal symbols with the same symbol and 2) encodes parameters to point to previous like-parameters. More formally, Q is constructed of individual Q[i] with 1 ≤ i ≤ n where: ⎧ ⎨ T [i], if T [i] ∈ (Σ ∪ {$}) 0, if T [i] ∈ Π ∧ T [i] = T [j] for any 1 ≤ j < i Q[i] = ⎩ i − k, if T [i] ∈ Π ∧ k = max{j|T [i] = T [j], 1 ≤ j < i} For a p-string T of length n, the above O(n) space prev encoding demands the worst case construction time O(n log(min{n, |Π|})), which follows from the discussions of Baker [1,6] and Amir et al. [5] on the dependency of alphabet Π in p-match applications. Note that with an indexed alphabet and an auxiliary O(|Π|) mapping structure, we can construct prev in O(n) time. Using Deﬁnition 3, our examples evaluate to prev(S) = A0B0AB54$, prev(T ) = A0B0AB54$, prev(U ) = A0B2AB31$. The relationship between p-strings and the lexicographical ordering of the prev encoding is fundamental to the p-match problem. Deﬁnition 4. prev Lexicographical Ordering: Given the p-strings S and T and two symbols s and t from the encodings prev(S) and prev(T ) respectively, the relationships =, =, refer to lexicographical ordering between s and t. We deﬁne the ordering of symbols from a prev encoding of the production (Σ ∪ Z)∗ $ to be $ < ζ ∈ Z < σ ∈ Σ, where each ζ and σ is lexicographically sorted in their respective alphabets. The relationships =, =, ≺, and

refer to the lexicographical ordering between strings. In the case of prev(S) and prev(T ), prev(S) ≺ prev(T ) when prev(S)[1] = prev(T )[1], prev(S)[2] = prev(T )[2], ..., prev(S)[j −1] = prev(T )[j −1], prev(S)[j] < prev(T )[j] for some j, j ≥ 1. Similarly, we can deﬁne =k , =k , ≺k , and k to refer to the lexicographical relationships between a pair of p-strings considering only the ﬁrst k ≥ 0 symbols. The following proposition essential to the p-matching problem is directly related to the symbol ordering established in Deﬁnition 4. Proposition 1. ([1]) Two p-strings S and T p-match when prev(S) = prev(T ). Also, S ≺ T when prev(S) ≺ prev(T ) and S T when prev(S) prev(T ). The example prev encodings show a p-match between S and T since prev(S) = A0B0AB54$ and prev(T ) = A0B0AB54$. Also, U S and U T since prev(U ) = A0B2AB31$ > prev(S) = prev(T ) = A0B0AB54$. We use the ordering established in Deﬁnition 4 to deﬁne the parameterized suﬃx array. Deﬁnition 5. Parameterized Suﬃx Array (p-suﬃx array): The p-suﬃx array (pSA) for a p-string T of length n maintains a lexicographical ordering of the indices i representing individual p-suﬃxes prev(T [i...n]) with 1 ≤ i ≤ n, such that prev(T [pSA[q]...n]) ≺ prev(T [pSA[q + 1]...n])∀q, 1 ≤ q < n. The act of constructing pSA is referred to as p-suﬃx sorting.

48

R. Beal and D. Adjeroh

In the working example using T , the p-suﬃx array pSA = {9, 8, 7, 4, 2, 1, 5, 6, 3}. The encoding prev is supplemented by the encoding forw. Deﬁnition 6. Forward (forw) Encoding: Let the function rev(T ) reverse the p-string T and repl(T, x, y) replace all occurrences in T of the symbol x with y. We deﬁne the function forw for the p-string T of length n as forw(T ) = rev(repl(prev(rev(T )), 0, n)). Essentially, forw performs the following on a p-string T of length n: 1) encodes constant/terminal symbols with the same symbol and 2) encodes each parameter p with the forward distance to the next occurrence of p or an unreachable forward distance n. Our deﬁnition of the forw encoding generates output mirroring the fw encoding used by Deguchi et al. [7,8]. Let N refer to the set of positive, non-zero integers. The function fw : (Σ ∪ Π)∗ → (Σ ∪ N)∗ produces an output encoding ⎧ G with fw(T ) = G for each 1 ≤ i ≤ n: ⎨ T [i], if T [i] ∈ Σ G[i] = ∞, if T [i] ∈ Π ∧ T [i] = T [j] for any i < j ≤ n ⎩ k − i, if T [i] ∈ Π ∧ k = min{j|T [i] = T [j], i < j ≤ n} The forw encodings in our example with n = 9 are forw(S) = A5B4AB99$, forw(T ) = A5B4AB99$, forw(U ) = A2B3AB19$.

4

p-Suﬃx Sorting via Fingerprints

The magic of sorting the suﬃxes of a string T of length n from an alphabet Σ is rooted in the notion that individual suﬃxes are very closely related. Throughout this work, we are challenged with the reality that the p-suﬃx, more formally prev(T [i...n]), is not na¨ıvely the suﬃx of the prev encoding of T , namely prev(T )[i...n], which is formalized in Lemma 1. (Given space constraints, we omit the proofs of the lemmas, which are included in [16]). Lemma 1. Given a p-string T of length n, the suﬃxes of prev(T) are not necessarily the p-suﬃxes of T. More formally, if π ∈ Π occurs more than once in T , then ∃i, s.t. prev(T [i...n]) = prev(T )[i...n], 1 ≤ i ≤ n. The centerpiece of this work is the idea that we can directly construct the psuﬃx array without the large memory footprint of the p-suﬃx tree by handling the dynamically changing p-suﬃxes, which is fundamentally diﬀerent from the standard suﬃx sorting approaches for traditional strings. To visually identify the diﬀerence between traditional suﬃxes and p-suﬃxes, consider the example T = zAwz$ as a traditional string, in which the suﬃxes are methodically created by removing a symbol: zAwz$ → Awz$ → wz$ → z$ → $ . If we consider the same example T = zAwz$ with Σ = {A} and Π = {w, z}, then the p-suﬃxes deﬁned under the prev encoding are dynamically changing: 0A03$ → A00$ → 00$ → 0$ → $ . Our idea is to modify the traditional Karp and Rabin (KR) ﬁngerprinting scheme presented in [10,11,17] to accommodate the changing nature of p-suﬃxes.

p-Suﬃx Sorting as Arithmetic Coding

49

The KR algorithm generates an integral KR “signature” or “ﬁngerprint” code to represent a string using the lexicographical ordering of symbols [17]. By representing p-suﬃxes through numeric ﬁngerprints we devise a mechanism to retain a “tangible” copy of the changing p-suﬃxes under the prev encoding. In this section, we assume that n is not too large. That is, the KR codes can ﬁt into standard integer representations such as long long integer. We now denote the following variables that are continually reused throughout this section for the working p-string T of length n: prevT = prev(T ), f orwT = forw(T ), max = maxdist(prevT ) (see below), R = |Σ| + max + 2. Our ﬁngerprinting approach relies on a lexicographical ordering implementation of Deﬁnition 4 to appropriately accommodate the prev alphabet Σ ∪ Z ∪ {$}. Our ordering scheme, function map, is formalized in Deﬁnition 7. Deﬁnition 7. Mapping Function: Let max = maxdist(prevT ) = max{prevT [i] | prevT [i] ∈ Z for 1 ≤ i ≤ n}. Let function αi (x, X) return the lexicographical order (1, 2, ..., |X|) of the symbol x in alphabet X. We then deﬁne the function map : (Σ ∪Z∪{$}) → N to map a symbol, say x, in prevT to an integer preserving the ordering of Deﬁnition 4. We also deﬁne the supplement function in(x, X) to determine⎧if x ∈ X instantaneously based on the deﬁnition of map(x). ⎨ 1, if x = $ αi (x, Z) + 1, if x ∈ Z map(x) = ⎩ α ⎧ i (x, Σ) + max + 2, if x ∈ Σ ⎨ true, if X = Z ∧ (1 < map(x) ≤ max + 2) true, if X = (Σ ∪ {$}) ∧ (map(x) = 1 ∨ map(x) > max + 2) in(x, X) = ⎩ f alse, otherwise The function map is fundamental for the parameterized Karp-Rabin ﬁngerprinting (pKR) algorithm, which generates parameterized Karp-Rabin (pKR) codes. Deﬁnition 8. Parameterized Karp-Rabin (pKR) Function: Let prevTi = i k−1 prev(T [i...n]). We deﬁne pKR(i) = × map(prevTi [n − k + 1]) to k=n R return a ﬁngerprint generated for the p-suﬃx beginning at index i. Table 1 shows example ﬁngerprints using our pKR algorithm and also the standard algorithm KR for the string T = AwBzABwz$. This example shows the true power of our pKR algorithm in that the ordering of the computed ﬁngerprints for p-suﬃxes of T yields the correct p-suﬃx array pSA = {9, 8, 7, 4, 2, 1, 5, 6, 3}. We notice that using KR directly produces the array {1, 4, 5, 2, 3, 6, 7, 9, 8}, which is not the correct p-suﬃx array. The execution of function pKR may be na¨ıvely cascaded to produce ﬁngerprints for all n p-suﬃxes at positions 1 ≤ i ≤ n of p-string T requiring O(n2 ) time, which is a theoretical bottleneck. We can intelligently construct pKR codes for the p-suﬃxes of T by taking advantage of the relationship between p-suﬃxes and pKR codes. Consider qi to be the pKR code for the p-suﬃx at position i. The code qi+1 can be used to compute the ﬁngerprint for qi for i ≥ 1 by introducing a new symbol at position i. Lemmas 2 and 3 identify the adjustments that dynamically change the p-suﬃxes between the neighboring p-suﬃxes at i and (i + 1) when considering a symbol introduced at position i.

50

R. Beal and D. Adjeroh

Table 1. Lexicographical ordering of p-suﬃxes with pKR, using T = AwBzABwz$ i 1 2 3 4 5 6 7 8 9

pSA 9 8 7 4 2 1 5 6 3

T [pSA[i]...n] prev(T [pSA[i]...n]) $ $ z$ 0$ wz$ 00$ zABwz$ 0AB04$ wBzABwz$ 0B0AB54$ AwBzABwz$ A0B0AB54$ ABwz$ AB00$ Bwz$ B00$ BzABwz$ B0AB04$

pKR(pSA[i]) 43046721 90876411 96190821 129298356 130740084 358900444 388608030 398108358 401786973

KR(pSA[i]) 43046721 263063295 330556302 129593601 130740084 358900444 391501431 424148967 401819778

Lemma 2. Given p-string T , prevT = prev(T ), and prevT [i + 1...n] = prev(T [i + 1...n]) where T [i] is a constant, terminal, or the only occurrence of parameter T [i] in T [i...n], then prevT [i...n] = prev(T [i...n]) if prevT [i] = prev(T [i]). Lemma 3. Given p-string T , prevT = prev(T ), f orwT = forw(T ), and prevT [i + 1...n] = prev(T [i + 1...n]) where T [i] ∈ Π occurs multiple times in T [i...n], then prevT [i...n] = prev(T [i...n]) after 1) identifying the current parameter as the ﬁrst occurrence of T [i] (prevT [i] = 0) and 2) modifying the future occurrence of T [i] (prevT [i + f orwT [i]] = f orwT [i]). We refer to a code generated by pKR for the p-suﬃx i as qi . The transitions needed to compute a p-suﬃx i from a p-suﬃx (i + 1) formalized in Lemmas 2 and 3 are subsequently the requirements to compute code qi from qi+1 . These transitions are consolidated into δpKR and shown to eﬃciently generate pKR codes. Deﬁnition 9. Function δpKR : Let β = f orwT [i], λ = (map(β) − map(0)) × q +map(prev(T [i]))Rn Rn−β−1 , and B = i+1 . We deﬁne the function δpKR (i, qi+1 ) as R follows to return the code qi via a transition of the provided code qi+1 with the newly added symbol at position i. B, if in(prevT [i], Σ ∪ {$}) ∨ (in(prevT [i], Z) ∧ f orwT [i] ≥ n) δpKR (i, qi+1 ) = B + λ, if in(prevT [i], Z) ∧ f orwT [i] < n Theorem 1. Given a p-string T of length n and precalculated variables prevT and f orwT , function δpKR requires O(n) time to generate ﬁngerprints for all p-suﬃxes in T . Proof. The ﬁngerprints are generated successively by the function calls qn = δpKR (n, 0), qn−1 = δpKR (n − 1, qn),...,q1 = δpKR (1, q2 ). Either case of function δpKR may be computed in O(1) time and is called sequentially a total of n times, once for each of the n p-suﬃxes. The overall time is O(n). We introduce p suffix sort pKR in Algorithm 1 to sort p-suﬃxes via the sorting of ﬁngerprints through the transition function in Deﬁnition 9. Theorem 2 proves the time complexity of Algorithm 1.

p-Suﬃx Sorting as Arithmetic Coding

51

Theorem 2. Given a p-string T of length n, function p suffix sort pKR sorts all the n p-suﬃxes of T in O(n) time. Proof. We assume that the ﬁngerprints for each p-suﬃx are practically represented by an integer code and each use of the code is accomplished in constant time. Thus, Section A) of p suffix sort pKR follows from Theorem 1 to require O(n) time. The radix sorting required in section B) requires O(cn), where c is a constant. The loop in section C) clearly requires O(n) time. Overall, p suffix sort pKR requires O(n) time. The idea used in Algorithm p suffix sort pKR is novel, but assumes that the pKR ﬁngerprints ﬁt into practical integer representations. This assumption is primarily a limitation inherent to ﬁngerprinting. It is well documented that Karp-Rabin integral ﬁngerprints can be large and exceed the extremes of an integer with large strings and vast alphabets. The modulo operation discussed in [10,11,17] is used to handle this problem. However, the modulo operation will not preserve the lexicographical ordering between ﬁngerprints and creates a new problem with respect to suﬃx sorting. Even if we use ﬁngerprints to encode preﬁxes of p-suﬃxes, the codes can still be quite large with collisions. We extend our idea using arithmetic coding to address these limitations. Algorithm 1. p-suﬃx sorting with ﬁngerprints 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

struct pcode { i n t i , long long i n t pKR } i n t [ ] p suffix sort pKR ( char T [ ] ) { pcode code [ n ] , long long i n t pKR=0 i n t pSA [ n ] , k // A) −− g e n e r a t e t h e i n d i v i d u a l prev f i n g e r p r i n t s f o r k=n to 1 { pKR=δpKR ( k , pKR) code [ k ]=( k , pKR) } // B) −− s o r t p−s u f f i x e s radix sort t h e pKR a t t r i b u t e o f each p a i r i n code // C) −− r e t a i n p−s u f f i x a r r a y f o r k=1 to n pSA [ k]= code [ k ] . i return pSA }

5

p-Suﬃx Sorting via Arithmetic Coding

Arithmetic coding compresses a string by recursively dividing up a real number line into intervals that account for the cumulative distribution function (cdf ), which describes the probability space of each symbol. The interval for an arithmetic code AC is (lo, hi), where lo and hi are the low and high boundaries,

52

R. Beal and D. Adjeroh

respectively. Any consistent choice in this region, say tag(s) = s.hi+s.lo , repre2 sents the arithmetic code and preserves the lexicographical ordering of strings. Arithmetic coding is further described in [18,19]. Recently, Adjeroh and Nan [20] used a novel application of Shannon-Fano-Elias codes from information theory to address the traditional suﬃx sorting problem. In the work, they generate arithmetic codes for m-blocks, or m-length preﬁxes of the suﬃxes, to maintain the ordering of m symbols. They show how to eﬃciently transition one AC m-block code at suﬃx i to construct the m-block AC at suﬃx (i + 1) by removing the symbol at i and appending the symbol at (i + m). The transitioning scheme is illustrated in Fig. 1. In terms of suﬃx sorting with arithmetic codes in [20], the suﬃxes are recursively partitioned and the generated m-block arithmetic codes are exploited to induce the ordering of the partitions in linear time. Extending the suﬃx sorting via arithmetic coding algorithm given in [20] to the p-suﬃx sorting problem is not straightforward because of the dynamic relationship between p-suﬃxes, identiﬁed in Lemma 1.

Fig. 1. Transitioning the AC m-block code from a cab → cab → cab d

Given an n-length p-string T , we can create a parameterized arithmetic code pAC via function pAC from Deﬁnition 10 for the m-blocks, or m-length preﬁxes, of the n p-suﬃxes of T . The distribution of symbols will impact the size of the intervals and hence the tag, but this does not change the order of the generated arithmetic codes. Thus, without loss of generality, we assume that each symbol x ∈ (Σ ∪ Z ∪ {$}) in the alphabet of a prev encoding to be equally probable, where p represents the probability of a symbol and the array cdf contains the values of the uniform cdf with respect to the neighboring lexicographical alphabet symbols. The following deﬁnition modiﬁes the traditional AC algorithm to create an m-block arithmetic code for a p-suﬃx at position i in T . Deﬁnition 10. Parameterized Arithmetic Coding (pAC) Function: For an n-length p-string T , the function pAC in Algorithm 2 will generate an arithmetic code interval for the m-block of the p-suﬃx starting at position i. Table 2 shows the pAC codes for m-blocks of m = 2, 3, n of p-string T = AwBzABwz$. We notice that a “collision” occurs for two pAC codes using

p-Suﬃx Sorting as Arithmetic Coding

53

Algorithm 2. Generating pAC for an m-length preﬁx of p-suﬃx i 1 2 3 4 5 6 7 8 9 10

struct AC { long double l o , long double h i } AC pAC ( i n t i , i n t m) { i n t end=min{ i+m−1 ,n } , k char prevT i [ ] = prev (T [ i . . . end ] ) , AC new = ( 0 , 0 ) , o l d =(0 ,1) f o r k=i to end { new . h i=o l d . l o +( o l d . hi−o l d . l o ) ∗ c d f [ map ( prevTi [ k−i + 1 ] ) ] new . l o=o l d . l o +( o l d . hi−o l d . l o ) ∗ c d f [ map ( prevTi [ k−i +1]) −1] o l d=new } return new }

Table 2. Lexicographical ordering of p-suﬃxes with pAC, using T = AwBzABwz$ i pSA T [pSA[i]...n] prev(T [pSA[i]...n]) 1 2 3 4 5 6 7 8 9

9 8 7 4 2 1 5 6 3

$ $ z$ 0$ wz$ 00$ zABwz$ 0AB04$ wBzABwz$ 0B0AB54$ AwBzABwz$ A0B0AB54$ ABwz$ AB00$ Bwz$ B00$ BzABwz$ B0AB04$

tag(pAC(pSA[i], m)) m=2 m=3 m=n 0.055556 0.055556 0.055556 0.117284 0.117284 0.117284 0.129630 0.124143 0.124143 0.203704 0.209191 0.208743 0.216049 0.211934 0.212459 0.796296 0.801783 0.801384 0.882716 0.878601 0.878076 0.907407 0.903292 0.902683 0.907407 0.911523 0.912083

m = 2 since the m-blocks are equivalent. Even though the pAC codes distinctly sort the n p-suﬃxes of T when m approaches n, we highlight that the practical limitation is arithmetic precision. See [18,20] for handling this problem. In order to use the m-block codes, we must generate them eﬃciently. We denote the m-block arithmetic code at p-suﬃx i by pACi . The idea is to ﬁrst use function pAC to compute pAC1 and use this code to generate the remaining (n − 1) codes, namely pAC2 , pAC3 , ..., and pACn . Iteratively, we will need to adjust the arithmetic codes to 1) remove the old symbol and 2) add the new symbol. These cases are described below. The lemmas are similar in nature to Lemmas 2 and 3 and thus, are omitted for space. Case 1: Removing a symbol s from an arithmetic code m-block requires us to simply delete s when s ∈ Σ or s ∈ Π and does not occur in the m-block. When s ∈ Π and occurs later in the m-block, the code must accommodate for both the removed occurrence and the future occurrence of s. − Deﬁnition 11. Remove Symbol δpAC Transition: Given the AC code A at − m-block i with i + m − 1 ≤ n, δpAC supplies the transition to remove the symbol at

54

R. Beal and D. Adjeroh

position i and provide the new code A of the (m-1)-block at p-suﬃx (i + 1). Let β = f orwT [i], j = i + β, e = min{i + m − 1, n}, λ = (map(β) − map(0)) × pβ+1 , and c = cdf [map(prev(T [i])) −1]. ⎧

A.lo−c A.hi−c ⎪ , ,if (in(prevT [i], Z) ∧ j > e)∨ ⎪ ⎨ p p − in(prevT [i], Σ ∪ {$}) δpAC (i, A) =

⎪ ⎪ ⎩ A.lo−λ−c , A.hi−λ−c ,if in(prevT [i], Z) ∧ j ≤ e p

p

Case 2: Adding (i.e. appending) symbol s to an arithmetic code m-block requires us to simply append the code when s ∈ Σ or s ∈ Π and does not occur in the m-block. When s ∈ Π and occurs previously in the m-block, the code must account for the new occurrence in terms of the previous occurrence of s. + Deﬁnition 12. Add Symbol δpAC Transition: Given the AC code A at (m+ 1)-block (i −m+ 1) ≥ 1, δpAC supplies the transition to add the symbol at position i and provide the new code A of the m-block at p-suﬃx (i − m + 1). Let b = max{1, i−m+1}, k = i−prevT [i], Δ = A.hi−A.lo, d = Δ×cdf [map(prev(T [i]))], f = Δ × cdf [map(prev(T [i])) − 1], v = Δ × cdf [map(prevT [i])], and w = Δ × cdf [map(prevT ⎧ [i]) − 1]) ⎨ (A.lo + f, A.lo + d),if (in(prevT [i], Z) ∧ k < b)∨ + in(prevT [i], Σ ∪ {$}) δpAC (i, A) = ⎩ (A.lo + w, A.lo + v),if in(prevT [i], Z) ∧ k ≥ b

With the assistance of Deﬁnitions 11 and 12, we can eﬃciently generate the m-block codes for all n p-suﬃxes of T . Consider the p-string T = zwzABA$, Σ = {A, B}, Π = {w, z}, and m = 4, we successively generate the m-block codes − δpAC

+ δpAC

in the following fashion: 0 0 2 A → 00A → 00A B → · · · . Theorem 3. Given a p-string T of length n and precalculated variables prevT and f orwT , the pAC codes for all the m-length preﬁxes of the p-suﬃxes require O(n) time to generate. Proof. Generating the ﬁrst m-block code pAC1 via pAC1 = pAC(1, m) will require O(m) time. Iteratively, the neighboring pAC codes will be used to create the successive p-suﬃx codes. The ﬁrst extension of code pAC1 to create − pAC2 will require the removal of prevT [1] via a call to pAC2 = δpAC (1, pAC1 ), which is O(1) work, and the addition of symbol prevT [2 + m − 1] via a call to + pAC2 = δpAC (2 + m − 1, pAC2 ), which also demands O(1) work. This process requiring two O(1) steps is needed for the remaining (n − 1) m-block p-suﬃxes of T . The resulting time is O(m + n). Since m ≤ n, the theorem holds. The eﬃcient preprocessing from Theorem 3 leads to our main result: an average case linear time algorithm for direct p-suﬃx sorting for non-binary parameter alphabets. We discuss the intricacies of worst case p-suﬃx array construction in the conclusions as an area for future work.

p-Suﬃx Sorting as Arithmetic Coding

55

Theorem 4. Given a p-string T of length n, p-suﬃx-sorting of T can be accomplished in O(n) time on average via parameterized arithmetic coding. Proof. We can construct prev(T ) in O(n) time given an indexed alphabet and an O(|Π|) auxiliary data structure. The lexicographical ordering of the m-block pAC codes follow from the notion of arithmetic coding and Deﬁnition 7. From Theorem 3, we can create all the m-block pAC codes in O(n) time. Similar to [20], the individual ﬂoating-point codes may be converted to integer

codes tag(pACi )−tag(pACmin ) di in the range [0, c(n − 1)] by di = c(n − 1) tag(pACmax )−tag(pACmin ) , where the constant c > 1 is chosen to best separate the di and values pACmin and pACmax correspond to the minimum and maximum pAC codes, respectively. From [21,22], we know that an n-length general string has a max longest common preﬁx of O(log|Σ| n). Let x ◦ y be the string concatenation of x and y. Then, Q = prev(T [1...n−1])$◦prev(T [2...n−1])$◦...◦prev(T [n−2...n−1])$◦$ contains each individual p-suﬃx of T . Notice that Q is of length |Q| = n(n+1) ∈ O(n2 ) 2 and since all p-suﬃxes are clearly represented, the symbols of Q may be mapped to a traditional string alphabet, allowing us to use the contribution of [21,22] to obtain the length of the maximum longest common preﬁx for an average string, which is of the same order O(log n2 ) ∈ O(log n). Then by choosing m = O(log n) and generating the m-block pAC codes, only the ﬁrst O(n) radix sort of the di codes is required to diﬀerentiate the p-suﬃxes of an average case string, demanding only O(n) operations.

6

Conclusion and Discussion

Approaching the direct p-suﬃx sorting problem by representing p-suﬃxes with ﬁngerprints and arithmetic codes provides new mechanisms to handle the challenges of the p-string. We proposed a theoretical algorithm using ﬁngerprints to p-suﬃx sort an n-length p-string in O(n) time, with n and the alphabet size constrained in practice. Arithmetic codes were then used to propose an algorithm to p-suﬃx sort p-strings in linear time on average. In terms of direct suﬃx sorting, the time/space tradeoﬀ varies with algorithms. For instance, the algorithm in [23] accomplishes in-place suﬃx sorting in super-linear time, using only space for the suﬃx array and text. On a practical note, our algorithms use space and computation to achieve linear time direct construction of the p-suﬃx array, improving on the time required by the approaches introduced in [7]. With respect to space, our algorithms use an array for the prev encoding, which replaces the text, in addition to an array for pairs of elements representing the numeric codes and suﬃx indices. A future reseach problem is to address the worst case performance by identifying the intricate relationship between the dynamic nature of p-suﬃx partitions with induced sorting, the fundamental mechanism in worst case linear time suﬃx sorting of traditional strings [9,20,24,25].

56

R. Beal and D. Adjeroh

References 1. Baker, B.: A theory of parameterized pattern matching: Algorithms and applications. In: STOC 1993, pp. 71–80. ACM, New York (1993) 2. Shibuya, T.: Generalization of a suﬃx tree for RNA structural pattern matching. Algorithmica 39(1), 1–19 (2004) 3. Zeidman, B.: Software v. software. IEEE Spectr. 47, 32–53 (2010) 4. Idury, R., Sch¨ aﬀer, A.: Multiple matching of parameterized patterns. Theor. Comput. Sci. 154, 203–224 (1996) 5. Amir, A., Farach, M., Muthukrishnan, S.: Alphabet dependence in parameterized matching. Inf. Process. Lett. 49, 111–115 (1994) 6. Baker, B.: Parameterized pattern matching by Boyer-Moore-type algorithms. In: SODA 1995, pp. 541–550. ACM, Philadelphia (1995) 7. Tomohiro, I., Deguchi, S., Bannai, H., Inenaga, S., Takeda, M.: Lightweight Parameterized Suﬃx Array Construction. In: Fiala, J., Kratochv´ıl, J., Miller, M. (eds.) IWOCA 2009. LNCS, vol. 5874, pp. 312–323. Springer, Heidelberg (2009) 8. Deguchi, S., Higashijima, F., Bannai, H., Inenaga, S., Takeda, M.: Parameterized suﬃx arrays for binary strings. In: PSC 2008, Czech Republic, pp. 84–94 (2008) 9. Adjeroh, D., Bell, T., Mukherjee, A.: The Burrows-Wheeler Transform: Data Compression, Suﬃx Arrays and Pattern Matching. Springer, New York (2008) 10. Gusﬁeld, D.: Algorithms on Strings, Trees and Sequences: Computer Science and Computational Biology. Cambridge University Press, Cambridge (1997) 11. Smyth, W.: Computing Patterns in Strings. Pearson, New York (2003) 12. Kosaraju, S.: Faster algorithms for the construction of parameterized suﬃx trees. In: FOCS 1995, pp. 631–637. ACM, Washington, DC (1995) 13. Cole, R., Hariharan, R.: Faster suﬃx tree construction with missing suﬃx links. In: STOC 2000, pp. 407–415. ACM, New York (2000) 14. Lee, T., Na, J.C., Park, K.: On-Line Construction of Parameterized Suﬃx Trees. In: Karlgren, J., Tarhio, J., Hyyr¨ o, H. (eds.) SPIRE 2009. LNCS, vol. 5721, pp. 31–38. Springer, Heidelberg (2009) 15. Manber, U., Myers, G.: Suﬃx arrays: A new method for on-line string searches. SIAM J. Comput. 22, 935–948 (1993) 16. Beal, R.: Parameterized Strings: Algorithms and Data Structures. MS Thesis. West Virginia University (2011) 17. Karp, R., Rabin, M.: Eﬃcient randomized pattern-matching algorithms. IBM J. Res. Dev. 31, 249–260 (1987) 18. Moﬀat, A., Neal, R., Witten, I.: Arithmetic coding revisited. ACM Trans. Inf. Syst. 16, 256–294 (1995) 19. Cover, T., Thomas, J.: Elements of Information Theory. Wiley (1991) 20. Adjeroh, D., Nan, F.: Suﬃx sorting via Shannon-Fano-Elias codes. Algorithms 3(2), 145–167 (2010) 21. Karlin, S., Ghandour, G., et al.: New approaches for computer analysis of nucleic acid sequences. PNAS 80(18), 5660–5664 (1983) 22. Devroye, L., Szpankowski, W., Rais, B.: A note on the height of suﬃx trees. SIAM J. Comput. 21, 48–53 (1992) 23. Franceschini, G., Muthukrishnan, S.: In-Place Suﬃx Sorting. In: Arge, L., Cachin, C., Jurdzi´ nski, T., Tarlecki, A. (eds.) ICALP 2007. LNCS, vol. 4596, pp. 533–545. Springer, Heidelberg (2007) 24. K¨ arkk¨ ainen, J., Sanders, P., Burkhardt, S.: Linear work suﬃx array construction. J. ACM. 53, 918–936 (2006) 25. Manzini, G., Ferragina, P.: Engineering a lightweight suﬃx array construction algorithm. Algorithmca 40, 33–50 (2004)

Periods in Partial Words: An Algorithm Francine Blanchet-Sadri1 , Travis Mandel2 , and Gautam Sisodia3 1

2

Department of Computer Science, University of North Carolina, P.O. Box 26170, Greensboro, NC 27402–6170, USA [email protected] Department of Mathematics, The University of Texas at Austin, 1 University Station, C1200, Austin, TX 78712, USA 3 Department of Mathematics, University of Washington, P.O. Box 354350, Seattle, WA 98195-4350, USA

Abstract. Partial words are ﬁnite sequences over a ﬁnite alphabet that may contain some holes. A variant of the celebrated Fine-Wilf theorem shows the existence of a bound L = L(h, p, q) such that if a partial word of length at least L with h holes has periods p and q, then it has period gcd(p, q). In this paper, we associate a graph with each p- and q-periodic word, and study two types of vertex connectivity on such a graph: modiﬁed degree connectivity and r-set connectivity where r = q mod p. As a result, we give an algorithm for computing L(h, p, q) in the general case.

1

Introduction

The problem of computing periods in words, or ﬁnite sequences of symbols from a ﬁnite alphabet, has important applications in several areas including data compression, coding, computational biology, string searching and pattern matching algorithms. Repeated patterns and related phenomena in words have played over the years a central role in the development of combinatorics on words [1], and have been highly valuable tools for the design and analysis of algorithms. In many practical applications, such as DNA sequence analysis, repetitions admit a certain variation between copies of the repeated pattern because of errors due to mutation, experiments, etc. Approximate repeated patterns, or repetitions where errors are allowed, are playing a central role in diﬀerent variants of string searching and pattern matching problems [2]. Partial words, or ﬁnite sequences that may contain some holes, have acquired importance in this context. A (strong) period of a partial word u over an alphabet A is a positive integer p such that u(i) = u(j) whenever u(i), u(j) ∈ A and i ≡ j mod p (in such a case, we call u p-periodic). In other words, p is a period of u if for all positions i and j congruent modulo p, the letters in these positions are the same or at least one of these positions is a hole.

This material is based upon work supported by the National Science Foundation under Grant No. DMS–0452020.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 57–70, 2011. c Springer-Verlag Berlin Heidelberg 2011

58

F. Blanchet-Sadri, T. Mandel, and G. Sisodia

There are many fundamental results on periods of words. Among them is the well-known periodicity result of Fine and Wilf [3], which determines how long a p- and q-periodic word needs to be in order to also be gcd(p, q)-periodic. More precisely, any word having two periods p, q and length at least p + q − gcd(p, q) has also gcd(p, q) as a period. Moreover, the length p + q − gcd(p, q) is optimal since counterexamples can be provided for shorter lengths, that is, there exists an optimal word of length p + q − gcd(p, q) − 1 having p and q as periods but not having gcd(p, q) as period [1]. Extensions of Fine and Wilf’s result to more than two periods have been given. For instance, in [4], Constantinescu and Ilie give an extension for an arbitrary number of periods and prove that their lengths are optimal. Fine and Wilf’s result has been generalized to partial words [5,6,7,8,9,10,11]. Some of these papers are concerned with weak periodicity, a notion not discussed in this paper. The papers that are concerned with strong periodicity refer to the basic fact, proved by Shur and Konovalova (Gamzova) in [10], that for positive integers h, p and q, there exists a positive integer l such that a partial word u with h holes, two periods p and q, and length at least l has period gcd(p, q). The smallest such integer is called the optimal length and it will be denoted by L(h, p, q). They gave a closed formula for the case where h = 2 (the cases h = 0 or h = 1 are implied by the results in [3,5]), while in [9], they gave a formula in the case where p = 2 as well as an optimal asymptotic bound for L(h, p, q) in the case where h is “large.” In [7], Blanchet-Sadri et al. gave closed formulas for the optimal lengths when q is “large,” whose proofs are based on connectivity in the so-called (p, q)-periodic graphs. In this paper, we study two types of vertex connectivity in these graphs: the modiﬁed degree connectivity and r-set connectivity where r = q mod p. Although the graph-theoretical approach is not completely new, the paper gives insights into periodicity in partial words and provides an algorithm for determining L(h, p, q) in all cases. We end this section by reviewing basic concepts on partial words. Fixing a nonempty ﬁnite set of letters or an alphabet A, ﬁnite sequences of letters from A are called (full) words over A. The number of letters in a word u, or length of u, is denoted by |u|. The unique word of length 0, denoted by ε, is called the empty word. The set of all words over A of ﬁnite length is denoted by A∗ . A partial word u of length n over A is a partial function u : {0, . . . , n − 1} → A. For 0 ≤ i < n, if u(i) is deﬁned, then i belongs to the domain of u, denoted by i ∈ D(u), otherwise i belongs to the set of holes of u, denoted by i ∈ H(u). For convenience, we will refer to a partial word over A as a word over the enlarged alphabet A = A ∪ {}, where ∈ A represents a “do not know” symbol or hole.

2

(p, q)-Periodic Graphs

In this section, we discuss the fundamental property of periodicity, the goal of our paper which is to describe an algorithm to compute L(h, p, q) in all cases, and some initial results. We can restrict our attention to the case where p and q are coprime, since it is well-known that the general case can be reduced to the coprime case (see, for example, [5,9]). Also, we assume without loss of generality

Periods in Partial Words: An Algorithm

59

that 1 < p < q. Fine and Wilf show that L(0, p, q) = p + q − gcd(p, q) [3], Berstel and Boasson that L(1, p, q) = p + q [5], and Shur and Konovalova prove L(2, p, q) to be 2p + q − gcd(p, q) [10]. Other results include the following. Theorem 1 ([7,9]). For 0 ≤ m < q, L(nq + m, 2, q) = (2n + 1)q + m + 1. Theorem 2 ([7]). If q > x(p, h) where x(p, h) is p( h2 ) if h is even and p( h+1 ) 2 if h is odd, then p( h+2 if h is even; 2 ) + q − gcd(p, q), L(h, p, q) = h+1 p( 2 ) + q, if h is odd. The problem of ﬁnding L(h, p, q) is equivalent to a problem involving the vertex connectivity of certain graphs, as described in [7], which we now discuss. We can represent the periodic structure of a full word with two periods through a graph associated with the word. The (p, q)-periodic graph of size l is the graph G = (V, E) where V = {0, 1, . . . , l − 1} and for i, j ∈ V , the pair {i, j} ∈ E if and only if i ≡ j mod p or i ≡ j mod q. The degree of a vertex i ∈ V , denoted d(i), is the number of vertices connected to i, that is, l − 1 − i mod p l − 1 − i mod q l − 1 − i mod pq d(i) = + − . p q pq The ﬁrst term gives the number of p-connections, the second term the number of q-connections, and the third term the number of pq-connections.

Fig. 1. The (3, 4)-periodic graph of size 11. The bold connections are q-edges, while the lighter ones are p-edges.

The (p, q)-periodic graph of size l can be thought to represent a full word of length l with periods p and q, with the vertices corresponding to positions of the

60

F. Blanchet-Sadri, T. Mandel, and G. Sisodia

word, and the edges corresponding to the equalities between letters of the word forced by one of the periods. For example, we see that if the (p, q)-periodic graph of size l is connected, then a word of length l with periods p and q is 1-periodic, because there exists a path between every pair of vertices, thus the word is over a singleton alphabet. A graph has vertex connectivity κ if it can be disconnected with a suitable choice of κ vertex removals, but cannot be disconnected by any choice of κ − 1 vertex removals. Note that a hole in a partial word u of length l with periods p and q corresponds to the removal of the associated vertex from the (p, q)-periodic graph of size l. Thus our search for L(h, p, q) (when gcd(p, q) = 1) can be restated in terms of vertex connectivity. Lemma 1. The length L(h, p, q) is the smallest l such that the (p, q)-periodic graph of size l has vertex connectivity at least h + 1. If G = (V, E) is the (p, q)-periodic graph of size l, then the p-class of vertex i is {j ∈ V | j ≡ i mod p}. A p-connection (or p-edge) is an edge {i, j} ∈ E such that i ≡ j mod p. If an edge {i, j} is a p-connection, then i and j are considered p-connected. Similar statements hold for q-classes, q-connections and pq-classes, pq-connections. Throughout the paper, we will ﬁnd it useful to group together p-classes whose smallest elements are congruent modulo r where r = q mod p. We do so by introducing the r-set of vertex i, where i ∈ {0, 1, . . . , r − 1}, which is the set 0≤j

pq, vertices within the same p-class may belong to the same q-class (that is to say, vertices may be both p- and q-connected, or pq-connected). For a vertex i in V , vertices that are pq-connected to i share all other connections with i, and thus should not be counted in the number of vertices required to disconnect i as they are disconnected when i is disconnected. Thus, we introduce the idea of “modiﬁed” degree. Let G = (V, E) be the (p, q)-periodic graph of size l, and let i ∈ V . The modified degree of i, denoted d∗ (i), is the number of vertices that are either por q-connected to i, but not pq-connected to i, that is, l − 1 − i mod p l − 1 − i mod q l − 1 − i mod pq d∗ (i) = + −2 . (1) p q pq We subtract 2 times the number of pq-connections: once because we double counted them, and again because vertices that are pq-connected are connected to the same vertices, so disconnecting one vertex will also disconnect all the vertices pq-connected to it. Note that when l ≤ pq, d(i) = d∗ (i). When l > pq, minimum

62

F. Blanchet-Sadri, T. Mandel, and G. Sisodia

degree disconnections are replaced by minimum modiﬁed degree disconnections. For a (p, q)-periodic graph G, we deﬁne the modified degree connectivity of G, denoted κd , to be the smallest number of vertex removals required to make a minimum modiﬁed degree disconnection, and denote the minimum size of G such that κd = h + 1 by ld (h, p, q). Usually, disconnecting more than one p-class takes more holes than individually disconnecting any one p-class, because in general, a set of p-classes has more connections with the rest of the graph than any single p-class. However, disconnecting entire r-sets may prove to be eﬃcient when l is small, as the graph “bottlenecks” between r-sets (that is, fewer q-classes span r-sets than connect p-classes within an r-set). For a (p, q)-periodic graph G, we deﬁne the r-set connectivity of G, denoted κr , to be the smallest number of vertex removals required to make an r-set disconnection, and denote the minimum size of G such that κr = h + 1 by lr (h, p, q). Thus, if G is the (p, q)-periodic graph of size l for l > 2q, then either a modiﬁed degree disconnection or an r-set disconnection will give an optimal disconnection of G. Note that the sizes at which our graphs change connectivity are the optimal lengths in question. If the (p, q)-periodic graph of size l has vertex connectivity κ while the (p, q)-periodic graph of size l + 1 has vertex connectivity κ + 1, then L(κ, p, q) = l + 1. Similarly, if the (p, q)-periodic graph of size l has modiﬁed degree connectivity κd (respectively, r-set connectivity κr ) while the (p, q)-periodic graph of size l + 1 has modiﬁed degree connectivity κd + 1 (respectively, r-set connectivity κr + 1), then ld (κd , p, q) = l + 1 (respectively, lr (κr , p, q) = l + 1).

4

r-Set Connectivity

Consider the (p, q)-periodic graph of size l where q = mp + r with 0 < r < p. Set l = kp + r where 0 ≤ r < p. Figure 3 depicts a case in which r = 0. We can see here that there are k rows in each r-set. In the columns on either side of any r-set we see that m + 1 vertices do not have q-connections to the adjacent r-set, so exactly β = k − (m + 1) vertices are q-connected to the adjacent rset. Consider two adjacent r-sets. Looking at the q-classes that connect these r-sets, we can see that the bottom m of these q-classes have 1 vertex in the left r-set. The next m q-classes have 2 vertices in the left r-set, and so on for the ﬁrst k − (m + 1) q-classes. The left side of the right r-set is anti-symmetric to this: the top m q-classes each have 1 vertex in the right r-set, and the next m q-classes each have 2 vertices and so on working down. When breaking these q-connections it is best to remove all the vertices from the smaller side of the q-class. Thus, for the bottom half of the q-classes we remove vertices from the left side, and for the top half we remove the same number of vertices from the right side. If β = γ(2m) + φ for 0 ≤ φ < 2m, then we see that the number of vertices we must remove to separate these adjacent r-sets is 2m

γ i=1

i + φ(γ + 1) = 2m

γ(γ + 1) + φ(γ + 1). 2

Periods in Partial Words: An Algorithm

63

Fig. 3. An r-set disconnection for p = 16, q = 35 = 2p + 3, and l = 9p (this length is not optimal). Here we are disconnecting the r-set of vertex 2 from the other r-sets.

Since an r-set disconnection requires separating adjacent r-sets twice, we have κr = mγ(γ + 1) + φ(γ + 1) = (mγ + φ)(γ + 1). 2 Since γ is an integer and φ < 2m, we can ﬁnd γ in terms of κr and m by solving for when φ is equal to zero and then taking the ﬂoor. Using the quadratic formula, √ 2 m + 2mκr − m γ= . 2m κr We solve for φ and ﬁnd φ = 2(γ+1) − mγ. From the deﬁnition of β we have k = 2mγ + φ + m + 1. The length is never optimal when r = 0 because κr only increases for nonzero values of r , as described below. We therefore want to select γ and φ such that they give us a value of κr that is strictly less than h + 1. We will make room for the remaining vertex removals by adding r vertices. Now we need to calculate r by determining at exactly which sizes the rset connectivity actually increases. Starting with size l = kp, if we increase the size by r then the number of vertex removals required to break any r-set connection increases by 1 because between each connected pair of r-sets there is one more q-connection. Thus, the r-set connectivity increases by 2. Notice that every connected pair of r-sets requires the same number of vertex removals to separate them. Thus, if we remove the last vertex we added, then the r-set connectivity will have only increased by 1 from the previous size. After decreasing the size by one more vertex the r-set connectivity will be back down to where

64

F. Blanchet-Sadri, T. Mandel, and G. Sisodia

it was for l = kp. The same thing happens if we add another r vertices and continue until we reach the r-set connectivity of the graph of size l = (k + 1)p. If we have calculated k for a given p, q and h, then deﬁne δ to be the diﬀerence between the r-set connectivity that we are looking for and the r-set connectivity at length l = kp. Then δ = h + 1 − 2(mγ + φ)(γ + 1), and we can calculate r = δ+1 r − δ mod 2. We arrive at the following theorem. 2 Theorem 3. Let q = mp + r where 0 p h+1 , so r-set disconnections are not optimal (see Theorem 2). 2 h=3 h=4 h=5 h=6 p < q < 2p 2p + q 3p + q − 1 3p + q 2p + 2q − 1 2p < q < 3p 3p + q 4p + q − 1 3p < q < 4p

h=7 2p + 2q 4p + q 4p + q

lengths in Table 1 to the lengths that can be calculated using modiﬁed degree, r-set disconnections are only more eﬃcient when h = 4 and q < 3p . As we 2 increase the length beyond the values shown in the table, experimental evidence suggests that r-set disconnections will continue to become less eﬃcient because r-sets now gain q-connections faster than any pq-class gains connections.

5

Modified Degree Connectivity

To count the number of vertices we must remove to disconnect vertex i and all the vertices pq-connected to it, we use the formula in (1) for d∗ (i). Suppose l = τ pq + ω for nonnegative integers τ and ω < pq. If ω = 0 then every vertex has the same modiﬁed degree: d∗ (i) = (τ q−1)+(τ p−1)−2(τ −1) = τ (p + q − 2). If ω > 0 then deﬁne G to be the subgraph of the (p, q)-periodic graph G of size l that contains only the vertices in the last ω positions. Each of the last ω vertices has τ (p + q − 2) vertices in the ﬁrst τ pq positions to which it is either p-connected or q-connected but not pq-connected. Thus, the modiﬁed degree of a vertex i in G is equal to τ (p + q − 2) + dG (i), where dG (i) is the degree of i in G . In other words, we can ﬁnd the degree of the vertex i within the subgraph G , and add this degree to τ (p + q − 2) to get its modiﬁed degree in G. Thus, we have d∗ (i) = τ (p + q − 2) + d∗G (i). (2)

Periods in Partial Words: An Algorithm

65

The positions of these last ω vertices modulo pq are all less than ω = l mod pq, and any two positions in the same pq-class have the same modiﬁed degree. Thus we know that one of them will have the lowest modiﬁed degree of the graph.

Fig. 4. The (4, 5)-periodic graph of size 47. This ﬁgure depicts an optimal disconnection where the dashed vertices are in H, the bold vertices are in V2 , and the rest of the vertices are in V1 . Notice that the vertices in V2 have the minimal modiﬁed degree. They are all pq-connected to each other, and are p- or q-connected to the vertices in H. Increasing the size by 1 gives this pq-class one more p-connection, thereby increasing the connectivity of the graph by 1.

We want d∗ (i) = h + 1. Since τ is an integer and d∗G (i) < p+

q − 2, we can h+1 use the division algorithm and Equation (2) to get τ = p+q−2 and d∗G (i) = (h + 1) mod (p + q − 2). Recall that ld (h, p, q) is the smallest length at which the minimum modiﬁed degree is h+1. In other words, ld (h, p, q) is the optimal length L(h, p, q) if we restrict ourselves to minimum modiﬁed degree disconnections. Note that we consider the degree of the empty graph to be zero. We now arrive at the following theorem. Theorem 4. The equality

ld (h, p, q) = τ pq + ω holds, where 0 ≤ ω < pq. More h+1 specifically, τ = p+q−2 and ld ((h + 1) mod (p + q − 2) − 1, p, q), if (h + 1) mod (p + q − 2) = 0; ω= 0, otherwise.

66

F. Blanchet-Sadri, T. Mandel, and G. Sisodia

We have now reduced cases where ld (h, p, q) ≥ pq to those where ld (h, p, q)

ω mod p and i > ω mod q, so f (n1 p, p, q) = 2 for n1 p > q and f (n1 p, p, q) = 1 for n1 p < q. Similarly, f (n2 q, p, q) = 2 for any positive n 2 .

To calculate n1 when f (ω, p, q) = 2 we use the formula κd = h + 1 = np1 p +

n1 p n1 p p − 2. We can solve as follows: n + = (h + 1) + 2 or n 1 + = 1 1 q q q h + 3. So if a solution exists, it is h+3 n1 = . (3) 1 + pq

If there is no solution for n1 satisfying n1 + nq1 p − 2 = h + 1, then there must

be a solution for n2 satisfying κd = h + 1 = n2 + np2 q − 2 and we calculate h+3 n2 = . (4) 1 + qp

Periods in Partial Words: An Algorithm

67

We now consider the f (ω, p, q) = 1 case. Note that f (l, p, q) = 1 for all l < q. For these cases vertices can only have p-connections, and we can see that ld (h, p, q) =

(h + 2)p so long as h + 2 ≤ pq . For larger numbers of holes we must better characterize when vertices of lowest degree gain p- and q-connections. First, there is always a vertex of minimal degree in either the p−1 p-class or the q −1 q-class. This is because if we pick any other position that has minimal degree then we can increase this position without adding more p- or q-connections until it is in either the p − 1 p-class or the q − 1 q-class. Optimal lengths occur when these positions of minimal degree gain a new p- or q-connection.

Remark 2. If ld (h, p, q) = ω, f (ω, p, q) = 1, and h + 2 > pq , then ω = n1 p + n2 q

for some positive integers n1 and n2 . For ω = n1 p+n2 q − 1, the vertices of lowest degree are in the symmetric positions n1 p − 1 and n2 q − 1. We now focus on ﬁnding these positions n1 p − 1 and n2 q − 1. If f (ω, p, q) changes from 2 to 1 when the n1 p − 1 vertex gains a q-connection, then we see from the deﬁnition of f (ω, p, q) that the n1 p − 1 vertex must have a larger value modulo q than the other vertices in the p − 1 p-class. Thus we can say that (n1 p − 1) mod q > (n1 p − 1) mod q for all positive integers n1 = n1 where n1 p < n1 p + n2 q. Similarly we must have (n2 q − 1) mod p > (n2 q − 1) mod p for all positive integers n2 = n2 where n2 q < n1 p + n2 q. Also, n1 p + n2 q must fall between the f (ω, p, q) = 2 solutions for ld (h − 1, p, q) and ld (h, p, q).

Algorithm 1. Find ld (h, p, q) when 1 < p < q, gcd(p, q) = 1 and h < p + q − 2

if h + 2 ≤ pq then ld (h, p, q) = (h + 2)p else solve for f (ω, p, q) = 2 solutions for ld (h − 1, p, q) and ld (h, p, q) if the f (ω, p, q) = 2 value for ld (h, p, q) is n1 p then find the maximum value of n1 p mod q for 0 < n1 < n1 if the vertex in this position has a q-connection between f (ω, p, q) = 2 solutions for ld (h − 1, p, q) and ld (h, p, q) then ld (h, p, q) is the position of this q-connection else ld (h, p, q) = n1 p if the f (ω, p, q) = 2 value for ld (h, p, q) is n2 q then find the maximum value of n2 q mod p for 0 < n2 < n2 if the vertex in this position has a p-connection between f (ω, p, q) = 2 solutions for ld (h − 1, p, q) and ld (h, p, q) then ld (h, p, q) is the position of this p-connection else ld (h, p, q) = n2 q

68

F. Blanchet-Sadri, T. Mandel, and G. Sisodia

For m = pq , the mp − 1 vertex has the lowest degree in a large number of cases when the length is less than pq (keep in mind that we can reduce any case to one where the length is less than pq). The following lemma identiﬁes many of these cases. We then use this knowledge to ﬁnd a large number of optimal lengths in the theorem that follows. Lemma 2. Let G be the (p, q)-periodic graph of size l, let q = mp + r where 0 < r < p, and let l = nq + r1 where 0 ≤ r1 < q. Let mp ≤ l ≤ pq. If l mod q < mp or nr − 1 < l mod p, then the mp − 1 vertex has minimum degree. Proof. We require l ≥ mp so the mp − 1 vertex exists, and we require l ≤ pq so we do not have vertices that are both p- and q- connected to each other. We have that l = nq + r1 = n(mp + r) + r1 = mnp + nr + r1 , so l ≡ (nr + r1 ) mod p. A l vertex in the p-class of i has p p-connections if i < (nr + r1 ) mod p or pl − 1 p-connections if i ≥ (nr + r1 ) mod p. Similarly, the number of q-connections for a position in the q-class of j is n if j < r1 or n − 1 if j ≥ r1 . The mp − 1 vertex is in the p-class of p − 1 so it always has pl − 1 p-connections since p − 1 ≥ (nr + r1 ) mod p. The mp − 1 vertex is in the q-class of mp − 1 and so it has n − 1 q-connections if r1 ≤ mp − 1 and has n q-connections if mp ≤ r1 < q. The degree of the mp− 1 vertex is clearly minimum when r1 < mp, that is, when l mod q < mp. However, if mp ≤ r1 ≤ mp + s for some 0 ≤ s < r, then the vertices in the q-class of mp + s have one fewer q-connection than any other vertex, and may have the same number of p-connections as the mp − 1 vertex, giving them a lower degree than the mp − 1 vertex. These vertices are of the form (mp + s) + tq = mp + s + t(mp + r) = (t + 1)mp + tr + s for some nonnegative integer t satisfying mp + s + tq ≤ l − 1. Thus a vertex mp + s + tq falls in

the p-class of (tr + s) mod p. Thus, vertices in the q-class of mp + s have pl p-connections if and only if (tr + s) mod p < l mod p for all integers t ∈ {0, . . . , n − 1} and s ∈ {r1 − mp, . . . , r − 1}. If this is the case then these vertices have one more p-connection than the mp − 1 vertex and therefore do not have lower degree. Since t ≤ n − 1 and s ≤ r − 1, we have that tr + s ≤ nr − 1. Note that if nr−1 < l mod p, then (tr+s) mod p = (tr+s) < l mod p for all t ∈ {0, . . . , n−1} and s ∈ {r1 − mp, . . . , r − 1}. Thus, if nr − 1 < l mod p, then the mp − 1 vertex has lowest degree in G. The following theorem gives ld (h, p, q) when the mp − 1 vertex has the minimum degree in the graph of size ld (h, p, q) − 1. h+3 Theorem 6. Let q = mp + r where 0 < r < p. Define n1 = 1+ and n2 = p q h+3 , and define ω = min{n1 p, mp + (n2 − 1)q}. Let mp ≤ ω ≤ pq. If 1+ q p

ω mod q < mp or ωq r − 1 < ω mod p, then ld (h, p, q) = ω . Proof. Let G denote the (p, q)-periodic graph of size l. If we restrict the size so that mp ≤ l ≤ pq with l mod q < mp or nr − 1 < l mod p, then by Lemma 2

Periods in Partial Words: An Algorithm

69

the vertex mp − 1 of G has lowest degree. Thus, within these ranges, optimal lengths occur whenever the mp − 1 vertex gains a p- or q-connection. The mp − 1 vertex gains a p-connection exactly when l = n1 p for an integer n1 > m. We can calculate n1 using Equation (3). The mp − 1 position gains a q-connection exactly when l = mp + n2 q. This ﬁts the form described in Remark 2 where n1 = m. After using Equations (3) and 4 to calculate n1 and n2 , we search for n2 satisfying max{(n1 − 1)p, (n2 − 1)q} < mp + n2 q < n1 p. The optimal length is then mp + n2 q if and only if such an n2 exists. Since mp < q and n2 q is the smallest multiple of q greater than n1 p, any such n2 satisfying the inequalities must be equal to n2 −1, where we calculate n2 using Equation (4). We then know that mp + n2 q > max{(n1 − 1)p, (n2 − 1)q}, so we can now say that mp + n2 q is the optimal length if and only if it is less than n1 p. Otherwise, n1 p is the optimal length. Algorithm 2. Find L(h, p, q) when 1 < p < q and gcd(p, q) = 1

if p = 2 then L(h, p, q) = (2 hq + 1)q + h mod q + 1 by Thm 1 else if q > p h+1 then L(h, p, q) = p h+2 + q − (h + 1) mod 2 by Thm 2 2 2 else compute lr (h, p, q) using Theorem 3 compute ld (h, p, q) using Theorem 4 (and Algorithm 1) L(h, p, q) = max{lr (h, p, q), ld (h, p, q)}

Theorem 7. Given a number of holes h and two periods p and q, Algorithm 2 computes the optimal length L(h, p, q). Computing ld (h, p, q) is linear in p and q and constant in h.

6

Conclusion

Using the ideas of r-set and modiﬁed degree connectivities described in this paper, we have been able to answer conjectures in [7] (due to page restrictions however, we cannot provide these results here). Our methods can be used to prove closed formulas for any given number of holes. However, as the number of holes increases, the number of cases also increases. Our calculations show that an r-set disconnection is strictly more eﬃcient than any modiﬁed degree disconnection, or lr (h, p, q) > ld (h, p, q), if and only if h = 4 and q < 3p 2 , in which case, L(h, p, q) = q + 3p − 1. For instance, we have proved that if p and q are integers satisfying 2 < p < q and gcd(p, q) = 1, then L(3, p, q) is p + 2q if 3p q < 3p 2 , 4p if 2 < q < 2p, and 2p + q if q > 2p. A topic of future research is to extend our approach to any number of periods. Moreover, a World Wide Web server interface has been established at

70

F. Blanchet-Sadri, T. Mandel, and G. Sisodia

www.uncg.edu/cmp/research/finewilf4 for automated use of a program which given as input a number of holes h and two periods p and q, outputs L(h, p, q) and an optimal word for that length.

References 1. Choﬀrut, C., Karhum¨ aki, J.: Combinatorics of Words. In: Rozenberg, G., Salomaa, A. (eds.) Handbook of Formal Languages, vol. 1, pp. 329–438. Springer, Berlin (1997) 2. Smyth, W.F.: Computing Patterns in Strings. Pearson, Addison-Wesley (2003) 3. Fine, N.J., Wilf, H.S.: Uniqueness theorems for periodic functions. Proceedings of the American Mathematical Society 16, 109–114 (1965) 4. Constantinescu, S., Ilie, L.: Generalised Fine and Wilf’s theorem for arbitrary number of periods. Theoretical Computer Science 339, 49–60 (2005) 5. Berstel, J., Boasson, L.: Partial words and a theorem of Fine and Wilf. Theoretical Computer Science 218, 135–141 (1999) 6. Blanchet-Sadri, F.: Algorithmic Combinatorics on Partial Words. Chapman & Hall/CRC Press, Boca Raton, FL (2008) 7. Blanchet-Sadri, F., Bal, D., Sisodia, G.: Graph connectivity, partial words, and a theorem of Fine and Wilf. Information and Computation 206(5), 676–693 (2008) 8. Halava, V., Harju, T., K¨ arki, T.: Interaction properties of relational periods. Discrete Mathematics and Theoretetical Computer Science 10, 87–112 (2008) 9. Shur, A.M., Gamzova, Y.V.: Partial words and the interaction property of periods. Izvestiya Rossiiskoi Akademii Nauk. Seriya Matematicheskaya 68(2), 191–214 (2004) 10. Shur, A.M., Konovalova, Y.V.: On the Periods of Partial Words. In: Sgall, J., Pultr, A., Kolman, P. (eds.) MFCS 2001. LNCS, vol. 2136, pp. 657–665. Springer, Heidelberg (2001) 11. Smyth, W.F., Wang, S.: A new approach to the periodicity lemma on strings with holes. Theoretical Computer Science 410, 4295–4302 (2009)

The 1-Neighbour Knapsack Problem Glencora Borradaile1, , Brent Heeringa2, , and Gordon Wilfong3 1

Oregon State University glencora@eecs.oregonstate.edu 2 Williams College heeringa@cs.williams.edu 3 Bell Labs gtw@research.bell-labs.com

Abstract. We study a constrained version of the knapsack problem in which dependencies between items are given by the adjacencies of a graph. In the 1-neighbour knapsack problem, an item can be selected only if at least one of its neighbours is also selected. We give approximation algorithms and hardness results when the nodes have both uniform and arbitrary weight and proﬁt functions, and when the dependency graph is directed and undirected.

1

Introduction

We consider the knapsack problem in the presence of constraints. The input is a graph G = (V, E) where each vertex v has a weight w(v) and a profit p(v), and a knapsack of size k. We start with the usual knapsack goal—ﬁnd a set of vertices of maximum proﬁt whose total weight does not exceed k—and handle the additional requirement that a vertex can be selected only if at least one of its neighbours is also selected (vertices with no neighbours can always be selected). We call this the 1-neighbour knapsack problem. We consider the problem with general (arbitrary) and uniform (p(v) = w(v) = 1 ∀v) weights and proﬁts, and with undirected and directed graphs. In the case of directed graphs, the neighbour constraint applies to the out-neighbours of a vertex. Constrained knapsack problems have applications to scheduling, tool management, investment strategies and database storage [8,1,7]. There are also applications to network formation. For example, suppose a set of customers C ⊂ V in a network G = (V, E) wish to connect to a server, represented by a single sink s ∈ V . The server may activate each edge at a cost and each customer would result in a certain proﬁt. The server wishes to activate a subset of the edges with cost within the server’s budget. By introducing a vertex mid-edge with zero-proﬁt and weight equal to the cost of the edge and giving each customer zero-weight, we convert this problem to a 1-neighbour knapsack problem.

Glencora Borradaile is supported by NSF grant CCF-0963921. Brent Heeringa is supported by NSF grant IIS-08125414.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 71–84, 2011. c Springer-Verlag Berlin Heidelberg 2011

72

G. Borradaile, B. Heeringa, and G. Wilfong

Results. We show that the four resulting problems {general, uniform} × {undirected, directed} vary in complexity but admit several algorithmic approaches. We summarize our results in Table 1. Table 1. Our results: upper and lower bounds on the approximation ratios for combinations of {general, uniform} × {undirected, directed}. For uniform, undirected, the bounds are running-times of optimal algorithms. Upper Uniform

Undirected

linear-time exact

Directed General

Lower

Undirected Directed

PTAS (1−ε) 2

NP-hard (strong sense) 1−ε

· (1 − 1/e open

)

1 − 1/e + 1/Ω(log1−ε n)

In Section 2 we describe a greedy algorithm that applies to the general 1neighbour problem for both directed and undirected dependency graphs. The algorithm requires two oracles: one for ﬁnding a set of vertices with high proﬁt and another for ﬁnding a set of vertices with high proﬁt-to-weight ratio. In both cases, the total weight of the set cannot exceed the knapsack capacity and the subgraph deﬁned by the vertices must adhere to a strict combinatorial structure which we deﬁne later. The algorithm achieves an approximation ratio of (α/2) · (1 − 1/eβ ). The approximation ratios of the oracles determine the α and β terms respectively. For the general, undirected 1-neighbour case, we give polynomial-time oracles that achieve α = β = (1 − ε) for any ε > 0. This yields a polynomial time ((1 − ε)/2) · (1 − 1/e1−ε )-approximation. We also show that no approximation ratio better than 1 − 1/e is possible (assuming P=NP). This matches the upper bound up to (almost) a factor of 2. These results appear in Section 2.1. In Section 2.2, we show that the general, directed 1-neighbour knapsack problem is 1/Ω(log1−ε n)-hard to approximate, even in DAGs. In Section 3 we show that the uniform, directed 1-neighbour knapsack problem is NP-hard in the strong sense but that it has a polynomial-time approximation scheme (PTAS)1 . Thus, as with general, undirected 1-neighbour problem, our upper and lower bounds are essentially matching. Finally, in Section 4 we show that the uniform, undirected 1-neighbour knapsack problem aﬀords a simple, linear-time solution. Related Work. There is a tremendous amount of work on maximizing submodular functions under a single knapsack constraint [13], multiple knapsack 1

A PTAS is an algorithm that, given a ﬁxed constant ε < 1, runs in polynomial time and returns a solution within 1 − ε of optimal. The algorithm may be exponential in 1/ε.

The 1-Neighbour Knapsack Problem

73

constraints [11], and both knapsack and matroid constraints [12,4]. While our proﬁt function is submodular, the constraints given by the graph are not characterized by a matroid (our solutions, for example, are not closed downward). Thus, the 1-neighbour knapsack problem represents a class of knapsack problems with realistic constraints that are not captured by previous work. As we show in Section 2.1, the general, undirected 1-neighbour knapsack problem generalizes several maximum coverage problems including the budgeted variant considered by Khuller, Moss, and Naor [9] which has a tight (1 − 1/e)approximation unless P=NP. Our algorithm for the general 1-neighbour problem follows the approach taken by Khuller, Moss, and Naor but, because of the dependency graph, requires several new technical ideas. In particular, our analysis of the greedy step represents a non-trivial generalization of the standard greedy algorithm for submodular maximization. Johnson and Niemi [7] give an FPTAS for knapsack problems on dependency graphs that are in-arborescences (these are directed trees in which every arc is directed toward a single root)2 . This problem can be viewed as an instance of the general, directed 1-neighbour knapsack problem. In a longer technical report [2] we explore a version of the constrained knapsack problem where an item may be selected only if all its neighbours are selected. This problem generalizes the subset-union knapsack problem (SUKP) [8], the precedence constrained knapsack problem (PCKP) [1], and the partially ordered knapsack problem (POK) [10]. Notation. We consider graphs G with n vertices V (G) and m edges E(G). Whether the graph is directed or undirected will be clear from context. We refer to edges of directed graphs as arcs. For an undirected graph, NG (v) denotes the neighbours of a vertex v in G. For a directed graph, NG (v) denotes the outneighbours of v in G, or, more formally, NG (v) = {u : vu ∈ E(G)}. Given a set − of nodes X, NG (X) is the set of nodes not in X but that have a neighbour (or − out-neighbour in the directed case) in X. That is, NG (X) = {u : uv ∈ E(G), u ∈ X, and v ∈ X}. The degree (in undirected graphs) and out-degree (in directed graphs) of a vertex v in G is denoted δG (v). The subscript G will be dropped when the graph is clear from context. For a set of vertices or edges U , G[U ] is the graph induced on U . For a directed graph G, D is the directed, acyclic graph (DAG) resulting from contracting maximal strongly-connected components (SCCs) of G. For each node u ∈ V (D), let V (u) be the set of vertices of G that are contracted to obtain u. For convenience, extend any function f deﬁned on items in a set X to any subset A ⊆ X by letting f (A) = a∈A f (a). If f (a) is a set, then f (A) = f (a). If f is deﬁned over vertices, then we extend it to edges: f (E) = a∈A f (V (E)). For any knapsack problem, OPT is the set of vertices/items in an optimal solution. 2

In their problem formulation, the constraints are given as an out-arborescences— directed trees in which every arc is directed away from a single root—and feasible solutions are subsets of vertices that are closed under the predecessor operation.

74

G. Borradaile, B. Heeringa, and G. Wilfong

(a)

(b)

Fig. 1. (a) An undirected graph. If H is the family of star graphs, then the shaded regions give the only viable partition of the nodes—no other partition yields 1-neighbour sets. However, every edge viable with respect to H. The singleton node is also viable since it is a 1-neighbour set for the graph. (b) A graph G with 1-neighbour sets A (dark shaded) and B (dotted). For convenience, we include both directed and undirected edges. The lightly shaded regions give a viable partition for G[A \ B] and the − white nodes denote NG (B). For the undirected case, Y2 is viable for G[A \ B], and since |Y2 | = 2, it is viable for G[V (G) \ B]. Y1 is not viable for G[V (G) \ B] but it is in − NG (B). For the directed case, Y3 is viable in G[V (G) \ B] whereas Y4 is a viable set only since we consider G[V (G) \ B] with the dotted arc removed.

Viable Families and Viable Sets. A set of nodes U is a 1-neighbour set for G if for every vertex v ∈ U , |NG[U] (v)| ≥ min{δG (v), 1}. That is, a 1-neighbour set is feasible with respect to the dependency graph. A family of graphs H is a viable family for G if, for any subgraph G of G, there exists a partition YH (G ) of G into 1-neighbour sets for G , such that for every Y ∈ YH (G ), there is a graph H ∈ H spanning G[Y ]. For directed graphs, we take spanning to mean that H is a directed subgraph of G[Y ] and that Y and H contain the same number of nodes. For a graph G, we call YH (G) a viable partition of G with respect to H. In Section 2.1 we show that star graphs form a viable family for any undirected dependency graph. That is, we show that any undirected graph can be partitioned into 1-neighbour sets that are stars. Fig. 1 (a) gives an example. In contrast, edges do not form a viable family since, for example, a simple path with 3 nodes cannot be partitioned into 1-neighbour sets that are edges. For DAGs, in-arborescences are a viable family but directed paths are not (consider a directed graph with 3 nodes u, v, w and two arcs (u, v) and (w, v)). Note that a viable family always contains a singleton vertex. A 1-neighbour set U for G is viable with respect to H if there is a graph H ∈ H spanning G[U ]. Note that the 1-neighbour sets in YH (G) are, by deﬁnition, viable for G, but a viable set for G need not be in YH (G). For example, if H is the family of stars and G is the undirected graph in Fig. 1 (a), then any edge is a viable set for G but the only viable partition is the shaded region. Note that if U is a viable set for G then it is also a viable set for any subgraph G of G provided U ⊆ V (G ).

The 1-Neighbour Knapsack Problem

75

Viable families and viable sets play an essential role in our greedy algorithm for the general 1-neighbour knapsack problem. Viable families establish a set of structures over which our oracles can search. This restriction simpliﬁes both the design and analysis of eﬃcient oracles as well as couples the oracles to a shared family of graphs which, as we’ll show later, is essential to our analysis. In essence, viable families provide a mechanism to coordinate the oracles into returning sets with roughly similar structure. Viable sets correctly capture the idea of an indivisible unit of choice in the greedy step. We formalize this with the following lemma which is illustrated in Fig. 1 (b). Lemma 1. Let G be a graph and H be a viable family for G. Let A and B be 1-neighbour sets for G. If YH (C) is a viable partition of G[C] where C = A \ B − then every set Y ∈ YH (C) is either (i) a singleton node y such that y ∈ NG (B) (i.e., y has a neighbour in B), or (ii) a viable set for G = G[V (G) \ B] where, − in the case that G is directed, G contains no arc with a tail in NG (B). Proof. Let YH (C) be a viable partition for G[C] where C = A \ B and A, B, G, G and H are deﬁned as above. If |Y | = 1 then let Y = {y}. If δG (y) = 0 then Y is a viable set for G so it is viable set for G . Otherwise, since A is a − 1-neighbour set for G, y must have a neighbour in B so y ∈ NG (B). If |Y | > 1 then, provided G is undirected, Y is also a viable set in G so it is a viable set in G . If G is directed, then Y may not be viable in G since it might contain a node z that is a sink in G[C] but that is not a sink in G. However, in this case − − c ∈ NG (B) so it is a sink in G since G contains no arc with a tail in NG (B). Therefore, Y is viable for G .

2

The General 1-Neighbour Knapsack Problem

Here we give a greedy algorithm Greedy-1-Neighbour for the general 1neighbour knapsack problem on both directed and undirected graphs. A formal description of our algorithm is available in Fig. 2. Greedy1-Neighbour relies on two oracles Best-Profit-Viable and Best-Ratio-Viable which ﬁnd viable sets of nodes with respect to a ﬁxed viable family H. In each iteration i, we call Best-Ratio-Viable which, given the nodes not yet chosen by the algorithm, returns the highest proﬁt-to-weight ratio, viable set Si with weight not exceeding the remaining capacity. We also consider the set of nodes Z not in the knapsack, but with at least one neighbour already in the knapsack. Let si be the node with highest proﬁt-to-weight ratio in Z not exceeding the remaining capacity. We greedily add either si or Si to our knapsack U depending on which has higher proﬁt-to-weight ratio. We continue until we can no longer add nodes to the knapsack. For a viable family H, if we can eﬃciently approximate the highest proﬁt-toweight ratio viable set to within a factor of β and if we can eﬃciently approximate the highest proﬁt viable set to within a factor of α, then our greedy algorithm yields a polynomial time α2 (1 − 1/eβ )-approximation.

76

G. Borradaile, B. Heeringa, and G. Wilfong Greedy-1-Neighbour(G, k) : Smax = best-profit-viable(G, k) K = k, U = ∅, i = 1, G = G, Z = ∅ WHILE there is either a viable set in G or a node in Z with weight ≤ K Si = best-ratio-viable(G , K) si = arg max{p(v)/w(v) | v ∈ Z} IF p(si )/w(si ) > p(Si )/w(Si ) Si = {si } G = G[V (G ) \ Si ] i = i + 1, U = U ∪ V (Si ), K = K − w(Si ) − Z = NG (U ) If G is directed, remove any arc in G with a tail in Z RETURN arg max{p(Smax ), p(U )}

Fig. 2. The Greedy-1-Neighbour algorithm. In each iteration i, we greedily add either the viable set Si or the node si to our knapsack U depending on which has higher proﬁt-to-weight ratio. This continues until we can no longer add nodes to the knapsack.

Theorem 1. Greedy-1-Neighbour is a α2 (1− e1β )-approximation for the general 1-neighbour problem on directed and undirected graphs. Proof. Let OPT be the set of vertices in an optimal solution. In addition, let Ui = ∪ij=1 V (Sj ) correspond to U after the ﬁrst i iterations where U0 = ∅. Let + 1 be the ﬁrst iteration in which there is either a node in Z ∩ OPT or a viable set in OPT \ U whose proﬁt-to-weight ratio is larger than S+1 . Of these, let S+1 be the node or set with highest proﬁt-per-weight. For convenience, let Si = Si and Ui = Ui for i = 1 . . . , and U+1 = U ∪ S+1 . Notice that U is a feasible solution to our problem but that U+1 is not since it contains S+1 which has weight exceeding K. We analyze our algorithm with respect to U+1 . Lemma 2. For each iteration i = 1, . . . , + 1, the following holds: p(Si ) ≥ β

w(Si ) (p(OPT) − p(Ui−1 )) k

Proof. Fix an iteration i and let I be the graph induced by OPT \ Ui−1 . Since both OPT and Ui−1 are 1-neighbour sets for G, by Lemma 1, each Y ∈ YH (I) is either a viable set for G (so it can be selected by best-ratio-viable) or a − singleton vertex in NG (Ui−1 ) (which Greedy-1-Neighbour always considers). Thus, if i ≤ , then by the greedy choice of the algorithm and approximation ratio of best-ratio-viable we have p(Si ) p(Y ) ≥β for all Y ∈ YH (I). w(Si ) w(Y )

(1)

If i = + 1 then p(S+1 )/w(S+1 ) is, by deﬁnition, at least as large as the proﬁt-to-weight ratio of any Y ∈ Y. It follows that for i = 1, . . . , + 1

The 1-Neighbour Knapsack Problem

p(OPT) − p(Ui−1 ) =

p(u) ≤

u∈V (I)

77

1 p(Si ) w(u), by Eq. 1 β w(Si ) u∈V (I)

1 p(Si ) w(OPT), since I is a subset of OPT β w(Si ) 1 k ≤ p(Si ), since w(OPT) ≤ k β w(Si ) ≤

Rearranging gives Lemma 2. Lemma 3. For i = 1, . . . , + 1, the following holds: ⎡ ⎤ i w(Sj ) ⎦ p(Ui ) ≥ ⎣1 − 1−β p(OPT) k j=1

Proof. We prove the lemma by induction on i. For i = 1, we need to show that p(U1 ) ≥ β

w(S1 ) p(OPT). k

(2)

This follows immediately from Lemma 2 since p(U0 ) = 0 and U1 = S1 . Suppose the lemma holds for iterations 1 through i − 1. Then it is easy to show that the inequality holds for iteration i by applying Lemma 2 and the inductive hypothesis. This completes the proof of Lemma 3. We are now ready to prove Theorem 1. Starting with the inequality in Lemma 3 and using the fact that adding S+1 violates the knapsack constraint (so w(U+1 ) > k) we have ⎡ ⎤ +1 w(S ) j ⎦ p(OPT) p(U+1 ) ≥ ⎣1 − 1−β k j=1 ⎡ ⎤ +1 w(S ) j ⎦ p(OPT) ≥ ⎣1 − 1−β w(U ) +1 j=1 +1 β 1 ≥ 1− 1− p(OPT) ≥ 1 − β p(OPT) +1 e where the penultimate inequality follows because equal w(Sj ) maximize the product. Since Smax is within a factor of α of the maximum proﬁt viable set of weight ≤ k and S+1 is contained in OPT, p(Smax ) ≥ α · p(S+1 ). Thus, we have p(U ) + p(Smax )/α ≥ p(U ) + p(S+1 ) = p(U+1 ) ≥ 1 − e1β p(OPT). Therefore max{p(U ), p(Smax )} ≥ α2 1 − e1β p(OPT).

78

2.1

G. Borradaile, B. Heeringa, and G. Wilfong

The General, Undirected 1-Neighbour Problem

Here we formally show that stars are a viable family for undirected graphs and describe polynomial-time implementations of Best-Profit-Viable and Best-Ratio-Viable that operate with respect to stars. Both oracles achieve an approximation ratio of (1 − ε) for any ε > 0. Combined with Greedy-1Neighbour this yields a polynomial time ((1−ε)/2)·(1−1/e1−ε)-approximation for the general, undirected 1-neighbour problem. In addition, we show that this approximation is nearly tight by showing that the general, undirected 1neighbour problem generalizes many coverage problems including the max k-cover and budgeted maximum coverage, neither of which have a (1 − 1/e + )approximation for any > 0 unless P=NP. Stars. For the rest of this section, we assume H is the family of star graphs (i.e. graphs composed of a center vertex u and a (possibly empty) set of edges all of which have u as an endpoint) so that given a graph G and a capacity k, BestProfit-Viable returns the highest proﬁt, viable star with weight at most k and Best-Ratio-Viable returns the highest proﬁt-to-weight, viable star with weight at most k. Lemma 4. The nodes of any undirected constraint graph G can be partitioned into 1-neighbour sets that are stars. Proof. Let Gi be an arbitrary connected component of G. If |V (Gi )| = 1 then V (Gi ) is trivially a 1-neighbour set and the trivial star consisting of a single node is a spanning subgraph of Gi . If Gi is non-trivial then let T be any spanning tree of Gi and consider the following algorithm: while T contains a path P with |P | > 2, remove an interior edge of P from T . When the algorithm ﬁnishes, each path has at least one edge and at most two edges, so T is a set of non-trivial stars, each of which is a 1-neighbour set. Best-Profit-Viable. Finding the maximum proﬁt, viable star of a graph G subject to a knapsack constraint k reduces to the traditional unconstrained knapsack problem which has a well-known FPTAS that runs in O(n3 /ε) time [6,14]. Every vertex v ∈ V (G) deﬁnes a knapsack problem: the items are NG (v) and the capacity is k − w(v). Combining v with the solution returned by the FPTAS yields a candidate star. We consider the candidate star for each vertex and return the one with highest proﬁt. Since we consider all possible star centers, Best-Profit-Viable runs in O(n4 /ε) time and returns a viable star within a factor of (1 − ε) of optimal, for any ε > 0. Best-Ratio-Viable. We again turn to the FPTAS for the standard knapsack problem. Our goal is to ﬁnd a high proﬁt-to-weight star in G with weight at most k. The standard FPTAS for the unconstrained knapsack problem builds a dynamic programing table T with n rows and nP columns where n is the number of available items and P is the maximum adjusted proﬁt over all p(v) the items. Given an item v, its adjusted proﬁt is p (v) = (ε/n)·P where P is

The 1-Neighbour Knapsack Problem

79

the true maximum proﬁt over all the items. Each entry T [i, p] gives the weight of the minimum weight subset over the ﬁrst i items achieving proﬁt p. An auxiliary data structure allows us to eﬃciently retrieve the corresponding subset. Notice that, for any ﬁxed proﬁt p, p/T [n, p] is the highest proﬁt-to-weight ratio for that p. Therefore, for 1 ≤ p ≤ nP , the p maximizing p/T [n, p] gives the highest proﬁt-to-weight ratio of any feasible subset provided T [n, p] ≤ k. Let S be this subset. We will show that p(S)/w(S) is within a factor of (1 − ε) of OPT where OPT is the proﬁt-to-weight ratio of the highest proﬁt-to-weight ratio feasible subset S ∗ . Letting r(v) = p(v)/w(v) and r (v) = p (v)/w(v), and following [14], we have r(S ∗ ) − ((ε/n) · P ) · r (S ∗ ) ≤ εP/w(S ∗ ) since, for any item v, the diﬀerence between p(v) and ((ε/n) · P ) · p (v) is at most (ε/n) · P and we can ﬁt at most n items in our knapsack. Because r (S) ≥ r (S ∗ ) and OPT is at least P/w(S ∗ ) we have r(S) ≥ (ε/n) · P · r (S ∗ ) ≥ r(S ∗ ) − εP/w(S ∗ ) ≥ OPT − εOPT = (1 − ε)OPT. Now, just as with Best-Profit-Viable, every vertex v ∈ V (G) deﬁnes a knapsack instance where NG (V ) is the set of items and k − w(v) is the capacity. We run the modiﬁed FTPAS for knapsack on the instance deﬁned by v and add v to the solution to produce a set of candidate stars. We return the star with highest proﬁt-to-weight ratio. Since we consider all possible star centers, Best-RatioViable runs in O(n4 /ε) time and returns a viable star within a factor of (1 − ε) of optimal, for any ε > 0. Why Stars? Besides some isolated vertices, our solution is a set of edges, but the edges are not necessarily vertex disjoint. Analyzing our greedy algorithm in terms of edges risks counting vertices multiple times. Partitioning into stars allows us to charge increases in the proﬁt from the greedy step without this risk. In fact, stars are essentially the simplest structure meeting this requirement which is why we use them as our viable family. General, Undirected 1-Neighbour Knapsack is APX-Complete. Here we show that it is NP-hard to approximate the general, undirected 1-neighbour knapsack problem to within a factor better than 1 − 1/e + for any > 0 via an approximation-preserving reduction from max k-cover [3]. An instance of max k-cover is a set cover instance (S, R) where S is a ground set of n items and R is a collection of subsets of S. The goal is to cover as many items in S using at most k subsets from R. Theorem 2. The general, undirected 1-neighbour knapsack problem has no 1 − 1/e + -approximation for any > 0 unless P=NP. Proof. Given an instance of (S, R) of max k-cover, build a bipartite graph G = (U ∪ V, E) where U has a node ui for each si ∈ S and V has a node vj for each

80

G. Borradaile, B. Heeringa, and G. Wilfong

set Rj ∈ R. Add the edge {ui , vj } to E if and only if ui ∈ Rj . Assign proﬁt p(ui ) = 1 and weight w(ui ) = 0 for each vertex ui ∈ U and proﬁt p(vj ) = 0 and weight w(ui ) = 1 for each vertex vj ∈ V . Since no pair of vertices in U have an edge and since every vertex in U has no weight, our strategy is to pick vertices from V and all their neighbours in U . Since every vertex of U has unit proﬁt, we should choose the k vertices from V which collectively have the most neighbours. This is exactly the max k-cover problem. The max k-cover problem represents a class of budgeted maximum coverage (BMC) problems where the elements in the base set have unit proﬁt (referred to as weights in [9]) and the cover sets have unit weight (referred to as costs in [9]). In fact, one can use the above reduction to represent an arbitrary BMC instance: form the same bipartite graph, assign the element weights in BMC as vertex proﬁts in U , and ﬁnally assign the covering set costs in BMC as vertex weights in V . 2.2

General, Directed 1-Neighbour Knapsack Is Hard to Approximate

Here we consider the 1-neighbour knapsack problem where G is directed and has arbitrary proﬁts and weights. We show via a reduction from directed Steiner tree (DST) that the general, directed 1-neighbour problem is hard to approximate within a factor of 1/Ω(log1−ε n). Our result holds for DAGs. Because of this negative result, we also don’t expect that good approximations exist for either Best-Profit-Viable and Best-Ratio-Viable for any family of viable graphs. In the DST problem on DAGs we are given a DAG G = (V, E) where each arc has an associated cost, a subset of t vertices called terminals and a root vertex r ∈ V . The goal is to ﬁnd a minimum cost set of arcs that together connect r to all the terminals (i.e., the arcs form an out-arborescence rooted at r). For all ε > 0, DST admits no log2−ε n-approximation algorithm unless N P ⊆ ZT IM E[npoly log n ] [5]. This result holds even for very simple DAGs such as leveled DAGs in which r is the only root, r is at level 0, each arc goes from a vertex at level i to a vertex at level i + 1, and there are O(log n) levels. We use leveled DAGs in our proof of the following theorem. Theorem 3. The general, directed 1-neighbour knapsack problem 1/Ω(log1−ε n)-hard to approximate unless N P ⊆ ZT IM E[npoly log n ].

is

Proof. Let D be an instance of DST where the underlying graph G is a leveled DAG with a single root r. Suppose there is a solution to D of cost C. Claim. If there is an α-approximation algorithm for the general, directed 1neighbour knapsack problem then a solution to D with cost O(α log t) × C can be found where t is the number of terminals in D. Proof. Let G = (V, A) be the DAG in instance D. We modify it to G = (V , A ) where we split each arc e ∈ A by placing a dummy vertex on e with weight equal

The 1-Neighbour Knapsack Problem

81

to the cost of e according to D and proﬁt of 0. In addition, we also reverse the orientation of each arc. Finally, all other vertices are given weight 0 and terminals are assigned a proﬁt of 1 while the non-terminal vertices of G are given a proﬁt of 0. We create an instance N of the general, directed 1-neighbour knapsack problem consisting of G and budget bound of C. By assumption, there is a solution to N with cost C and proﬁt t. Therefore given N , an α-approximation algorithm would produce a set of arcs whose weight is at most C and includes at least t/α terminals. That is, it has a proﬁt of at least t/α. Set the weights of dummy nodes to 0 on the arcs used in the solution. Then for all terminals included in this solution, set their proﬁt to 0 and repeat. Standard set-cover analysis shows that after O(α log t) repetitions, each terminal will have been connected to the root in at least one of the solutions. Therefore the union of all the arcs in these solutions has cost at most O(α log t) × C and connects all terminals to the root. Using the above claim, we’ll show that if there is an α-approximation algorithm for the general, directed-1-neighbour problem then there is an O(α log t)approximation algorithm for DST which implies the theorem. Let L be the total cost of the arcs in the instance of DST. For each 2i < L, take C = 2i and perform the procedure in the previous claim for α log t iterations. If after these iterations all terminals are connected to the root then call the cost of the resulting arcs a valid cost. Finally, choose the smallest valid cost, say C and C will be no more than 2COPT where COPT is the optimal cost of a solution for the DST instance. By the previous claim we have a solution whose cost is at most 2COPT × O(α log t).

3

The Uniform, Directed 1-Neighbour Knapsack Problem

In this section, we give a PTAS for the uniform, directed 1-neighbour knapsack problem. We rule out an FPTAS by proving the following theorem, the proof of which appears in [2]. Theorem 4. The uniform, directed 1-neighbour problem is strongly NP-hard. A PTAS for the Uniform, Directed 1-Neighbour Problem. Let U be a 1-neighbour set. Let AU be a minimal set of arcs of G such that for every vertex u ∈ U , δG[AU ] (u) ≥ min{δG (u), 1}. That is, AU is a witness to the feasibility of U as a 1-neighbour set. Since each node of U in G[AU ] has out-degree 0 or 1, the structure of AU has the following form. Property 1. Each connected component of G[AU ] is a cycle C and a collection of vertex-disjoint in-arborescences, each rooted at a node of C. C may be trivial, i.e., C may be a single vertex v, in which case δG (v) = 0. For a strongly connected component X, let c(X) be the size of the shortest directed cycle in X with c(X) = 1 if and only if |X| = 1.

82

G. Borradaile, B. Heeringa, and G. Wilfong

C

P

C'

(a)

(b)

Fig. 3. Construction of a witness containing the smallest cycle of an SCC. The shaded region highlights the vertices of an SCC (edges not in C, C , or P are not depicted). The edges of the witness are solid. (a) The smallest cycle C is not in the witness. (b) By removing an edge from C and leaf edges from the in-arborescences rooted on C, we create a witness that includes the smallest cycle C .

Lemma 5. There is an optimal 1-neighbour knapsack U and a witness AU such that for each non-trivial, maximal SCC K of G, there is at most one cycle of AU in K and this cycle is a smallest cycle of K. Proof. First we modify AU so that it contains smallest cycles of maximal SCCs. We rely heavily on the structure of AU guaranteed by Property 1. The idea is illustrated in Fig. 3. Let C be a cycle of AU and let K be the maximal SCC of G that contains C. Suppose C is not the smallest cycle of K or there is more than one cycle of AU in K. Let H be the connected component of AU containing C. Let C be a smallest cycle of K. Let P be the shortest directed path from C to C . Since C and C are in a common SCC, P exists. Let T be an in-arborescence in G spanning P , C and H rooted at a vertex of C . Some vertices of C ∪ P might already be in the 1-neighbour set U : let X be these vertices. Note that X and V (H) are disjoint because of Property 1. Let T be a sub-arborescence of T such that: – T has the same root as T , and – |V (T ∪ C ) ∪ X| = |V (H)| + |X|. Since |V (T ∪ C )| = |V (P ∪ H ∪ C )| ≥ |V (H)| + |X| and T ∪ C is connected, such an in-arborescence exists. Let B = (AU \ H) ∪ T ∪ C . Let B be a witness spanning V (B) contained in B that contains the arcs in C . We have that B has |U | vertices and contains a smallest cycle of K. We repeat this procedure for any SCC in our witness that contains a cycle of a maximal SCC of G that is not smallest or contains two cycles of a maximal SCC. To describe the algorithm, let D = (S, F ) be the DAG of maximal SCCs of G and let ε > 1/k be a ﬁxed constant where k is the knapsack bound. (If ε ≤ 1/k then

The 1-Neighbour Knapsack Problem

83

the brute force algorithm which considers all subsets V ⊆ V (G) with |V | ≤ k yields an acceptable bound for a PTAS.) We say that u ∈ S is large if c(u) > ε k, petite if 1 < c(u) ≤ ε k, or tiny if c(u) = 1. Let L, P , and T be the set of all large, petite and tiny SCCs respectively. Note that since ε > 1/k, for every u ∈ L, c(u) > ε k > 1. uniform-directed-1-neighbour B=∅ For every subset X ⊆ L such that |X| ≤ 1/ε DX = D[P ∪ X]. Z = {tiny sinks of D} ∪ {petite sinks of DX } P = any maximal subset of Z such that c(P ) + c(X) ≤ k. U = K∈P ∪X {V (C) : C is a smallest cycle of K} Greedily add vertices to U such that U remains a 1-neighbour set until there are no more vertices to add or |U | = k. (Via a backwards search rooted at U .) B = arg max{|B|, |U |} Return B. Theorem 5. uniform-directed-1-neighbour is a PTAS for the uniform, directed 1-neighbour knapsack problem. Proof. Let U ∗ be an optimal 1-neighbour knapsack and let AU ∗ be its witness as guaranteed by Lemma 5. Let L, P, and T be the sets of large, petite, and tiny cycles in AU ∗ respectively. By Lemma 5, each of these cycles is in a diﬀerent maximal SCC and each cycle is a smallest cycle in its maximal SCC. Let L = {L1 , . . . , L } and let L∗ be the set of large SCCs that intersect L1 , . . . , L . Note that |L∗ | = . Since k ≥ |U ∗ | ≥ i=1 |Li | > ε k we have < 1/ε. So, in some iteration of uniform-directed-1-neighbour, X = L∗ . We analyze this iteration of the algorithm. There are two cases: P = Z. First we show that every vertex in U ∗ has a descendant in X ∪ P . Clearly if a vertex of U ∗ has a descendant in some Li ∈ L, it has a descendant in X. Suppose a vertex of U ∗ has a descendant in some Pi ∈ P. Pi is within an SCC of DX , and so it must have a descendant that is in a sink of DX . Similarly, suppose a vertex of U ∗ has a descendant in some Ti ∈ T . Ti is either a sink in D or has a descendant that is either a sink of D or a sink of DX . All these sinks are contained in X ∪ P . Since every vertex of U ∗ can reach a vertex in X ∪ P , greedily adding to this set results in |U | = |U ∗ | and the result of uniform-directed-1-neighbour is optimal. P = Z. For any sink x ∈ / P , c(P ) + c(X) + c(x) > k but c(x) ≤ ε k by the deﬁnition of tiny and petite. So, |U | ≥ c(P ) + c(X) > (1 − ε)k, and the resulting solution is within (1 − ε) of optimal. The running time of uniform-directed-1-neighbour is nO(1/ε) . It is dominated by the number of iterations, each of which can be executed in poly time.

84

4

G. Borradaile, B. Heeringa, and G. Wilfong

The Uniform, Undirected 1-Neighbour Problem

As our ﬁnal result, we note that there is a relatively straightforward linear time algorithm for ﬁnding an optimal solution for instances of the uniform, undirected 1-neighbour knapsack problem. The algorithm essentially breaks the graph into connected components and then, using a counting argument, builds an optimal solution from the components. A proof of the following theorem appears in [2]. Theorem 6. The uniform, undirected case has a linear-time solution. Acknowledgments. We thank Anupam Gupta for helpful discussions in showing hardness of approximation for general, directed 1-neighbour knapsack.

References 1. Boland, N., Fricke, C., Froyland, G., Sotirov, R.: Clique-based facets for the precedence constrained knapsack problem. Technical report. Tilburg University Repository, Netherlands (2005), http://arno.uvt.nl/oai/wo.uvt.nl.cgi 2. Borradaile, G., Heeringa, B., Wilfong, G.: The knapsack problem with neighbour constraints. CoRR, abs/0910.0777 (2011) 3. Feige, U.: A threshold of ln n for approximating set cover. J. ACM 45(4), 634–652 (1998) 4. Goundan, P.R., Schulz, A.S.: Revisiting the greedy approach to submodular set function maximization (2009) (preprint) 5. Halperin, E., Krauthgamer, R.: Polylogarithmic inapproximability. In: Proceedings of STOC, pp. 585–594 (2003) 6. Ibarra, O.H., Kim, C.E.: Fast approximation algorithms for the knapsack and sum of subset problems. J. ACM 22, 463–468 (1975) 7. Johnson, D.S., Niemi, K.A.: On knapsacks, partitions, and a new dynamic programming technique for trees. Mathematics of Operations Research, 1–14 (1983) 8. Kellerer, H., Pferschy, U., Pisinger, D.: Knapsack Problems. Springer, Heidelberg (2004) 9. Khuller, S., Moss, A., Naor(Seﬃ), J.: The budgeted maximum coverage problem. Inf. Process. Lett. 70(1), 39–45 (1999) 10. Kolliopoulos, S.G., Steiner, G.: Partially ordered knapsack and applications to scheduling. Discrete Applied Mathematics 155(8), 889–897 (2007) 11. Kulik, A., Shachnai, H., Tamir, T.: Maximizing submodular set functions subject to multiple linear constraints. In: Proceedings of the twentieth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2009, pp. 545–554. Society for Industrial and Applied Mathematics, Philadelphia (2009) 12. Lee, J., Mirrokni, V.S., Nagarajan, V., Sviridenko, M.: Non-monotone submodular maximization under matroid and knapsack constraints. In: Proceedings of the 41st Annual ACM Symposium on Theory of Computing, STOC 2009, pp. 323–332. ACM, New York (2009) 13. Sviridenko, M.: A note on maximizing a submodular set function subject to a knapsack constraint. Operations Research Letters 32(1), 41–43 (2004) 14. Vazirani, V.: Approximation Algorithms. Springer, Berlin (2001)

A Golden Ratio Parameterized Algorithm for Cluster Editing Sebastian B¨ocker Lehrstuhl f¨ ur Bioinformatik, Friedrich-Schiller-Universit¨ at Jena, Ernst-Abbe-Platz 2, 07743 Jena, Germany sebastian.boecker@uni-jena.de

Abstract. The Cluster Editing problem asks to transform a graph by at most k edge modiﬁcations into a disjoint union of cliques. The problem is NP-complete, but several parameterized algorithms are known. We present a novel search tree algorithm for the problem, which improves running time from O∗ (1.76k ) to O∗ (1.62k ). In detail, we can show that we can always branch with branching vector (2, 1) or better, resulting in the golden ratio as the base of the search tree size. Our algorithm uses a well-known transformation to the integer-weighted counterpart of the problem. To achieve our result, we combine three techniques: First, we show that zero-edges in the graph enforce structural features that allow us to branch more eﬃciently. Second, by repeatedly branching we can isolate vertices, releasing costs. Finally, we use a known characterization of graphs with few conﬂicts.

1

Introduction

Given an undirected graph G, the Cluster Editing problem asks for a minimal set of edge modiﬁcations such that the resulting graph is a vertex-disjoint union of cliques. In the corresponding Integer-Weighted Cluster Editing problem, we are given modiﬁcation costs for each edge or non-edge, and we search for a set of edge modiﬁcations with minimum total weight. Here, one assumes that all edges have non-zero modiﬁcation cost. In application, the above task corresponds to clustering objects, that is, partitioning a set of objects into homogeneous and well-separated subsets. Similar objects are connected by an edge, and a cluster is a clique of the input graph. The input graph is corrupted and we have to clean (edit) the graph to reconstruct the clustering under the parsimony criterion. Clustering data still represents a key step of numerous life science problems. The weighted variant of the Cluster Editing problem has been frequently proposed for clustering biological entities such as proteins [18]. The Cluster Editing problem is NP-hard [13]. The parameterized complexity of Cluster Editing, using the number of edge modiﬁcations as parameter k, is well-studied, see also the FPT races column in [17]. A ﬁrst algorithm with running time O∗ (2.27k ) [10] was improved to O∗ (1.92k ) by an extensive case analysis [9]. By transforming the problem to the integer-weighted C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 85–95, 2011. c Springer-Verlag Berlin Heidelberg 2011

86

S. B¨ ocker

variant, running time was advanced to O∗ (1.82k ) [1]. Using a characterization of graphs that do not contain many conﬂicts, results in the currently fastest algorithm with running time O∗ (1.76k ) [3]. There exist linear problem kernels for the unweighted [5] and the integer-weighted variant [4]. Recently, Cluster Editing with “don’t care edges” (that is, edges whose modiﬁcation cost is zero) has been shown to be ﬁxed-parameter tractable [14]. To ﬁnd exact solutions in practice, a combination of data reduction and Integer Linear Programming proved to be very eﬃcient [2]. Our contributions. We present a new search tree algorithm for Cluster Editing with running time O(1.62k + k 2 + m + n) for m edges and n vertices, being the fastest known for the problem. The algorithm itself is rather simple, and is based on the merge branching introduced in [1]. We stress that our result only holds for the unweighted Cluster Editing problem, as general integerweighted instances will not satisfy the “parity property” introduced below.

2

Preliminaries

A problem with input size n and parameter k is fixed-parameter tractable (FPT) if it can be solved in O(f (k) · p(n)) time where f is any computable function and p is a polynomial. We naturally focus on the f (k) factor, and sometimes adopt the O∗ (f (k)) notation that suppresses polynomial factors. For a general introduction we refer to [7,15]; in particular, we assume familiarity with bounded search trees, branching vectors, and branching numbers. In the following, let n be the number of vertices, and k the number of edge modiﬁcations. For brevity, we write uv as shorthand for an unordered pair {u, v} ∈ V2 . V Let s : 2 → Z be a weight function that encodes the input graph: For s(uv) > 0 a pair uv is an edge of the graph and has deletion cost s(uv), while for s(uv) < 0, the pair uv is not an edge (a non-edge) of the graph and has insertion cost −s(uv). Let N (u) be the set of all vertices v ∈ V such that s(uv) > 0. If s(uv) = 0, we call uv a zero-edge. We require that there are no zero-edges in the input graph. Nonetheless, zero-edges can appear in the course of computation and require additional attention when analyzing the algorithm. When analyzing connected components we only consider edges of the graph. We say that C ⊆ V is a clique in an integer-weighted graph if all pairs uv ∈ C2 are edges. If all vertex pairs of a connected component are either edges or zero-edges, we call it a weak clique. Vertices uvw form a conflict triple in an integer-weighted graph if uv and vw are edges but uw is either a non-edge or a zero-edge. We distinguish two types of conﬂict triples uvw: if uw has weight zero then the conﬂict triple is called weak, whereas if uw is a non-edge then the conﬂict triple is called strong. If the integer-weighted graph contains no conﬂict triples then it is transitive, i.e. a disjoint union of weak cliques. But the converse is obviously not true, as the example of a single weak conﬂict triple shows: This graph is a weak clique but contains a (weak) conﬂict triple. To solve Weighted Cluster Editing we ﬁrst identify all connected components of the input graph and calculate the best solutions for each component separately, because an

A Golden Ratio Parameterized Algorithm for Cluster Editing

87

optimal solution never connects disconnected components. Furthermore, if the graph is decomposed during the course of the algorithm, then we recurse and treat each connected component individually. An unweighted Cluster Editing instance can be encoded by assigning weights s(uv) ∈ {+1, −1}. In the resulting graph, all conﬂict triples are strong. During data reduction and branching, we may set pairs uv to “forbidden” or “permanent”. Permanent edges can be merged immediately: Merging uv means replacing the vertices u and v with a single vertex u , and, for all vertices w ∈ V \ {u, v}, replacing pairs uw, vw with a single pair u w. In this context, we say that we join vertex pairs uw and vw. The weight of the joined pair is s(u w) = s(uw) + s(vw). In case one of the pairs is an edge while the other is a non-edge, then we can decrease parameter k by min{|s(uw)| , |s(vw)|}. Note that we may join any combination of two edges, non-edges, or zero-edges when merging two vertices. We stress that joined pairs can be zero-edges. We encode a forbidden pair uv by setting s(uv) = −∞. By deﬁnition, every forbidden pair uv is a non-edge, since s(uv) < 0. A forbidden pair uw can be part of a conﬂict triple uvw, which then is a strong conﬂict triple. Assume that we join pairs uv and uw where uw is forbidden and, hence, a non-edge. From the above deﬁnition, the resulting pair u w is forbidden, too, as s(u w) = s(uw) + s(vw) = −∞ + s(vw) = −∞ holds for all s(vw) ∈ R ∪ {−∞}. Finally, if uw is forbidden and vw is an edge then k is decreased by min{∞, |s(vw)|} = s(vw). The following branching was proposed in [1]: We branch on an edge uv by recursively calling the algorithm two times, either removing uv and setting it to forbidden, or merging uv. If uv is part of at least one strong conﬂict triple, then merging uv will generate cost: As there is both an edge uw and a non-edge vw, we can reduce k by min{s(uw), −s(vw)}. In case s(uw) = −s(vw), joining uw and vw into u w results in u w being a zero-edge. At a later stage of the algorithm, this would prevent us from decreasing our parameter when joining the zero-edge u w. To circumvent this problem, the following bookkeeping trick was introduced in [1]: We assume that joining uw and vw with s(uw) = −s(vw) only reduces the parameter by min{s(uw), −s(vw)} − 12 = |s(uw)| − 12 ≥ 12 . If at a later stage we join this zero-edge with another pair, we decrease our parameter by the remaining 12 . So, both generating and destroying a zero-edge generates cost of at least 12 . Note that joining with a forbidden pair cannot create a zero-edge. Assume that s(vw) = −s(uw) with |s(vw)| = |s(uw)| ≥ 2. Then, merging an edge uv in a conﬂict triple uvw will also generate a zero-edge, and generates cost of at least 32 . In our analysis, we sometimes concentrate on the case that s(vw) = −s(uw) = ±1, where merging uv has cost 12 . We do so only if it is absolutely obvious that |s(vw)| = |s(uw)| ≥ 2 will result in the desired branching vector. Our ﬁxed-parameter algorithms require a cost limit k: In case a solution with cost ≤ k exists, the algorithm ﬁnds this solution; otherwise, “no solution” is returned. To ﬁnd an optimal solution we call the algorithm repeatedly, increasing k.

88

3

S. B¨ ocker

Vertex Parities

We need a simple observation about the input graphs to reach an improved running time: An integer-weighted graph G with weight function s : V2 → Z has the parity property if there is a parity mapping p : V → {even, odd} such that, for each pair uv, s(uv) is odd if and only if both p(u) = odd and p(v) = odd holds. We ignore forbidden pairs in this deﬁnition, since s(uv) = −∞ has no parity. Note that p is not necessarily unique, as demonstrated by a graph with two vertices and even edge weight. We infer a few simple observations from this deﬁnition: If s(uv) is even, then either u or v or both must have even parity. If u is even then s(uv) is even or uv is forbidden, for all v = u. Clearly, an unweighted instance of Cluster Editing has the parity property, as we can set p(u) = odd for all vertices u ∈ V . The interesting observation is that a graph does not loose the parity property if we merge two vertices. Quite possibly, this results has been stated before in a diﬀerent graph-theoretical context. We defer the simple, constructive proof to the full paper. Lemma 1. Assume that an integer-weighted graph G has the parity property. If we merge two vertices in G, then the resulting graph also has the parity property. If the input graph has the parity property then, after any sequence of merging operations, the resulting graph still has the parity property. This is particularly so for the edge branching from [1], as both operations (setting an edge to forbidden, or merging two vertices) preserve the parity property. For our branching, it is important to notice that a zero-edge has even parity, so the parity of at least one of its incident vertices must be even.

4

Isolation and Vertices of Even Parity √

Let ϕ = 1+2 5 = 1.61803 . . . be the golden ratio, satisfying ϕ = 1 + ϕ1 . One can easily see that a search tree algorithm with branching vector (2, 1) results in a search tree of size O(ϕk ): This branching number is the positive root of x−2 + x−1 − 1, so 1 + x − x2 = 0, and dividing by x results in the deﬁnition of the golden ratio. Our branching strategy is based on a series of lemmata, ensuring that either there is an edge to branch on, or that the remaining graph is “easy”. Clearly, branching on an edge that is part of four or more conﬂict triples results in the desired branching vector. To this end, we concentrate on the critical case of three conﬂict triples. First, we consider the case of three strong conﬂict triples: Lemma 2. Let G be an integer-weighted graph that has the parity property. Assume that an edge uv is part of exactly three conflict triples, all of which are strong. Then, we can branch with branching number ϕ = 1.61803 . . . . We use this lemma to show that we can ﬁnd an edge to branch on, if we can ﬁnd an edge that is part of at least three conﬂict triples.

A Golden Ratio Parameterized Algorithm for Cluster Editing

89

Lemma 3. Let G be an integer-weighted graph that has the parity property. Assume that an edge uv is part of three or more conflict triples. Then, we can either find an edge with branching number ϕ, or we can reduce k without branching. The remainder of this section is devoted to proving these two central lemmata. Proof (Lemma 2). We will show that we can ﬁnd an edge to branch on, with branching vector (1, 2) or better. In our reasoning, we will show that either, we have already reached the desired branching vector; or, we can infer certain structural properties about the instance. Let a, b, c be the three vertices that are part of the three conﬂict triples with u, v. If s(uv) ≥ 2 then branching on uv results in deletion cost s(uv) ≥ 2 and merging cost 3 · 12 , so we reach branching vector (2, 32 ) and we are done. If uvx with x ∈ {a, b, c} is a conﬂict triple such that s(vx) ≥ 2 or s(ux) ≤ −2, then merging uv into u will not create a new zero-edge incident to u . So, branching on uv has branching vector (1, 2 · 12 + 1) = (1, 2), and we are done. The same argumentation holds for a conﬂict triple vux. In the following, we may assume that a, b, c are odd, and that s(uv) = 1 and |s(wx)| = 1 holds for all w ∈ {u, v} and x ∈ {a, b, c}; for all other cases, we have just shown that the desired branching vector can be reached. Assume that u, v do not have a common neighbor, N (u)∪N (v) = {u, v, a, b, c}. Then, merging u, v into u generates three zero-edges u a, u b, u c, and u is isolated, N (u ) = ∅. But then, we do not have to use bookkeeping for these edges, as {u } will also be a separated cluster of size one in the solution. So, branching on uv results in branching vector (1, 3). We will now use the same trick that the merged vertex u can be isolated, but this is slightly more involved in case u, v have at least one common neighbor. Let D := N (u) ∩ N (v), then N (u) ∪ N (v) = D ∪ {u, v, a, b, c} and |D| ≥ 1. Our ﬁrst step is to branch on uv: We delete uv with cost 1, and set it to forbidden. Next, we merge u, v into a new vertex u . This generates three zero edges u a, u b, u c with costs 32 . Here, s(u d) ≥ 2 holds for all d ∈ D = {d1 , . . . , dl }. We will now branch on all edges u dj where the case that u dj is deleted, is further analyzed. In detail, we either merge u di with costs 32 ; or, we delete u di with cost 2 and branch on u di+1 , if i < l. Note that we either delete all d1 , . . . , dl , or we ﬁnally merge some u di with cost 32 . In the latter case, the total costs of this branch are 2(i − 1) + 32 . But in the very last case where all d1 , . . . , dl are deleted, we separate u . Hence, by the reasoning introduced above, we can “cash” cost 32 we have put aside when generating the three zero-edges u a, u b, u c. So, the costs of this ﬁnal branch are 2l + 32 . Recall that in all cases, we have additional cost 3 2 for generating the three zero-edges. In total, we reach the partial branching vector (0 + 3, 2 + 3, . . . , 2l + 3) = (3, 5, 7, . . . , 2l + 3). We combine these two partial branching vectors into one branching vector (1, 3, 5, 7, 9, . . . , 2l + 3). We claim that any such branching vector corresponds to a branching number x < ϕ, and that the numbers converge towards ϕ. To this end, ﬁrst note that 1/ϕ is the unique positive root of the polynomial x2 + x − 1, that is the characteristic polynomial of branching vector (2, 1). We analyze the

90

S. B¨ ocker

inﬁnite series f (x) := x0 + x2 + x4 + . . . that converges for all |x| < 1. Now, x2 · f (x) = f (x) − 1 and (x2 + x − 1) · f (x) = f (x) − 1 + xf (x) − f (x) = xf (x) − 1. So, for the series g(x) := xf (x) − 1 we have g(x) = xf (x) − 1 = (x2 + x − 1) · f (x) and, hence, g(1/ϕ) = 0. For the partial sums Sl (x) := x2l+3 + x2l+1 + · · · + x3 + x1 − 1 we infer Sl (x) < Sl+1 (x) and Sl (x) < g(x) for x ∈ (0, ∞). Also, Sl is strictly increasing in [0, ∞). Note that any polynomial of the form p(x) := an xn + · · · + a1 x1 − 1 with ai ≥ 0 for all i, has exactly one positive root for p ≡ −1. This follows as p is continuous, p (x) > 0 for all x > 0, so p is strictly increasing in (0, ∞), p(0) = −1, and limx→∞ p(x) = ∞. Let xl be the unique positive root of Sl (x). With Sl (xl+1 ) < Sl+1 (xl+1 ) = 0 we ﬁnally infer x1 > x2 > x3 > · · · > 1/ϕ. By deﬁnition, 1/xl is the branching (1, 3, 5, 7, 9, . . . , 2l + 3), and we reach

number

for

branching

vector

1/x1 < 1/x2 < 1/x3 < · · · < ϕ. Since the series Sl converges uniformly to g in the interval [0, α] for every α < 1, we infer that liml 1/xl = ϕ must hold, which concludes the proof of the lemma.

Proof (Lemma 3). Again, we will show that either, we have already reached the desired branching vector (1, 2) or better; or, we can infer certain structural properties about the instance. If uv is part of four conﬂict triples then we reach branching vector (1, 4 · 12 ) = (1, 2). If uv is part of three strong conﬂict triples then Lemma 2 guarantees branching number ϕ. So, assume that uv is part of exactly three conﬂict triples, and that uvw is a weak conﬂict triple, so uw is a zero-edge. As uv is part of three conﬂict triples, we can choose a, b such that N (u) N (v) = {w, a, b}. Clearly, for s(uv) = 2 we have branching vector (2, 32 ), so we may assume s(uv) = 1. This implies that both u and v must have odd parity. Since uw is a zero-edge, we infer that w has even parity and, hence, that s(vw) ≥ 2 holds. For our worst-case considerations, we may assume s(vw) = 2. If vw is part of any additional conﬂict triples besides wvu, then we reach branching vector (2, 1) for branching on vw: Deleting vw has cost 2, and merging vw then has cost 2 · 12 . The same holds true if v or w are incident to additional zero-edges besides uw. So, assume there are no zero-edges incident to v or w besides uw, and vx is an edge if and only if wx is an edge for all x = u, v, w. Let X ⊆ V \ {u, v, w} be the set of vertices incident to v and, consequently, also to w. Let X := X \ {a, b}, and note that this set can be empty. All x ∈ X are

A Golden Ratio Parameterized Algorithm for Cluster Editing

91

also incident with u; otherwise, there is a fourth conﬂict triple for the edge uv. We infer N ({u, v, w}) ⊆ {u, v, w, a, b} ∪ X . Choose an arbitrary x ∈ X . If wx is part of an additional conﬂict triple besides wxu, or if x is incident to a zero-edge, then we again reach branching vector (2, 1) for branching on wx: Deleting wx has cost 2 since w is even, and merging wx has cost 2 · 12 . Hence, we infer three things: Firstly, each y adjacent to some x ∈ X is also adjacent to w and, hence, y ∈ X. So, N (X ) ⊆ {u, v, w, a, b} ∪ X . Secondly, each pair x, y ∈ X must be connected by an edge. We distinguish three cases: 1. Assume a, b ∈ X, so va and vb are edges. In this case, u, v, w, a, b, X form a connected component. If ab is a zero-edge or non-edge, then branching on wa results in branching vector (2, 2 · 12 ): although w, a, u do not form a conﬂict triple, merging wa still destroys the zero-edge uw. So, we may assume that ab is an edge. By the same reasoning, ax and bx must be edges, for all x ∈ X . Next, s(ux) = 1 must hold for all x ∈ X ; otherwise, we can branch on ux with branching vector (2, 3 · 12 ). The cost of separating u from all other vertices is |X | + 1, and the resulting graph consists of two cliques {u} and {v, w, a, b} ∪ X . The cost of any other cut in this connected component is at least |X | + 3 (for separating a or b), since w is adjacent to all vertices but u with edges of weight at least 2. The cost of transforming the connected component into a clique is |s(ua)| + |s(ub)|. So, we can test in constant time if one of the two possible transformations has cost at most k. 2. Assume a ∈ X and b ∈ / X, so va and ub are edges. Then, N ({u, v, w, a} ∪ X ) ⊆ {u, v, w, a, b}∪X . For s(ua) < −1 we reach branching vector (1, 2· 12 + 1) for branching on uv, as merging u, v will not generate a zero-edge incident to a and, hence, no bookkeeping is required. (Obviously, this includes the case that ua is forbidden.) So, s(ua) ∈ {0, 1} must hold. Since bv is a nonedge, bw and bx for all x ∈ X are also non-edges. If s(ub) ≥ 2 then branching on ub results in branching vector (2, 1), as vub is a conﬂict triple. Now, one can easily see that no optimal solution can bisect v, w, a, X : For X = ∅ a bisection of vertices v, w, a costs at least 3, and for X = ∅ costs are at least 4. Given a solution that bisects v, w, a, X , we modify the solution by putting u, v, w, a, X in a separate clique, with cost at most 1 for inserting ua, and cost 1 for removing ub. Clearly, this new solution has smaller total cost than the initial solution, so the initial solution cannot be optimal. Hence, we can merge v, w, a, X without branching, generating cost of at least 12 for destroying the zero-edge uw. 3. Assume a, b ∈ / X, so ua and ub are edges. Then, va and vb are non-edges, since no zero-edges can be incident to v. Similar to above, this implies that wa and wb, as well as ax and bx for all x ∈ X , are non-edges, too: Otherwise, we can branch on vw or wx. If s(ua) ≥ 2 then branching on uv results in branching vector (1, 2). So, we infer s(ua) = 1 and, by symmetry, s(ub) = 1. Now, merging uv into some vertex u results in a separated clique with

92

S. B¨ ocker

vertex set u , w, X that is not connected to the rest of the graph, and can be removed immediately. Hence, branching on uv leads to branching vector (1, 2) as we do not have put away 2 · 12 for potentially destroying zero-edges u a and u b later. We have shown that we can ﬁnd an edge that allows for the desired branching vectors, simplify the instance and reduce k without branching, or solve the remaining instance in constant time.

5

Solving Remainder Instances

Assume that there is no edge in the graph that is part of three or more (weak or strong) conﬂict triples. We transform our weighted graph into an unweighted counterpart Gu , where zero-edges are counted as non-existing. This graph Gu is called the type graph of the weighted graph. Then, there is no edge uv in the unweighted graph Gu that is part of three conﬂict triples. Damaschke [6] characterizes such graphs: Let Pn , Cn , Kn be the chordless path, cycle, and clique on n vertices, respectively. Let G + H denote the disjoint union of two graphs, and let p · G denote p disjoint copies of G. Let G ∗ H be the graph G + H where, in addition, every vertex from G is adjacent to every vertex from H. Finally, the graph Gc has the same vertex set as G, and {u, v} is an edge of Gc if and only if it is no edge of G. Now, Theorem 2 from [6] states: Lemma 4. Let G be a connected, unweighted graph such that no edge is part of three or more conflict triples. Then, G has at most six vertices, is a clique, a path, a cycle, or a graph of type Kq ∗H for q ≥ 0 and H ∈ {K1 +K1 , C5 , P4 , K1 + K1 + K1 , K2 + K2 , K2 + K1 , (p · K2 )c }, p ≥ 2. In fact, the characterization in [6] is slightly more complicated: To this end, note that Kq ∗ P3 = Kq+1 ∗ (K1 + K1 ). Any non-edge in the type graph can be a non-edge or zero-edge in the weighted graph, and edges and non-edges can be arbitrarily weighted. We now show that we can eﬃciently solve all remaining, “simple” instances. This is similar to our argumentation in [3] but as we want to reach branching vector (2, 1), our argumentation is slightly more involved. We defer the proof of Lemma 5 to the full version of this paper. Lemma 5. Let G be a connected graph that has the parity property. Assume that there is no edge that is part of three conflict triples. Then, we can find an edge with branching number ϕ; reduce k without branching; or, we can solve the instance in polynomial time.

6

A Golden Ratio Base for Search Tree Size

Assume that G has the parity property. We want to show that we can either ﬁnd an edge to branch on with branching number ϕ; decrease k without branching; or, solve the remaining instance in polynomial time. If there is an edge uv that

A Golden Ratio Parameterized Algorithm for Cluster Editing

93

is part of at least three (weak or strong) conﬂict triples, we branch on this edge. By Lemma 3, doing so results in branching number ϕ, or we reduce k without branching, as desired. We can ﬁnd an edge to branch on, in time O(n3 ). Similarly, we can perform all other tasks required for one step of the branching, in this time. If there is no edge uv that is part of at least three conﬂict triples, then Lemma 5 guarantees that we can branch with branching number ϕ; reduce k without branching; or, solve the instance in polynomial time. To compute minimum s-tcuts as part of Lemma 5, we use the Goldberg-Tarjan algorithm [8] to compute a maximum s-t-ﬂow in time O(n3 ), independent of edge weights. We reach: Lemma 6. Given an integer-weighted instance of the Cluster Editing problem with no zero-edges that satisfies the parity property, this instance can be solved in O(ϕk · n3 ) time. We can combine this with the weighted kernel from [4] of size O(k) with running time O(n2 ), resulting in running time O(ϕk · k 3 + n2 ). To get rid of the multiplicative polynomial factor, we use interleaving [16]: Here, a small trick is required to make this kernel work with instances that may contain zero-edges; we defer the details to the full paper. Theorem 1. Given an integer-weighted instance of the Cluster Editing problem with no zero-edges that satisfies the parity property, this instance can be solved in O(ϕk + n2 ) time. Given an unweighted Cluster Editing instance, we ﬁrst identify all critical cliques in time O(m + n) for a graph with n vertices and m edges [12], and merge the vertices of each critical clique [1, 11]. The resulting integer-weighted instance has O(k) vertices and no zero-edges, and satisﬁes the parity property. Using Theorem 1 we reach: Theorem 2. Cluster Editing can be solved in O(1.62k + k 2 + m + n) time.

7

Conclusion

We have presented a parameterized algorithm for the Cluster Editing problem, that ﬁnally reaches the golden ratio as the base for the exponential growth of the running time. It is noticeable that search tree approaches plus additional structural observations still have a lot of potential to yield better FPT algorithms for well-known problems, even without extensive case handling. Note that the underlying edge branching is also very swift in practice, and can usually process instances with thousands of edge modiﬁcations in a matter of minutes [2]. √ The base ϕ = 1+2 5 = 1.61803 . . . , resulting from branching vector (2, 1), appears repeatedly in the analysis of advanced algorithms for the problem [1,3].

94

S. B¨ ocker

Hence, it is an interesting question for the future if we can get beyond the O∗ (ϕk ) barrier. One possible extension lies in the split-oﬀ technique introduced in [3] for Cluster Deletion, even though it cannot be directly applied, as branching on a C4 results in branching vector (1, 1) for Cluster Editing. Improving upon the running time should not be problematic for the rather technical Lemma 5, though. Here, the open question is, which of these special cases are tractable (such as H = K1 + K1 ) and which are intractable (such as H = K1 + K1 + K1 ), and what FPT algorithms can be derived for the hard ones.

References 1. B¨ ocker, S., Briesemeister, S., Bui, Q.B.A., Truss, A.: Going weighted: Parameterized algorithms for cluster editing. Theor. Comput. Sci. 410(52), 5467–5480 (2009) 2. B¨ ocker, S., Briesemeister, S., Klau, G.W.: Exact algorithms for cluster editing: Evaluation and experiments. Algorithmica 60(2), 316–334 (2011) 3. B¨ ocker, S., Damaschke, P.: Even faster parameterized cluster deletion and cluster editing. Inform. Process. Lett. 111(14), 717–721 (2011) 4. Cao, Y., Chen, J.: Cluster Editing: Kernelization Based on Edge Cuts. In: Raman, V., Saurabh, S. (eds.) IPEC 2010. LNCS, vol. 6478, pp. 60–71. Springer, Heidelberg (2010) 5. Chen, J., Meng, J.: A 2k Kernel for the Cluster Editing Problem. In: Thai, M.T., Sahni, S. (eds.) COCOON 2010. LNCS, vol. 6196, pp. 459–468. Springer, Heidelberg (2010) 6. Damaschke, P.: Bounded-Degree Techniques Accelerate Some Parameterized Graph Algorithms. In: Chen, J., Fomin, F.V. (eds.) IWPEC 2009. LNCS, vol. 5917, pp. 98–109. Springer, Heidelberg (2009) 7. Downey, R.G., Fellows, M.R.: Parameterized Complexity. Springer, Heidelberg (1999) 8. Goldberg, A.V., Tarjan, R.E.: A new approach to the maximum-ﬂow problem. J. ACM 35(4), 921–940 (1988) 9. Gramm, J., Guo, J., H¨ uﬀner, F., Niedermeier, R.: Automated generation of search tree algorithms for hard graph modiﬁcation problems. Algorithmica 39(4), 321–347 (2004) 10. Gramm, J., Guo, J., H¨ uﬀner, F., Niedermeier, R.: Graph-modeled data clustering: Fixed-parameter algorithms for clique generation. Theor. Comput. Syst. 38(4), 373–392 (2005) 11. Guo, J.: A more eﬀective linear kernelization for cluster editing. Theor. Comput. Sci. 410(8-10), 718–726 (2009) 12. Hsu, W.-L., Ma, T.-H.: Substitution Decomposition on Chordal Graphs and Applications. In: Hsu, W.-L., Lee, R.C.T. (eds.) ISA 1991. LNCS, vol. 557, pp. 52–60. Springer, Heidelberg (1991) 13. Kˇriv´ anek, M., Mor´ avek, J.: NP-hard problems in hierarchical-tree clustering. Acta. Inform. 23(3), 311–323 (1986) 14. Marx, D., Razgon, I.: Fixed-parameter tractability of multicut parameterized by the size of the cutset. In: Proc. of ACM Symposium on Theory of Computing, STOC 2011, pp. 469–478. ACM (2011), doi:10.1145/1993636.1993699

A Golden Ratio Parameterized Algorithm for Cluster Editing

95

15. Niedermeier, R.: Invitation to Fixed-Parameter Algorithms. Oxford University Press (2006) 16. Niedermeier, R., Rossmanith, P.: A general method to speed up ﬁxed-parametertractable algorithms. Inform. Process. Lett. 73, 125–129 (2000) 17. Rosamond, F. (ed.): FPT News: The Parameterized Complexity Newsletter (Since 2005), http://fpt.wikidot.com/ 18. Wittkop, T., Emig, D., Lange, S., Rahmann, S., Albrecht, M., Morris, J.H., B¨ ocker, S., Stoye, J., Baumbach, J.: Partitioning biological data with transitivity clustering. Nat. Methods 7(6), 419–420 (2010)

Stable Sets of Threshold-Based Cascades on the Erd˝ os-R´ enyi Random Graphs Ching-Lueh Chang1, and Yuh-Dauh Lyuu2,3, 1

2

Department of Computer Science and Engineering, Yuan Ze University, Taoyuan, Taiwan clchang@saturn.yzu.edu.tw Department of Computer Science and Information Engineering, National Taiwan University, Taipei, Taiwan lyuu@csie.ntu.edu.tw 3 Department of Finance, National Taiwan University, Taipei, Taiwan

Abstract. Consider the following reversible cascade on the Erd˝ os-R´enyi random graph G(n, p). In round zero, a set of vertices, called the seeds, are active. For a given ρ ∈ ( 0, 1 ], a non-isolated vertex is activated (resp., deactivated) in round t ∈ Z+ if the fraction f of its neighboring vertices that were active in round t − 1 satisﬁes f ≥ ρ (resp., f < ρ). An irreversible cascade is deﬁned similarly except that active vertices cannot be deactivated. A set of vertices, S, is said to be stable if no vertex will ever change its state, from active to inactive or vice versa, once the set of active vertices equals S. For both the reversible and the irreversible cascades, we show that for any constant > 0, all p ∈ [ (1 + ) (ln (e/ρ))/n, 1 ] and with probability 1 − n−Ω(1) , every stable set of G(n, p) has size O(ρn) or n − O(ρn).

1

Introduction

Let G(V, E) be a simple undirected graph and ρ ∈ ( 0, 1 ], where each vertex of G can be in one of two states, active or inactive. Consider the following process, called the reversible cascade. In round zero, only a set of vertices, called the seeds, are active. Thereafter, a non-isolated vertex is activated (resp., deactivated) in a round if the fraction f of its neighboring vertices that were active in the previous round satisﬁes f ≥ ρ (resp., f < ρ). A set S ⊆ V is said to be stable for the reversible cascade if no vertex will ever change its state once the set of active vertices equals S. The irreversible cascade and its stable sets are deﬁned similarly except that the deactivations of vertices are prohibited. To model socio-economic contagion amongst fully rational individuals, Morris [32] considers a countably inﬁnite population in which each player has two

Supported in part by the National Science Council of Taiwan under grant 99-2218E-155-014-MY2. Supported in part by the National Science Council of Taiwan under grant 97-2221-E002-096-MY3 and Excellent Research Projects of National Taiwan University under grant 98R0062-05.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 96–105, 2011. c Springer-Verlag Berlin Heidelberg 2011

Stable Sets of Threshold-Based Cascades

97

strategies and a ﬁnite set of neighbors. In each round, a player chooses strategy 1 if and only if at least a ρ ∈ ( 0, 1 ] fraction of its neighbors do likewise in the previous round. So the resulting model is the same as our reversible cascade except that G(V, E) is now an inﬁnite graph with ﬁnite degrees. Deﬁne the contagion threshold to be the largest ρ such that there exists a ﬁnite set of players whose initial choice of strategy 1 eventually leads all players to strategy 1. Morris proves several characterizations of the contagion threshold and an 1/2 upper bound on it. For variants with partially rational players whose states are updated at random times governed by a Poisson process, much research studies the expected waiting time until everyone or almost everyone enters the same state [7, 14, 28, 43]. Consensus formation and periodic behavior are important aspects of the reversible cascade with ρ = 1/2 [34, 36, 44]. No matter what vertices are chosen as seeds, the set of active vertices in a simple undirected graph will eventually (1) stabilize or (2) coincide with one subset of V in even-numbered rounds and another subset in odd-numbered rounds [20, 21]. More general discrete-time dynamical systems also exhibit similar behavior [19, 29–31, 38, 39]. The reversible cascade with ρ = 1/2 as well as its slight variants also model the propagation of transient faults in majority-based fault-tolerant systems [17, 18, 35] and the evolution of host-pathogen systems [2–4, 22]. Flocchini et al. [17, 18] and Peleg [35] study the minimum number of seeds guaranteeing that (1) all vertices will be active after a ﬁnite number of rounds and (2) no active vertices will ever be deactivated in any round. For any simple undirected graph G(V, E), Peleg [35] shows that Ω( | V | ) seeds are needed for activating all vertices in two rounds. Berger [6] constructs a graph family for which a constant number of seeds can activate all vertices after a ﬁnite number of rounds. Agur et al. [2, 4] and Granville [22] derive exact formulas for the number of stable sets of a ring. They also count the number of cyclic binary strings with arbitrary restrictions on the numbers of consecutive 0’s and 1’s. For a survey of the above results, see [36]. Next, we turn to irreversible cascades. Luccio et al. [26] and Flocchini et al. [16–18] assume that each vertex is activated when the majority of its neighboring vertices are active, where the majority may assume the strict or the simple form. Their setup is suitable for modeling the propagation of permanent faults in majority-based fault-tolerant systems [15–18, 26, 36]. Bounds have been derived on the minimum number of seeds that can activate all vertices after a ﬁnite number of rounds for rings [16, 17], complete trees, butterﬂies, cube-connected cycles, shuﬄe-exchange graphs, DeBruijn graphs, hypercubes [16, 17, 26], tori [13, 18, 24, 25, 37], Erd˝os-R´enyi random graphs [9, 11] or directed graphs without source vertices [1, 9, 10]. Bootstrap percolation analyzes the density of independently chosen seeds needed to activate all vertices at the end with high probability [5, 41]. Computational issues regarding irreversible cascades have also been studied. In particular, eﬃcient algorithms are known for the problem of ﬁnding a minimum set of seeds activating all vertices after a ﬁnite number of rounds in a

98

C.-L. Chang and Y.-D. Lyuu

tree [13, 40], cycle, complete graph and bipartite complete graph [40]. In contrast, many hardness results are known for the same problem and its variants in general graphs [12, 23, 24, 40]. For both the reversible and the irreversible cascades, this paper proves that for any constant > 0, all p ∈ [ (1 + ) (ln (e/ρ))/n, 1] and with probability 1 − n−Ω(1) , every stable set of G(n, p) has size O(ρn) or n − O(ρn). With ρ → 0+ , therefore, any stable set of G(n, p) occupies either an o(1) or a 1 − o(1) fraction of all vertices.

2

Definitions

Let G(V, E) be a simple undirected graph [42]. For X, Y ⊆ V, deﬁne e(X, Y ) to be the number of edges with one endpoint in X and the other in Y . For a positive integer n and a real number p ∈ [ 0, 1 ], the Erd˝os-R´enyi random graph G(n, p) is a simple undirected graph with vertices 1, 2, . . . , n where each of the possible n2 edges appears independently with probability p [8]. For each v ∈ {1, 2, . . . , n}, deﬁne N (v) ⊆ [ n ] \ {v} to be the set of neighbors of v and deg(v) ≡ | N (v) |. For convenience, deﬁne [ n ] ≡ {1, 2, . . . , n}. Furthermore, deﬁne 2[ n ] to be the power set of [ n ], i.e., the set of all subsets of [ n ]. Consider the following reversible cascade on the Erd˝ os-R´enyi random graph G(n, p) whose vertices have two possible states, active or inactive. In round zero, only a set of vertices, called the seeds, are active. For a given ρ ∈ ( 0, 1 ], a nonisolated vertex is activated (resp., deactivated) in round t ∈ Z+ if the fraction f of its neighboring vertices that were active in round t − 1 satisﬁes f ≥ ρ (resp., f < ρ). More precisely, a vertex with degree d > 0 is activated (resp., deactivated) in a round if at least (resp., less than) ρd of its neighboring vertices are active in the previous round. The irreversible cascade is deﬁned similarly except that deactivations of vertices are prohibited. Deﬁne σρrev : 2[ n ] → 2[ n ] to map the set of active vertices in a round to that in the next round, assuming the reversible cascade. Then deﬁne σρirr : 2[ n ] → 2[ n ] similarly for the irreversible cascade. A set S ⊆ [ n ] is said to be stable for the reversible (resp., irreversible) cascade if σρrev (S) = S (resp., σρirr (S) = S). So a reversible or irreversible cascade stops evolving precisely when its set of active vertices is stable. Below is a straightforward lemma. Lemma 1. For a simple undirected graph G(V, E) and all disjoint A, B ⊆ V, e (A, A ∪ B) ≥

| N (v) ∩ (A ∪ B) | . 2

v∈A

Proof. Each edge with an endpoint in A and the other in B \ A contributes 1 to both e(A, A ∪ B) and v∈A | N (v) ∩ (A ∪ B) |. Each edge with both endpoints in A contributes 1 to e(A, A ∪ B) and 2 to v∈A | N (v) ∩ (A ∪ B) |.

Stable Sets of Threshold-Based Cascades

3

99

Stable Sets of the Erd˝ os-R´ enyi Random Graphs

This section shows that for any constant > 0, all p ∈ [ (1 + ) (ln (e/ρ))/n, 1], ρ ∈ ( 0, 1 ] and with probability 1 − n−Ω(1) , every stable set of G(n, p) has size O(ρn) or n − O(ρn). Lemma 2. Let n ∈ Z+ , p ∈ [ 0, 1 ] and ρ ∈ ( 0, 1 ]. Then n Pr [ | {v ∈ [ n ] | deg(v) > 30pn} | ≥ ρn ] < 2−15pnρn , ρn where the probability is taken over the random graphs G(n, p). Proof. In the proof, all probabilities are taken over the random graphs G(n, p). Clearly, Pr [ | {v ∈ [ n ] | deg(v) > 30pn} | ≥ ρn ] = Pr [ ∃X ⊆ [ n ], | X | = ρn, ∀v ∈ X, deg(v) > 30pn ] ≤ Pr [ ∀v ∈ X, deg(v) > 30pn ] .

(1)

X⊆[ n ],| X |=ρn

Now ﬁx an arbitrary X ⊆ [ n ] with size ρn. If deg(v) > 30pn for all v ∈ X, then Lemma 1 implies e(X, [ n ]) > 15pn | X |. Hence Pr [ ∀v ∈ X, deg(v) > 30pn ] ≤ Pr [ e (X, [ n ]) > 15pn | X | ] < 2−15pnρn , where the last inequality follows from Chernoﬀ’s bound [33, Exercise 4.1]. This and inequality (1) complete the proof. Lemma 3. For any n ∈ Z+ , p ∈ [ 0, 1 ], ρ ∈ [ 1/n, 1 ], ξ ∈ Z+ with ξ > 30 and η ≡ 1 − (30/ξ), Pr [∃X, U ⊆ [n], |X| = ρn, ξρn ≤ |U| ≤ n − ξρn, ∀v ∈ [n] \ (U ∪ X) , |N (v) ∩ U| ≤ 30ρpn]

n/2 e en e−η ≤2 exp 2ρn ln + s ln + ηps(n − s) ln , ρ s (1 − η)1−η s=ξρn

where the probability is taken over the random graphs G(n, p). Proof. In the proof, all probabilities are taken over the random graphs G(n, p). For any X, U ⊆ [ n ] with | U | ≥ ξρn and each u ∈ [ n ] \ (U ∪ X), Pr [ | N (u) ∩ U | ≤ 30ρpn ] ≤ Pr [ | N (u) ∩ U | ≤ (1 − η) · E [ | N (u) ∩ U | ] ] p | U | e−η ≤ (1 − η)1−η

100

C.-L. Chang and Y.-D. Lyuu

by Chernoﬀ’s bound [27, Theorem 4.5]; hence, as the random variables | N (v) ∩ U | for v ∈ [ n ] \ (U ∪ X) are independent, p|U|(n−|U∪X|) e−η Pr [∀v ∈ [n] \ (U ∪ X) , |N (v) ∩ U | ≤ 30ρpn] ≤ . (2) (1 − η)1−η If, furthermore, | X | = ρn and | U | ≤ n − ξρn, then p | U | (n−| U∪X |) η p | U | (n−| U |) e−η e−η ≤ (1 − η)1−η (1 − η)1−η

(3)

by the easily veriﬁable fact that n − | U ∪ X | ≥ η (n − | U |). Now, ≤

Pr [∃X, U ⊆ [n], |X| = ρn, ξρn ≤ |U | ≤ n − ξρn, ∀v ∈ [n] \ (U ∪ X) , |N(v) ∩ U| ≤ 30ρpn] Pr [ ∀v ∈ [ n ] \ (U ∪ X) , | N (v) ∩ U | ≤ 30ρpn ] X⊆[ n ],| X |=ρn U ⊆[ n ],ξρn≤| U |≤n−ξρn

≤

X⊆[ n ],| X |=ρn U ⊆[ n ],ξρn≤| U |≤n−ξρn

≤

n ρn

U⊆[ n ],ξρn≤| U |≤n−ξρn

e−η (1 − η)1−η

e−η (1 − η)1−η

η p | U | (n−| U |)

η p | U | (n−| U |) ,

(4)

where the second inequality follows from inequalities (2)–(3). Furthermore, η p | U | (n−| U |) e−η (1 − η)1−η U ⊆[ n ],ξρn≤| U |≤n−ξρn

n−ξρn

=

s=ξρn U⊆[ n ], | U |=s n/2

≤2

s=ξρn n/2

≤2

s=ξρn

e−η (1 − η)1−η

ηps(n−s)

ηps(n−s) n e−η s (1 − η)1−η

(5)

en e−η exp s ln + ηps(n − s) ln , s (1 − η)1−η

(6)

where inequality (5) follows from ities (4)–(6) complete the proof.

n s

=

n n−s

and s (n − s) = (n − s) s. Inequal

Theorem 4. Let > 0. Then there exists an integer ξ > 30 such that for any n ∈ Z+ , ρ ∈ [ 1/n, 1/ξ 2 ), p ∈ [ (1 + ) (ln (e/ρ))/n, 1 ], σG : 2[ n ] → 2[ n ] satisfying ∀U ⊆ [ n ], {v ∈ [ n ] | | NG (v) ∩ U | > ρ degG (v)} ⊆ σG (U )

(7)

for each simple undirected graph G with vertex set [ n ], and writing σ ≡ σG(n,p) , Pr [ ∃U ⊆ [ n ], ξρn ≤ | U | ≤ n − ξρn, σ(U ) ⊆ U ] = n−Ω(1) ,

(8)

where the probability is taken over over the random graphs G(n, p). The hidden constants in the Ω notations are independent of n, p, ρ, and ξ.

Stable Sets of Threshold-Based Cascades

101

Proof. We will leave ξ to be determined later; before that we only need ξ > 30 in the derivation. Deﬁne η ≡ 1 − (30/ξ). As p ∈ [ (1 + ) (ln (e/ρ))/n, 1 ], en e−η exp s ln + ηps(n − s) ln s (1 − η)1−η en e s e−η ≤ exp s ln + η (1 + ) ln s 1− ln , (9) s ρ n (1 − η)1−η s ∈ ( 0, n ]. Deﬁne

en e s e−η g(s, n, ρ) ≡ s ln + η (1 + ) ln s 1− ln . s ρ n (1 − η)1−η

(10)

Elementary calculus and laborious calculations reveal the following properties of g(s, n, ρ): – g(ξρn, n, ρ) ≤ −4ρn ln(e/ρ) provided that ρ ∈ (0, 1/ξ 2 ) and 1 e−η ξ 1 + η (1 + ) 1 − ln < −4; ξ (1 − η)1−η – ∂g(s, n, ρ)/∂s < 0 for s ∈ [ ξρn, n/(4 + 4) ] provided that e−η 1 + η (1 + ) 1 − ln < 0; 2 + 2 (1 − η)1−η

(11)

(12)

– g(s, n, ρ) ≤ −3n for s ∈ [ n/(4 + 4), n/2 ] provided that ρ ∈ (0, 1/ξ 2 ) and 1 ln 2

2 e(4 + 4) e−η +η (1+) ln eξ 1− ln < −3. (13) 4+4 4+4 (1 − η)1−η

By elementary calculus and η = 1 − (30/ξ), lim ln

ξ→∞

e−η = −1. (1 − η)1−η

Therefore, with laborious calculations, inequalities (11)–(13) hold in the limit as ξ → ∞. Hence there exists a real number C() > 30, depending only on , such that inequalities (11)–(13) hold for ξ ≥ C(). From now on, we assume that ξ ≥ C() and ρ ∈ [ 1/n, 1/ξ 2 ). So the derived properties on g(s, n, ρ) give

e max g(s, n, ρ) ≤ max −4ρn ln , −3n . (14) ρ s∈[ ξρn,n/2 ] By Lemma 3 and inequalities (9)–(10) and (14), Pr [∃X, U ⊆ [n], |X| = ρn, ξρn ≤ |U | ≤ n − ξρn, ∀v ∈ [n] \ (U ∪ X) , |N(v) ∩ U| ≤ 30ρpn]

n/2 e e ≤2 exp max −2ρn ln , −3n + 2ρn ln ρ ρ s=ξρn 1 =O . (15) n

102

C.-L. Chang and Y.-D. Lyuu

Let Y ≡ {v ∈ [ n ] | deg(v) > 30pn} be the set of vertices with degrees greater than 30pn. By Lemma 2, n Pr [ | Y | ≥ ρn ] ≤ 2−15pnρn = n−Ω(1) . ρn

(16)

For any U ⊆ [ n ] with σ(U ) ⊆ U and v ∈ [ n ] \ U, | N (v) ∩ U | ≤ ρ deg(v) by relation (7); if, furthermore, v ∈ / Y, then | N (v) ∩ U | ≤ 30ρpn.

(17)

Therefore, Pr [(| Y | < ρn) ∧ (∃U ⊆ [ n ], ξρn ≤ | U | ≤ n − ξρn, σ(U ) ⊆ U) ] ≤ Pr [(|Y | < ρn) ∧ (∃U ⊆ [n], ξρn ≤ |U| ≤ n − ξρn, ∀v ∈ [n] \ (U ∪ Y ) , |N (v) ∩ U| ≤ 30ρpn)] 1 ≤O , (18) n

where the last inequality follows from inequality (15). Summing up inequalities (16) and (18) proves Eq. (8). As a remark, in Theorem 4, σG is nonrandom for each undirected graph G(V, E), whereas σG(n,p) depends on the underlying random graph G(n, p). As ξ depends only on in Theorem 4, we may take ξρn = O(ρn) in Eq. (8) when > 0 is a constant, as done below. Theorem 5. Let > 0 be a constant, n ∈ Z+ , ρ ∈ ( 0, 1 ] and p ∈ [ (1 + ) (ln (e/ρ))/n, 1 ]. Assume that σG : 2[ n ] → 2[ n ] satisfies relation (7) for each simple undirected graph G with vertex set [ n ]. Then, writing σ ≡ σG(n,p) , −Ω(1)

Pr [ ∀S ⊆ [ n ], (σ(S) = S) ⇒ (| S | = O (ρn)) ∨ (| S | = n − O (ρn)) ] = 1 − n

,

(19)

where the probability is taken over the random graphs G(n, p). The hidden constants in the O and Ω notations are independent of n, p, ρ and S. Proof. Assume without loss of generality that ρ ≥ 1/n. Let ξ be as in Theorem 4, which is a constant because is now a constant. The case of ρ ∈ [ 1/n, 1/ξ 2 ) is an immediate consequence of Theorem 4. For the case of ρ ≥ 1/ξ 2 = Ω(1), Eq. (19) trivially holds. We now have the following corollary on the stable sets for the reversible and the irreversible cascades. Corollary 6. Let > 0 be a constant. For any n ∈ Z+ , ρ ∈ ( 0, 1 ], p ∈ [ (1 + ) (ln (e/ρ))/n, 1 ] and with probabilities taken over the random graphs G(n, p), Pr [ every stable set of G(n, p) has size O (ρn) or n − O (ρn) ] = 1 − n−Ω(1) (20)

for both the reversible and the irreversible cascades. The hidden constants in the O and Ω notations are independent of n, p and ρ.

Stable Sets of Threshold-Based Cascades

103

Proof. Immediate from Theorem 5 and the fact that relation (7) holds with σ ∈ {σρrev , σρirr }. For the irreversible cascades on G(n, p) with p ∈ [ (1 + ) (ln (e/ρ))/n, 1 ], Corollary 6 implies the following polynomial-time algorithm for ﬁnding with probability 1 − o(1) a set of O(ρn) seeds activating all vertices at the end: First, pick a set S of Cρn seeds arbitrarily, where C > 0 is a suﬃciently large constant. Second, pick all the vertices in [ n ] \ σρirr (S) also as seeds. The number of seeds thus picked is O(ρn) with probability 1 − o(1) because, by Corollary 6, an irreversible cascade with Cρn seeds cannot stop activating vertices until at least n − Cρn vertices are activated. It is asymptotically optimal for p ∈ [ β (ln(e/ρ))/(ρn), 1 ], where β > 0 is a suﬃciently large constant [11]. We note that results of Ackerman et al. [1] can also be used to show the existence of O(ρn) seeds activating all vertices at the end for the irreversible cascades with p ∈ [ (1 + ) (ln (e/ρ))/n, 1 ]. The next theorem shows that the range p ∈ [ (1 + ) (ln (e/ρ))/n, 1 ] in Corollary 6 cannot be widened to p ∈ [ (1 − ) (ln (e/ρ))/n, 1 ]. The proof follows a standard analysis on the number of isolated vertices of the Erd˝ os-R´enyi random graphs. Theorem 7. Let ∈ (0, 1) be a constant. For any n ∈ Z+ , ρ ∈ [ 1/n, 1 ], p ∈ [ 0, (1 − ) (ln (e/ρ))/n ] and with probabilities taken over the random graphs G(n, p), Pr G(n, p) has stable sets of sizes Ω ρ1−/2 n and n − Ω ρ1−/2 n = 1 − o(1)

for both the reversible and the irreversible cascades. The hidden constants in the Ω notations are independent of p. Proof. It is implicit in [42, Theorem 8.5.22] that for p ∈ [ 0, (1 − ) (ln (e/ρ))/n ], the number of isolated vertices of G(n, p) is Ω ρ1−/2 n with probability 1−o(1). The theorem follows because both the set of isolated vertices and that of nonisolated vertices are stable for either the reversible or the irreversible cascade.

References [1] Ackerman, E., Ben-Zwi, O., Wolfovitz, G.: Combinatorial model and bounds for target set selection. Theoretical Computer Science (forthcoming 2010), doi:10.1016/j.tcs.2010.08.021 [2] Agur, Z.: Resilience and variability in pathogens and hosts. IMA Journal on Mathematical Medicine and Biology 4(4), 295–307 (1987) [3] Agur, Z.: Fixed points of majority rule cellular automata with application to plasticity and precision of the immune system. Complex Systems 5(3), 351–357 (1991) [4] Agur, Z., Fraenkel, A.S., Klein, S.T.: The number of ﬁxed points of the majority rule. Discrete Mathematics 70(3), 295–302 (1988) [5] Balogh, J., Bollob´ as, B., Morris, R.: Bootstrap percolation in high dimensions. Combinatorics, Probability and Computing 19(5-6), 643–692 (2010)

104

C.-L. Chang and Y.-D. Lyuu

[6] Berger, E.: Dynamic monopolies of constant size. Journal of Combinatorial Theory Series B 83(2), 191–200 (2001) [7] Blume, L.E.: The statistical mechanics of strategic interaction. Games and Economic Behavior 5(3), 387–424 (1993) [8] Bollob´ as, B.: Random Graphs, 2nd edn. Cambridge University Press (2001) [9] Chang, C.-L., Lyuu, Y.-D.: Spreading messages. Theoretical Computer Science 410(27-29), 2714–2724 (2009) [10] Chang, C.-L., Lyuu, Y.-D.: Bounding the Number of Tolerable Faults in MajorityBased Systems. In: Calamoneri, T., Diaz, J. (eds.) CIAC 2010. LNCS, vol. 6078, pp. 109–119. Springer, Heidelberg (2010) [11] Chang, C.-L., Lyuu, Y.-D.: Spreading of messages in random graphs. Theory of Computing Systems 48(2), 389–401 (2011) [12] Chen, N.: On the approximability of inﬂuence in social networks. In: Proceedings of the 19th Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 1029– 1037 (2008) [13] Dreyer, P.A., Roberts, F.S.: Irreversible k-threshold processes: Graph-theoretical threshold models of the spread of disease and of opinion. Discrete Applied Mathematics 157(7), 1615–1627 (2009) [14] Ellison, G.: Learning, local interaction, and coordination. Econometrica 61(5), 1047–1071 (1993) [15] Flocchini, P.: Contamination and decontamination in majority-based systems. Journal of Cellular Automata 4(3), 183–200 (2009) [16] Flocchini, P., Geurts, F., Santoro, N.: Optimal irreversible dynamos in chordal rings. Discrete Applied Mathematics 113(1), 23–42 (2001) [17] Flocchini, P., Kr´ aloviˇc, R., Ruˇziˇcka, P., Roncato, A., Santoro, N.: On time versus size for monotone dynamic monopolies in regular topologies. Journal of Discrete Algorithms 1(2), 129–150 (2003) [18] Flocchini, P., Lodi, E., Luccio, F., Pagli, L., Santoro, N.: Dynamic monopolies in tori. Discrete Applied Mathematics 137(2), 197–212 (2004) [19] Ginosar, Y., Holzman, R.: The majority action on inﬁnite graphs: Strings and puppets. Discrete Mathematics 215(1-3), 59–71 (2000) [20] Goles, E., Olivos, J.: Periodic behavior of generalized threshold functions. Discrete Mathematics 30(2), 187–189 (1980) [21] Goles-Chacc, E., Fogelman-Soulie, F., Pellegrin, D.: Decreasing energy functions as a tool for studying threshold networks. Discrete Applied Mathematics 12(3), 261–277 (1985) [22] Granville, A.: On a paper by Agur, Fraenkel and Klein. Discrete Mathematics 94(2), 147–151 (1991) ´ Maximizing the spread of inﬂuence through a [23] Kempe, D., Kleinberg, J., Tardos, E.: social network. In: Proceedings of the 9th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, pp. 137–146 (2003) [24] Kynˇcl, J., Lidick´ y, B., Vyskoˇcil, T.: Irreversible 2-conversion set is NP-complete. Technical Report KAM-DIMATIA Series 2009-933, Department of Applied Mathematics, Charles University, Prague, Czech Republic (2009) [25] Luccio, F.: Almost exact minimum feedback vertex set in meshes and butterﬂies. Information Processing Letters 66(2), 59–64 (1998) [26] Luccio, F., Pagli, L., Sanossian, H.: Irreversible dynamos in butterﬂies. In: Proceedings of the 6th International Colloquium on Structural Information and Communication Complexity, pp. 204–218 (1999)

Stable Sets of Threshold-Based Cascades

105

[27] Mitzenmacher, M., Upfal, E.: Probability and Computing: Randomized Algorithms and Probabilistic Analysis. Cambridge University Press (2005) [28] Montanari, A., Saberi, A.: Convergence to equilibrium in local interaction games. In: Proceedings of the 50th Annual IEEE Symposium on Foundations of Computer Science, pp. 303–312 (2009) [29] Moran, G.: Parametrization for stationary patterns of the r-majority operators on 0-1 sequences. Discrete Mathematics 132(1-3), 175–195 (1994) [30] Moran, G.: The r-majority vote action on 0-1 sequences. Discrete Mathematics 132(1-3), 145–174 (1994) [31] Moran, G.: On the period-two property of the majority operator in inﬁnite graphs. Transactions of the American Mathematical Society 347(5), 1649–1667 (1995) [32] Morris, S.: Contagion. Review of Economic Studies 67(1), 57–78 (2000) [33] Motwani, R., Raghavan, P.: Randomized Algorithms. Cambridge University Press (1995) [34] Mustafa, N.H., Pekec, A.: Majority Consensus and the Local Majority Rule. In: Yu, Y., Spirakis, P.G., van Leeuwen, J. (eds.) ICALP 2001. LNCS, vol. 2076, pp. 530–542. Springer, Heidelberg (2001) [35] Peleg, D.: Size bounds for dynamic monopolies. Discrete Applied Mathematics 86(2-3), 263–273 (1998) [36] Peleg, D.: Local majorities, coalitions and monopolies in graphs: A review. Theoretical Computer Science 282(2), 231–257 (2002) [37] Pike, D.A., Zou, Y.: Decycling Cartesian products of two cycles. SIAM Journal on Discrete Mathematics 19(3), 651–663 (2005) [38] Poljak, S., Sura, M.: On periodical behavior in societies with symmetric inﬂuences. Combinatorica 3(1), 119–121 (1983) [39] Poljak, S., Turzik, D.: On an application of convexity to discrete systems. Discrete Applied Mathematics 13(1), 27–32 (1986) [40] Reddy, T.V.T., Krishna, D.S., Rangan, C.P.: Variants of spreading messages. In: Proceedings of the 4th Workshop on Algorithms and Computation, pp. 240–251 (2010) [41] Stauﬀer, D., Aharony, A.: Introduction to Percolation Theory, 2nd edn. Taylor & Francis (1994) [42] West, D.B.: Introduction to Graph Theory, 3rd edn. Prentice-Hall, Upper Saddle River (2007) [43] Young, H.P.: The diﬀusion of innovations in social networks. In: Blume, L.E., Durlauf, S.N. (eds.) Economy as an Evolving Complex System. Proceedings Volume in the Santa Fe Institute Studies in the Sciences of Complexity, vol. 3, pp. 267–282. Oxford University Press, New York (2006) [44] Zollman, K.J.S.: Social structure and the eﬀects of conformity. Humanities, Social Sciences and Law 172(3), 317–340 (2008)

How Not to Characterize Planar-Emulable Graphs Markus Chimani1, , Martin Derka2, , Petr Hlinˇen´ y2, , and Matˇej Klus´ aˇcek2, 1

Algorithm Engineering, Friedrich-Schiller-University Jena, Germany markus.chimani@uni-jena.de 2 Faculty of Informatics, Masaryk University Brno, Czech Republic {hlineny,xderka,xklusac1}@fi.muni.cz

Abstract. We investigate the question of which graphs have planar emulators (a locally-surjective homomorphism from some finite planar graph)—a problem raised in Fellows’ thesis (1985) and conceptually related to the better known planar cover conjecture by Negami (1986). For over two decades, the planar emulator problem lived poorly in a shadow of Negami’s conjecture—which is still open—as the two were considered equivalent. But, in the end of 2008, a surprising construction by Rieck and Yamashita falsified the natural “planar emulator conjecture”, and thus opened a whole new research field. We present further results and constructions which show how far the planar-emulability concept is from planar-coverability, and that the traditional idea of likening it to projective embeddability is actually very out-of-place. We also present several positive partial characterizations of planar-emulable graphs.

1

Introduction

A graph G has a planar emulator (cover) H if H is a ﬁnite planar graph and there exists a homomorphism from H onto G that is locally surjective (bijective, respectively). In such a case we also say that G is planar-emulable (-coverable). See Def. 2.1 for a precise deﬁnition, and Fig. 1 for a simple example. Informally, every vertex of G is represented by one or more vertices in H such that the following holds: Whenever two nodes v and u are adjacent in G, any node representing v in H has at least one (in case of an emulator) or exactly one (in case of a cover) adjacent node in H that represents u. Conversely, no node representing v in H has a neighbor representing u if v, u are nonadjacent in G. Coarsely speaking, the mutually similar concepts of planar covers and planar emulators both “preserve” the local structure of a graph G while “gaining” planarity for it. Of course, the central question is which nonplanar graphs do have planar covers or emulators.

M. Chimani has been funded by a Carl-Zeiss-Foundation juniorprofessorship. M. Derka has been supported by Masaryk University internal grant for students. Supported by the Czech science foundation; grants P202/11/0196 and GIG/11/E023.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 106–120, 2011. c Springer-Verlag Berlin Heidelberg 2011

How Not to Characterize Planar-Emulable Graphs

a s

s

b2 s

b

s a2

c2 s s

c

b6 s

s

s

b1

c5

a3 s s c1

a1

s

s b5

b3 s c3

107

s c4 s

s s

b4

a4

Fig. 1. Examples of a planar cover (center) and a planar emulator (right) of the triangle G = K3 (left). We simply denote by aj , j = 1, 2, . . . the vertices representing a of G, and analogically with b, c.

The two concepts emerged independently from works of Fellows [5,6] (emulator) and Negami [16,17,18] (cover). On the one hand, the class of planar-coverable graphs is relatively well understood. At least, we have the following: Conjecture 1.1 (Negami [17], 1988). A graph has a (finite) planar cover if and only if it embeds in the projective plane. Yet, this natural (see below) and ﬁrmly believed conjecture is still open today despite of more than 20 years of intensive research. See [11] for a recent survey. On the other hand, it was no less natural to assume [5,6] that the property of being planar-emulable coincides with planar-coverability. By deﬁnition, the latter immediately implies the former. For the other direction, it was highly counterintuitive to assume that, having more than one neighbors in H representing the same adjacent vertex of G, could ever help to gain planarity of H —such “additional” edges seem to go against Euler’s bound on the number of edges of a planar graph. Hence, it was widely believed: Conjecture 1.2 (Fellows [6], 1988, falsified 2008). A graph has a (finite) planar emulator if and only if it embeds in the projective plane. Perhaps due to similarity to covers, no signiﬁcant eﬀort to speciﬁcally study planar-emulable graphs occurred during the next 20 years after Fellows’ manuscript [6]. Today, however, we know of one important diﬀerence between the two cases: Conjecture 1.2 is false! In 2008, Rieck and Yamashita [19] proved the truly unexpected breakthrough result that there are graphs which have planar emulators, but no planar covers and do not embed in the projective plane; see Theorem 2.4. This ﬁnding naturally ignited a new research direction, on which we report herein. We show that the class of planar-emulable graphs is, in fact, much larger than the class of planar-coverable ones; that the concept of projective embeddability seems very out-of-place in the context of planar emulators; and generally, how poorly planar emulators are yet understood. Apart from its pure graph theoretic appeal, research regarding planar emulators and covers may in fact have algorithmic consequences as well: While

108

M. Chimani et al. c2 s

s d2

ϕ(v1 ) = ϕ(v2 ) = v c s

G = K5

s

sd s

b s

v2

v z

sa

b2 ←− ϕ

s

s a2

d1 s

s c1 s

v1 a1

s

s b1

Fig. 2. The graph G = K5 (left) and its two-fold planar cover (right) via a homomorphism ϕ. The cover is obtained for a “crosscap-less” drawing of G and its mirror image.

Negami’s main interest [16] was of pure graph theoretic nature, Fellows [5, and personal communication] considered computing motivation for emulators. Additionally, we would like to sketch another potential algorithmic connection; there are problems that are NP-hard for general graphs, but polynomial-time solvable for planar graphs (e.g., maximum cut), or where the polynomial complexity drops when considering planar graphs (e.g., maximum ﬂow). Yet, the precise breaking point is usually not well understood. Considering such problems for planar-emulable or planar-coverable graphs may give more insight into the problems’ intrinsic complexities. Before this can be investigated, however, these classes ﬁrst have to be reasonably well understood themselves. Our paper aims at improving upon this latter aspect of planar emulators. This paper is organized as follows: Section 2 discusses all the major prior ﬁndings w.r.t. covers and emulators, including the aforementioned result by Rieck and Yamashita. Then, Theorem 2.5 presents our main new improvement. Section 3 reviews some necessary basic properties and tools, most of which have been previously sketched in [6]. In Section 4 we give previously unknown emulator constructions, proving Theorem 2.5 and also showing how unrelated emulators are from covers. We would particularly like to mention a very small and nicely-structured emulator of the notoriously diﬃcult graph K1,2,2,2 in Fig. 8. Finally, in Section 5 we study how far one can get in the pursuit to characterize planar-emulable graphs with the structural tools previously used in [12] for covers, and where the current limits are. Due to space restrictions, many arguments and constructions have to be skipped in this paper, and we refer to the long preprint version [2] for the rest.

2

On Planar Covers and Emulators

We restate the problem on a more formal level. All considered graphs are simple, ﬁnite, and undirected. A projective plane is the simplest nonorientable surface— a plane with one crosscap (informally, a place in which a bunch of selected edges

How Not to Characterize Planar-Emulable Graphs

K3,3 · K3,3

D1

K5 · K3,3

D4

E 19

K3,5

K1,2,2,2

K5 · K5

D9

E 20

K4,5 −4K2

B7

B3

D 17

D 12

E 27

K4,4 −e

C3

C2

F4

K7 −C4

D3

C4

D2

109

C7

E6

E 11

F6

G1

E5

F1

E2

Fig. 3. The 32 connected projective forbidden minors. (The three disconnected ones, K5 + K5 , K5 + K3,3 , K3,3 + K3,3 , are skipped since they are not important here.)

of an embedded graph may “cross” each other). A graph homomorphism of H into G is a mapping h : V (H) → V (G) such that, for every edge {u, v} ∈ E(H), we have {h(u), h(v)} ∈ E(G). Definition 2.1. A graph G has a planar emulator (cover) H if H is a planar finite graph and there exists a graph homomorphism ϕ : V (H) → V (G) such that, for every vertex v ∈ V (H), the neighbors of v in H are mapped by ϕ surjectively (bijectively) onto the neighbors of ϕ(v) in G. The homomorphism ϕ is called an emulator (cover) projection. One immediately obtains the following two claims: Lemma 2.2. a) If H is a planar cover of G, then H is also a planar emulator of G. The converse is not true in general. b) If G embeds in the projective plane, then G has a two-fold planar cover (i.e., |ϕ−1 (u)| = 2 for all u ∈ V (G)); cf. [16]. See also Fig. 2. These two claims, together with some knowledge about universal coverings in topology, make Conjectures 1.1 and 1.2 sound very plausible. To precisely describe the motivation for our research direction in planar emulators, we brieﬂy comment on the methods that have been used in the investigation of planarcoverable graphs, too.

110

M. Chimani et al.

←

Fig. 4. A colour-coded 3D-rendering of a planar emulator patched on a polyhedral body (right) for the graph K4,5 − 4K2 (left), taken from http://vivaldi.ics.nara-wu.ac.jp /~yamasita/emulator/

Firstly, we note that the properties of planar-coverability and planar-emulability are closed under taking minors (Proposition 3.1), and all 35 minor-minimal nonprojective graphs (projective forbidden minors, Fig. 3) are known [1]. If a connected graph G is projective, then G is planar-coverable (and hence also planar-emulable); otherwise, G contains one of the mentioned projective forbidden minors. Hence to prove Conjecture 1.1, only a seemingly simple task remains: we have to show that the known 32 connected projective forbidden minors have no planar covers. The following was established through a series of previous papers: Theorem 2.3 (Archdeacon, Fellows, Hlinˇ en´ y, and Negami, 1988–98). If the (complete four-partite) graph K1,2,2,2 has no planar cover, then Conjecture 1.1 is true. One can naturally think about applying the same arguments to planar emulators, i.e. to Conjecture 1.2. The ﬁrst partial results of Fellows [6]—see an overview in Section 3—were, in fact, encouraging. Yet, all the more sophisticated tools (of structural and discharging ﬂavor) used to show the non-existence of planar covers in Theorem 2.3 fail on a rather technical level when applied to emulators. As these problems seemed to be more of technical than conceptual nature, Fellows’ conjecture was always believed to be true until the following: Theorem 2.4 (Rieck and Yamashita [19], 2008). The graphs K1,2,2,2 and K4,5 − 4K2 do have planar emulators (cf. Fig. 4). Consequently, the class of planar-emulable graphs is strictly larger than the class of planar-coverable graphs, and Conjecture 1.2 is false. We remark that this is not merely an existence result, but the actual (and, surprisingly, not so large) emulators were published together with it. Both K1,2,2,2 and K4,5 − 4K2 are among the projective forbidden minors, and K4,5 − 4K2 has already been proved not to have a planar cover. One important new message of our paper is that Theorem 2.4 is not a rarity— quite the opposite, many other nonprojective graphs have planar emulators. In

How Not to Characterize Planar-Emulable Graphs

111

particular we prove that, among the projective forbidden minors that have been in doubt since Fellows’ [6], all except possibly K4,4 − e do have planar emulators: Theorem 2.5. All of the graphs (Fig. 3) K4,5 − 4K2 , K1,2,2,2 , B7 , C3 , C4 , D2 , E2 , and also K7 − C4 , D3 , E5 , F1 have planar emulators. Consequently, the class of planar-emulable graphs is much larger than the class of planar-coverable ones. We refer to Section 4 for details.

3

Basic Properties of Emulators

In this section, we review the basic established properties of planar-emulable graphs. These are actually all the properties of planar-coverable graphs which are known to extend to planar emulators (though, the extensions of some of the proofs are not so straightforward). The claims presented here, except for Theorem 3.4, were proved or sketched already in the manuscript [6] of Fellows. However, since [6] has never been published, we consider it appropriate to include their full statements with proof sketches here (while the complete formal proofs can be found also in [2]). We begin with two crucial closure properties. Proposition 3.1 (Fellows [6]). The property of being planar-emulable is closed under taking minors; i.e., under taking subgraphs and edge contractions. Proposition 3.2 (Fellows [6]). The property of being planar-emulable is closed under applying YΔ-transformations; i.e., the operations replacing (successively) any degree-3 vertex with a triangle on its three neighbors. Next, we identify some basic forbidden minors for planar-emulable graphs among the known list of projective forbidden minors (cf. Lemma 2.2 b). These again extend folklore knowledge about planar-coverable graphs, but the arguments are deﬁnitely not trivial this time. Actually, the following two theorems represent all the current knowledge about non-planar-emulable graphs (besides the trivial cases of K7 and K4,4, for which the nonexistence of planar emulators is immediate from Euler’s formula). Theorem 3.3 (Fellows [6]). A planar-emulable graph cannot contain “two disjoint k-graphs” (see [2]). Consequently, each of the 19 graphs—projective forbidden minors—in the first three rows of Fig. 3 has no planar emulator. Theorem 3.4 (Fellows / Huneke [13]). The graph K3,5 has no planar emulator. In a remaining limited space we try to brieﬂy outline the two important technical tools used to prove Theorems 3.3 and 3.4. Lemma 3.5 particularly implies both Proposition 3.2 and Theorem 3.4 with simple arguments.

112

M. Chimani et al. y1 ∈ ϕ−1 (a)

y1 ∈ ϕ−1 (a) y2 ∈ ϕ−1 (b)

y2 ∈ ϕ

y3 ∈ ϕ−1 (a)

−1

(b)

y3 ∈ ϕ−1 (a) x

x2

x1 yi+1

yi−1

yi+1 yi−1

yi ∈ ϕ−1 (c)

yi ∈ ϕ−1 (c)

Fig. 5. Splitting vertex x with a cubic image in X into vertices of lower degree

Lemma 3.5 (Fellows [6]). Let G be a planar-emulable graph and X ⊆ V (G) an independent set of vertices of degree 3. Then there exists a planar emulator H of G with a projection ϕ : V (H) → V (G) such that every vertex u ∈ ϕ−1 (v) over all v ∈ X is of degree 3. Proof (sketch). Whenever F is an emulator of our graph G with a projection ψ : V (F ) → V (G); let Dg(F ) (≥ 3) shortly denote the maximal F -degree of the vertices u ∈ ψ −1 (v) over all v ∈ X. We choose H as a planar emulator of G with projection ϕ such that the value Dg(H) is minimized. If Dg(H) > 3, then we choose any vertex x ∈ ϕ−1 (v) where v ∈ X such that x is of H-degree Dg(H) = d > 3. Let a, b, c be the three neighbors of v in G. The neighbors of x in H naturally deﬁne a cyclic word over the alphabet {a, b, c}, and we analyze its structure in three easy cases, showing in each of them how the degree of x can be decreased (while touching only the neighbors of x). The most interesting case is a “split” illustrated in Fig. 5. The proof then proceeds inductively, and we skip the remaining details. On the other hand, Theorem 3.3 is implied by the next Lemma 3.6. For motivation we brieﬂy explain that the property to “contain two disjoint k-graphs” roughly means that a graph has two minors, each isomorphic to nonplanar K5 or K3,3 , that “overlap” one another in one vertex (which may be formed by the other graph). Validity of Theorem 3.3 then follows from a suitable local application of the following: Lemma 3.6 (Fellows [6]). In every planar emulator H of a nonplanar connected graph G with the projection ϕ : V (H) → V (G), the following holds: |ϕ−1 (v)| ≥ 2 for each v ∈ V (G). Proof (sketch). The claim is proved separately for G = K5 , G = K3,3 , and then it is routinely extended to all nonplanar graphs using Proposition 3.1. We illustrate here the ﬁrst case G = K5 : Suppose, for a contradiction, that ϕ−1 (w) = {x} for some w ∈ V (K5 ) and x ∈ V (H). Then H − x is an emulator of K4 = K5 − w, and H − x is outerplanar, i.e. all its vertices are incident with one face since they are all adjacent to the

How Not to Characterize Planar-Emulable Graphs

113

Fig. 6. A planar emulator (actually, a cover) for the complete graph K4 with the rich faces depicted in gray colour. The same figure in a “polyhedral” manner on the right.

same vertex x in H. However, all degrees in H − x are at least 3 while an outerplanar simple graph must contain a vertex of degree ≤ 2, a contradiction.

4

Constructing New Planar Emulators

The central part of this paper deals with new constructions of planar emulators which consequently give the proof of Theorem 2.5. In this section we sketch the interesting (and in some sense central) emulators for the graphs E2 and K7 − C4 (Fig. 3), while a more detailed description together with emulators for the rest of the graphs discussed in Theorem 2.5 can be found in [2]. We remark that, to our best knowledge, no planar emulators of nonprojective graphs other than those mentioned in Theorem 2.4 have been studied or published prior to our paper. Moreover, using our systematic techniques we have succeeded in ﬁnding a much smaller emulator for K1,2,2,2 than the one presented by Rieck and Yamashita in [19]. Planar Emulator for E2 . In order to obtain an easily understandable description of an emulator for E2 , we note the following: A graph isomorphic to E2 (in Fig. 3) can be constructed from the complete graph K4 on V (K4 ) = {1, 2, 3, 4} by subdividing each edge once, calling the new vertices bi-vertices, and ﬁnally introducing a new vertex 0 adjacent to all the bi-vertices. A similar sketch can be applied to a construction of a planar emulator for E2 : If one can ﬁnd a planar emulator for K4 with the additional property that each edge is incident to at least one rich face—i.e., a face bordered by representatives of all edges of K4 , then a planar emulator for E2 can be easily derived from this. More precisely, if H0 is such a special emulator of K4 , see an example in Fig. 6, then the following construction is applied. Each edge of H0 is subdivided with a new vertex representing the corresponding bi-vertex of E2 , and a new vertex representing the vertex 0 of E2 is added to every rich face of H0 such that it is adjacent to all the subdividing vertices within this face. The resulting plane graph H clearly is an emulator for E2 (and this construction is reversible).

114

M. Chimani et al.

Fig. 7. A planar emulator for E2 . The bi-vertices of the construction are in white and labeled with letters, while the numbered core vertices (cf. Fig. 6) are in gray.

Fig. 8. A planar emulator for K1,2,2,2 ; obtained by taking YΔ-transformations on the core vertices labeled 1, 2, 3, 4 of the E2 emulator from Fig. 7.

Perhaps the simplest possible such an emulator for K4 with rich faces is depicted in Fig. 6 (left). This leads to the nicely structured planar emulator for the graph E2 in Fig. 7. It is also worth to note that the same core ideas which helped us to ﬁnd this emulator for E2 , were actually used in [10] to prove the

How Not to Characterize Planar-Emulable Graphs

115

nonexistence of a planar cover for E2 . This indicates how diﬀerent the coverability and emulability concepts are from each other, too. More Emulators Derived from the E2 Case. By Proposition 3.2, the property of having a planar emulator is closed under taking YΔ-transformations. Moreover, the proof is constructive, and we may use it to mechanically produce new emulators from existing ones (this principle goes even slightly beyond straightforward YΔ-transformations, see Section 5). Therefore we can easily obtain an alternative emulator for K1,2,2,2 (cf. Theorem 2.4) which is signiﬁcantly smaller and simpler than the original one in [19]. The emulator is presented in Fig. 8. Furthermore, in the same mechanical way, we can obtain planar emulators for other members of the “K1,2,2,2 -family”; namely for B7 , C3 , D2 in Fig. 3. On the other hand, ﬁnding a planar emulator for the last member, C4 , seems to be a more complicated case—the smallest one currently has 338 vertices [2]. Planar Emulator for K7 − C4 . Already the survey [11]—when commenting on the surprising Rieck–Yamashita construction—stressed the importance of deciding whether the graph K7 − C4 is planar-emulable. Its importance is tied with the structural search for all potential nonprojective planar-emulable graphs; see [12,3] and Section 5 for a detailed explanation. Brieﬂy saying, K7 − C4 (and its “family” of D3 , E5 , F1 ; Fig. 3) are the only projective forbidden minors which have planar emulators and are not “internally 4-connected”. In fact, for several reasons we believed that K7 − C4 cannot have a planar emulator, and so it came as another surprise when we have just recently discovered one. In order to describe our planar emulator construction for K7 − C4 , it is useful to divide the vertex set of K7 − C4 into three groups: the triple of central vertices (named 1, 2, 3 in Fig. 10 left) adjacent to all other vertices, and the two vertex pairs (named A, B and C, D) each of which has connections only to its mate and to the central triple. This view allows us to identify a skeleton of the potential emulator as the subgraph induced on the vertices representing the central triple 1, 2, 3 and place the remaining vertices representing A, B and C, D into the skeleton faces, provided certain additional requirements are met. This simple idea leads to the introduction of basic building blocks (Fig. 9), each of which “almost” emulates the subgraph induced on 1,2,3,A,B and

Fig. 9. Basic building blocks for our K7 − C4 planar emulator: On the left, only vertex 2 misses an A-neighbor and 1,3 miss a B-neighbor. Analogically on the right. The right-most picture shows the skeleton of the emulator in a “polyhedral” manner.

116

M. Chimani et al.

Fig. 10. A planar emulator for K7 − C4 , constructed from the blocks in Fig. 9. The skeleton representing the central vertices is drawn in bold.

1,2,3,C,D, respectively. The crucial property of the blocks is that the vertices labeled A,B or C,D have all the required neighbors in place. Finally, four copies of each of the blocks can be arranged in the shape of an octahedron such that all missing requirements in the blocks are satisﬁed. The resulting planar emulator is in Figure 10. Similar, though much more involved, procedures lead to constructions of planar emulators for the graphs D3 , E5 , F1 (which are YΔ-transformable to K7 −C4 ). Those emulators have 126, 138, and 142 vertices, respectively, and we refer readers to an illustration in Figure 11 and the full description in [2].

5

Structural Search: How Far Can We Go?

Until now, we have presented several newly discovered planar emulators of nonprojective graphs. Unfortunately, despite the systematic construction methods introduced in Section 4, we have got nowhere closer to a real understanding of the class of planar-emulable graphs. It is almost the other way round—the new planar emulators evince more and more clearly how complicated the problem is. Hence, we also need to consider a diﬀerent approach. The structural search method, on which we brieﬂy report in this section, is directly inspired by previous [12]; we refer to [3,4] for closer details which cannot ﬁt into this paper. The general idea can be outlined as follows: If H is a mysterious nonprojective planar-emulable graph, then H must contain one of the projective forbidden minors, say F , while F cannot be among those forbidden minors not having

How Not to Characterize Planar-Emulable Graphs

117

Fig. 11. A planar emulator for F1

planar emulators (Theorems 3.3, 3.4). Now there are basically three mutually exclusive possibilities: i. H is a planar expansion of a smaller graph. A graph H is a planar expansion of G if it can be obtained by repeatedly substituting a vertex of degree ≤ 3 in G by a planar subgraph with the attachment vertices on the outer face. ii. H contains a nonﬂat 3-separation. A separation in a graph is called flat if one of the sides has a plane drawing with all the boundary vertices on the outer face. iii. H is internally 4-connected, i.e., it is 3-connected and each 3-separation in H has one side inducing the subgraph K1,3 (informally, H is 4-connected up to possible degree-3 vertices with stable neighborhood). We denote by K7 − C4 = {K7 − C4 , D3 , E5 , F1 } the family of K7 − C4 . The underlying idea is that all the graphs in a family are YΔ-transformable to the family’s base graph. Particularly the family of K7 − C4 comprises all the projective forbidden minors in question which are not internally 4-connected. See in Fig. 3.

118

M. Chimani et al.

In the case (i.) above, we simply pay attention to the smaller graph G. In the case (ii.), one can argue that either the projective forbidden minor F (in H) itself contains a nonﬂat 3-separation (so F ∈ K7 − C4 ), or F is internally 4-connected and H then is not planar-emulable (a contradiction). The former is left for further investigation. Finally, in the case (iii.) we may apply a socalled splitter theorem for internally 4-connected graphs [14], provided that F is also internally 4-connected. This leads to a straightforward computerized search which has a high chance to ﬁnish in ﬁnitely many steps, producing all such desired internally 4-connected graphs H. Actually, when the aforementioned procedure was applied to the planar cover case in [12], the search was so eﬃcient that the outcome could have been described by hand; giving all 16 speciﬁc graphs that potentially might be counterexamples to Conjectures 1.1. In our emulator case, we get the following: Theorem 5.1 ([4]). Let H be a nonprojective planar-emulable graph. Then, H is a planar expansion of one of specific 175 internally 4-connected graphs, or H contains a minor isomorphic to a member of {E2 , K4,5 − 4K2 } ∪ K7 − C4 . Up to this point, we have not been successful in ﬁnishing the computations for the graphs F = K4,5 − 4K2 and E2 , due to the high complexity of the generated extensions. Yet, we strongly believe that it is possible to obtain ﬁnite results also for those cases, perhaps with the help of an improved generating procedure. On the other hand, the cases starting with F ∈ K7 − C4 will need an alternative procedure, e.g., using so-called “separation bridging”. This is subject to future investigations.

6

Conclusion and Further Questions

While our paper presents new and surprising ﬁndings about planar-emulable graphs, the truth is that these ﬁndings are often negative in the sense that they bring more intriguing questions than answers. Of course, the fundamental open question in the area is to ﬁnd a characterization of the class of planaremulable graphs in terms of some other natural (and preferably topological) graph property. Even coming up with a plausible conjecture (cf. Conjecture 1.1) would be of high interest, but, with our current knowledge, already this seems to be out of reach yet. Instead, we suggest to consider the following speciﬁc (sub)problems: – Is there a planar emulator of the graph K4,4 − e? We think the answer is no, but are currently unable to ﬁnd a proof, e.g. extending the arguments of [8]. – The emulators shown in Section 4 suggest that we can, in some mysterious way, reﬂect ΔY -transformations in emulator constructions (i.e., the converse direction of Proposition 3.2). Such a claim cannot be true in general since, e.g., a YΔ-transformation of the graph D4 (Fig. 3) leads to a strict subgraph of B3 , which therefore has a two-fold planar cover while D4 is not planaremulable by Theorem 3.3. But where is the precise breaking point?

How Not to Characterize Planar-Emulable Graphs

119

– The two smallest projective forbidden minors are on 7 vertices, K7 − C4 (missing four edges of a cycle) and K1,2,2,2 (missing three edges of a matching). Both of them, however, have planar emulators while their common supergraph K7 does not. What is a minimal subgraph of K7 not having a planar emulator? Can we, at least, ﬁnd a short argument that the graph K7 − e has no planar emulator? – Finally, Conjecture 1.1 can be reformulated in a way that a graph has a planar cover iﬀ it has a two-fold planar cover. The results of [12] moreover imply that the minimal required fold number for planar-covers is bounded by a constant. Although, in the emulator case, the numbers of representatives for each vertex of the emulated graph diﬀer, there is still a possibility of a ﬁxed upper bound on them: Is there a constant K such that every planar-emulable graph H has a planar emulator with projection ψ such that |ψ −1 (v)| ≤ K for all v ∈ V (H)? A computerized search as in Section 5 would be of great help in this task.

References 1. Archdeacon, D.: A Kuratowski Theorem for the Projective Plane. J. Graph Theory 5, 243–246 (1981) 2. Chimani, M., Derka, M., Hlinˇen´ y, P., Klus´ aˇcek, M.: How Not to Characterize Planar-emulable Graphs. ArXiv e-prints 1107.0176, http://arxiv.org/abs/1107.0176 3. Derka, M.: Planar Graph Emulators: Fellows’ Conjecture. Bc. Thesis, Masaryk University, Brno (2010), http://is.muni.cz/th/255724/fi_b/thesis.pdf 4. Derka, M.: Towards Finite Characterization of Planar-emulable Non-projective Graphs. Congressus Numerantium, 207–211 (submitted, 2011) 5. Fellows, M.: Encoding Graphs in Graphs. Ph.D. Dissertation, Univ. of California, San Diego (1985) 6. Fellows, M.: Planar Emulators and Planar Covers (1988) (unpublished manuscript) 7. Glover, H., Huneke, J.P., Wang, C.S.: 103 Graphs That Are Irreducible for the Projective Plane. J. of Comb. Theory Ser. B 27, 332–370 (1979) 8. Hlinˇen´ y, P.: K4,4 − e Has No Finite Planar Cover. J. Graph Theory 27, 51–60 (1998) 9. Hlinˇen´ y, P.: Planar Covers of Graphs: Negami’s Conjecture. Ph.D. Dissertation, Georgia Institute of Technology, Atlanta (1999) 10. Hlinˇen´ y, P.: Another Two Graphs Having no Planar Covers. J. Graph Theory 37, 227–242 (2001) 11. Hlinˇen´ y, P.: 20 Years of Negami’s Planar Cover Conjecture. Graphs and Combinatorics 26, 525–536 (2010) 12. Hlinˇen´ y, P., Thomas, R.: On possible counterexamples to Negami’s planar cover conjecture. J. of Graph Theory 46, 183–206 (2004) 13. Huneke, J.P.: A Conjecture in Topological Graph Theory. In: Robertson, N., Seymour, P.D. (eds.) Graph Structure Theory. Contemporary Mathematics, Seattle, WA, vol. 147, pp. 387–389 (1991/1993) 14. Johnson, T., Thomas, R.: Generating Internally Four-Connected Graphs. J. Combin. Theory Ser. B 85, 21–58 (2002)

120

M. Chimani et al.

15. Klus´ aˇcek, M.: Construction of planar emulators of graphs. Bc. Thesis, Masaryk University, Brno (2011), http://is.muni.cz/th/324101/fi_b/bc_thesis.pdf 16. Negami, S.: Enumeration of Projective-planar Embeddings of Graphs. Discrete Math. 62, 299–306 (1986) 17. Negami, S.: The Spherical Genus and Virtually Planar Graphs. Discrete Math. 70, 159–168 (1988) 18. Negami, S.: Graphs Which Have No Finite Planar Covering. Bull. of the Inst. of Math. Academia Sinica 16, 378–384 (1988) 19. Rieck, Y., Yamashita, Y.: Finite planar emulators for K4,5 − 4K2 and K1,2,2,2 and Fellows’ Conjecture. European Journal of Combinatorics 31, 903–907 (2010)

Testing Monotone Read-Once Functions Dmitry V. Chistikov Faculty of Computational Mathematics and Cybernetics Moscow State University, Russia dch@cs.msu.ru

Abstract. A checking test for a monotone read-once function f depending essentially on all its n variables is a set of vectors M distinguishing f from all other monotone read-once functions of the same variables. We describe an inductive procedure for obtaining individual lower and upper bounds on the minimal number of vectors T (f ) in a checking test for any function f . The task of deriving the exact value of T (f ) is reduced to a combinatorial optimization problem related to graph connectivity. We show that for almost all functions f expressible by read-once conjunctive or disjunctive normal forms, T (f ) ∼ n/ ln n. For several classes of functions our results give the exact value of T (f ).

1

Introduction

A Boolean function of variables X is called monotone read-once iﬀ it can be expressed by a formula over {∧, ∨} without repetitions of variables (such formulae are also called read-once). By deﬁnition, we say that 0 and 1 are monotone read-once functions too. One can see that f depends essentially on a variable xi iﬀ xi appears in a read-once formula for f . Suppose that f is a monotone read-once function depending essentially on all variables from X; then a set M of input vectors is a checking test (or simply a test ) for f iﬀ for each monotone read-once function f ≡ f of variables X there exists a vector α ∈ M such that f (α) = f (α). In other words, M is a checking test for f iﬀ values of f on vectors from M allow one to distinguish between f and all other monotone read-once functions of variables X. The length of a test is the number of vectors contained in it. For a read-once function f , the minimal length of a checking test for f is denoted by T (f ). Any test for f having this length is called optimal or, equivalently, minimal. The problem of checking for read-once functions and study of minimal test length were suggested by A. A. Voronenko, whose paper [9] investigated this problem for the basis of all binary Boolean functions (in this setting the deﬁnition of a read-once function is appropriately generalized; most further results are available in English; see, e. g., [11]). It was proved that every n-variable read once function over this basis has a checking test of length less or equal to 4 n2 . This universal bound was subsequently lowered to match a trivial individual lower bound of n2 + n + 1 for an n-ary disjunction x1 ∨ . . . ∨ xn [6]. It is known, though, that there exist individual functions allowing checking tests of length C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 121–134, 2011. c Springer-Verlag Berlin Heidelberg 2011

122

D.V. Chistikov

O(n) [8,12]. Generalizations of these results to the case of arbitrary Boolean bases are discussed in [11,13]. For the basis {∧, ∨, ¬}, a universal upper bound of 7n/2 is proved in [10]. This bound has recently been improved to reach 2n + 1 [2], whereas the highest known individual lower bound is equal to n + 1. In this paper, we study minimal test length for individual monotone read-once functions (these functions are read-once over the basis {∧, ∨}). It is known [1] that for any such function f depending essentially on n variables it holds that 2 n ≤ T (f ) ≤ n+1. An example of a function requiring n+1 vectors in a checking test is an n-ary disjunction x1 ∨ . . . ∨ xn , whereas the best known individual upper bound is 3 n − 1, for a special subsequence of CNF-expressible functions, i. e., those expressible by monotone read-once conjunctive normal forms (CNF). It is also known that all CNF-expressible functions f have T (f ) ≥ 2 2 n − 1. We demonstrate that for any monotone read-once function f sets of zeros and ones (false and true points) of f in an optimal test can be chosen independently: for instance, one cannot reduce the number of zeros at the expense of adding several extra ones. If we denote by T0 (f ) and T1 (f ) the smallest possible number of zeros and ones, respectively, in a checking test for f , this result is stated as T (f ) = T0 (f ) + T1 (f ) . For CNF-expressible functions f , it turns out that the value of T (f ) is primarily determined by T0 (f ). More precisely, for almost all such functions f depending essentially on n variables (regarded as mappings from {0, 1}n to {0, 1}) it holds that n T (f ) ∼ T0 (f ) = l(f ) ∼ , ln n where l(f ) is the number of clauses in the CNF expressing f , and the equality in the center holds for all CNF-expressible f . Interestingly, the task of deriving the exact value of T1 (f ) reveals a curious combinatorial optimization problem related to graph connectivity. Our bounds on the optimal solution to this problem show that for a CNF with r1 ≥ . . . ≥ rl variables in its clauses it holds that l ri −1 T1 (f ) ≥ max r1 + r2 − 1, log2 2 −l+1 +1 , T1 (f ) ≤ min

⎧ ⎨ ⎩

i=3k

i=1

⎫ ⎬ (ri − 1) + 1 . ⎭

log2 (l+1)

(ri − 1), 4 (max{r1 , l} − 1),

i=1

For the general case of monotone read-once functions, we show that the task of deriving the exact value of T (f ) for an individual function f can be performed by an inductive procedure traversing a read-once formula for f . Calculations on each step involve determining the optimal solution to the combinatorial problem mentioned above. For any function f our results allow one to easily obtain individual lower and upper bounds on the value of T (f ). The known universal upper bound of n + 1 can be deduced as a simple corollary. For one class of read-once functions, we present a simple way of computing exact values of T (f ) using read-once formulae for f .

Testing Monotone Read-Once Functions

123

Note that our deﬁnition of a checking test requires that all variables of f be essential, while alternatives f may well have ﬁctitious variables. This restriction is imposed so that the deﬁnition would be word-to-word identical to that for wider bases. Take, for instance, the basis {∧, ∨, ¬}. If the restriction on f is not imposed, then any checking test for f (x1 , . . . , xn ) ≡ 0 must distinguish it from all conjunctions of n literals and, therefore, must contain all 2n vectors. Such a setting should be considered degenerate. For monotone read-once functions considered in this paper, however, such a restriction can be freely lifted. Indeed, if a monotone read-once function f depends essentially on variables x1 , . . . , xn , and g is obtained from f by adding ﬁctitious variables y1 , . . . , ym , then a checking test for g can be obtained from a checking test M for f by extending all zeros of f in M with values y1 = . . . = ym = 1, and all ones of f in M with values y1 = . . . = ym = 0. Hence, the length of an optimal checking test for g is equal to that for f .

2

Combinatorial Reduction

Let f be a monotone read-once function of variables X. Denote by R(f ) a graph on vertices X such that an edge {xi , xk } is present in R(f ) iﬀ f has a projection equivalent to xi ∧xk . A classic result of V. A. Gurvich [4] (see also [5]) states that all projections of f that depend essentially on exactly two variables xi and xk are equal to each other, equivalent either to xi ∧ xk or to xi ∨ xk , and that at least one such projection exists. Every monotone read-once function is uniquely determined by its graph R(f ). We shall use a widely known fact that the complement of any nontrivial connected induced subgraph of R(f ) is disconnected (R(f ) is a cograph [3]). We say that a formula F is of type ∧ (∨) iﬀ it is either a variable or a conjunction (a disjunction) of two or more subformulae. A monotone read-once function f is of type ◦ ∈ {∧, ∨} iﬀ it can be expressed by a read-once formula of type ◦ over {∧, ∨}. Clearly, f is of type ∧ iﬀ R(f ) is connected. We need the following notation. An integer partition is a way of representing an integer as a sum of several positive integers. When referring to integer partitions, we write m = t1 + · · · + tp , where m, p, t1 , . . . , tp ≥ 1. We also use one operation on equivalence relations. Suppose that and are equivalence relations on a set S; then by ∨ we denote the transitive closure of the union of and . Thus, ∨ is itself an equivalence relation such that a ∼ b iﬀ there exists a sequence c0 , . . . , ck ∈ S such that a = c0 , b = ck and for each i = 1, . . . , k either ci−1 ∼ ci or ci−1 ∼ ci . In other words, ∨ is the ﬁnest equivalence relation on S that is coarser than both and . By true we denote the binary all-true relation on a set. Finally, we use symbols 0 and 1 to denote vectors consisting only of zeros and ones, respectively. Suppose that l ≥ 1 and r1 , . . . , rl ≥ 1. Take arbitrary positive integers ti,j for 1 ≤ i ≤ l and 1 ≤ j ≤ ri . Denote by F the multiset of l integer partitions mi = ti,1 + · · · + ti,ri , for i = 1, . . . , l. Deﬁne L(F ) as the smallest number t having the following property: there exist equivalence relations 1 , . . . , l on the

124

D.V. Chistikov

set {1, . . . , t} such that each i has ri equivalence classes of cardinality greater or equal to ti,1 , . . . , ti,ri , respectively, and i ∨ k = true whenever i = k. If ti,j = 1 for all possible i, j, the number L(F ) will also be referred to as L(r1 , . . . , rl ). Theorem 1. Let l ≥ 2 and r1 , . . . , rl ≥ 1. Suppose that fi,j , 1 ≤ j ≤ ri , 1 ≤ i ≤ l, are monotone read-once functions of type ∧ depending on disjoint sets of variables, fi = fi,1 ∨ . . . ∨ fi,ri for i = 1, . . . , l, f = f1 ∧ . . . ∧ fl , and fi,1 is a single variable whenever ri = 1. Then T (f ) = T0 (f ) + T1 (f ) , T0 (f ) =

l

T0 (fi ) ,

and

T1 (f ) = L(F ) ,

i=1

where F is the multiset of integer partitions T1 (fi,1 ) + · · · + T1 (fi,ri ) for all i = 1, . . . , l. Proof. First obtain the lower bounds. Suppose that a checking test M for f contains a vector α such that f (α) = 1. Clearly, replacing α with any vector β ≤ α such that f (β) = 1 yields a set of vectors that retains the property of being a checking test. Similarly, one can replace all vectors γ such that f (γ) = 0 with vectors δ ≥ γ such that f (δ) = 0. The obtained set M will still constitute a checking test for f , and |M | ≤ |M | (note that it may be the case that, e. g., diﬀerent vectors α and α can be replaced with a single vector β). Further on, we assume that all possible replacements have been performed, i. e., M contains only lower ones and upper zeros of f . Now take an arbitrary upper zero α of f . Let α be a concatenation of vectors α1 , . . . , αl such that each fi depends essentially on the variables assigned by αi . Since f is a read-once conjunction of all fi , 1 ≤ i ≤ l, this means that there exists a unique index i such that fi (αi ) = 0 and fk (αk ) = 1 for all k = i. Moreover, it follows that αi is an upper zero of fi and all αk = 1 for k = i. Denote by zi the number of all vectors α in M such that fi (αi ) = 0. Since M is a checking test for f , it follows that zi ≥ T0 (fi ). (Indeed, if zi < T0 (fi ), then there exists a monotone read-once function fi ≡ fi which depends on the same variables as fi and agrees with it on all zi vectors αi . It then follows that f cannot be distinguished from the function f obtained by substituting fi for fi in the read-once formula for f .) Observe that no vector α can be counted more than once in z1 , . . . , zl , for all non-constant monotone read-once functions take l l the value of 1 at 1. Thus, T0 (f ) ≥ i=1 zi ≥ i=1 T0 (fi ). In order to prove the lower bound on T1 (f ), consider the set α(1) , . . . , α(t) of all lower ones of f contained in M . One can see that an arbitrary lower one α of f is a concatenation of α1 , . . . , αl such that fi (αi ) = 1 for all i. Moreover, each αi must be a lower one of fi . Hence, each αi is a concatenation of αi,1 , . . . , αi,ri , and there exists a unique index j such that fi,j (αi,j ) = 1 and all αi,s = 0 for s = j. For each α(p) , these indices will be denoted by j1 (p), . . . , jl (p). For each i = 1, . . . , l consider an equivalence relation i on {1, . . . , t} such that p ∼i q iﬀ ji (p) = ji (q). We claim that i ∨ k = true if i = k. Assume

Testing Monotone Read-Once Functions

125

the converse, then there exists a non-empty proper subset S of {1, . . . , t} such that for all p ∈ S and q ∈ {1, . . . , t} \ S it holds that p ∼i q and p ∼k q. By deﬁnition, put I = { ji (p) | p ∈ S } and K = { jk (p) | p ∈ S }. Construct a monotone read-once function f by replacing the conjunction fi ∧ fk in the read-once formula for f with a disjunction (fi ∧ fk ) ∨ (fi ∧ fk ), where fi = fi,j , fk = fk,j , j∈I

fi

=

j∈K

fi,j ,

fk

j∈I

=

fk,j .

j∈K

We see that f is always greater or equal to f and disagrees with it only on vectors α such that either fi (αi ) ∧ fk (αk ) = 1 or fi (αi ) ∧ fk (αk ) = 1. Since M (1) (t) is a checking test, such a vector αmustbe present among α , . . . , α . Assume (p) (p) without loss of generality that fi αi ∧ fk αk = 1. By deﬁnition of fi and fk , it holds that ji (p) ∈ I and jk (p) ∈ K, so p ∈ S and p ∈ S, which is a contradiction. In order to prove that T1 (f ) ≥ L(F ), we show that ji (p) = j for at least T1 (fi,j ) numbers p ∈ {1, . . . , t}. Indeed, if this is not the case, then M contains fewer than T1 (fi,j ) vectors α such that αi,j = 0, 1, fi,j (αi,j ) = 1 and f (α) = 1. By deﬁnition of T1 (fi,j ), this means that these αi,j do not allow one to distinguish . (Note that 1 is between fi,j and a certain monotone read-once function fi,j included in a minimal checking test for fi,j iﬀ T1 (fi,j ) = 1, otherwise it is obviously of no use.) Substituting fi,j for fi,j in the read-once formula for f yields a formula expressing a monotone read-once function f ≡ f such that f agrees with f on all vectors from M . This concludes the proof of the lower bounds. We now prove the upper bounds and the equality T (f ) = T0 (f ) + T1 (f ). We use induction on the depth of the read-once formula for f . In the inductive step, we shall use only the fact that T (fi) = T0 (fi )+T1 (fi ) as an inductive assumption. Therefore, we need to check this equality for single variables, conjunctions and disjunctions. It can easily be checked that for n ≥ 1, T0 (x1 ∨ . . . ∨ xn ) = 1 ,

T1 (x1 ∨ . . . ∨ xn ) = n , T (x1 ∨ . . . ∨ xn ) = n + 1 ,

T0 (x1 ∧ . . . ∧ xn ) = n , T1 (x1 ∧ . . . ∧ xn ) = 1 ,

T (x1 ∧ . . . ∧ xn ) = n + 1 ,

so we proceed to the main part of the proof. Let M1 , . . . , Ml be optimal checking tests for f1 , . . . , fl , respectively, all consisting of upper zeros and lower ones of fi . Let N consist of all vectors α = (1, . . . , 1, αi , 1, . . . , 1) for all αi ∈ Mi such that fi (αi ) = 0 and i = 1, . . . , l. Now suppose that L(F ) = t and equivalence relations 1 , . . . , l on {1, . . . , t} satisfy the conditions of L(F ) deﬁnition. Assume that equivalence classes of each i are numbered 1 through ri so that jth class’s cardinality is greater or equal to T1 (fi,j ). Now recall that every vector αi ∈ Mi such that fi (αi ) = 1 is a lower one of fi and thus has a special representation as a concatenation of αi,j , 1 ≤ j ≤ ri . Put Ui,j = { αi,j | αi ∈ Mi , fi (αi ) = 1, αi,j = 0 }. For each p = 1, . . . , t put

126

D.V. Chistikov

(p) (p) (p) (p) (p) (p) α(p) = α1 , . . . , αl , where αi = αi,1 , . . . , αi,ri such that αi,j ∈ Ui,j if (p)

the number p belongs to the jth equivalence class of i and αi,j = 0 otherwise. (p)

We also require that for each valid pair i, j the set of all non-0 vectors αi,j be equal to Ui,j . This is possible because the number of elements in jth equivalence class of i is greater or equal to |Ui,j | = T1 (fi,j ) (this equality follows easily checked that from i , for it is M ri the inductive assumption and our choice of (1) (t) |U | = T (f )). We claim that M = N ∪ α , . . . , α is a checking test i,j 1 i j=1 for f . We show that if a monotone read-once function f coincides with f on all vectors from M , then f ≡ f . This is suﬃcient both for proving the claimed upper bound and, as a corollary, for establishing the equality T (f ) = T0 (f ) + T1 (f ). First, observe that f α(p) = 1 for all p = 1, . . . , t. Since f is monotone,

it follows that f (α) = 1 for any α of type 1, . . . , 1, αi , 1, . . . , 1 , where p = 1, . . . , t. By our construction of M , all vectors from Mi are present in (p) αi | α(p) ∈ M . Since M contains all vectors from N , it follows that f (α) = f (α) for all α = (1, . . . , 1, αi , 1, . . . , 1), where αi ∈ Mi . One concludes, then, that for each i = 1, . . . , l the function f has a projection equivalent to fi . Now we are going to reconstruct the graph R(f ) = R(f ) using the values of f on vectors from M . Note that all subgraphs Ri = R(fi ) are already known. Recall that all functions fi,j are of type ∧, so all Ri,j are connected. On the contrary, each Ri is either disconnected or a single vertex. It suﬃces to show that each subgraph Ri ∪ Rk of R(f ) (a subgraph of R(f ) induced by vertices of Ri and Rk ) is connected if i = k, for then all edges between Ri and Rk must be present in it, otherwise any edge between Ri and Rk not present in Ri ∪ Rk would imply the connectivity of Ri ∪ Rk ’s complement, which contradicts the connectivity of Ri ∪ Rk (recall that R(f ) is a cograph). We now contract all vertices in each Ri,j (Rk,j ) to a single vertex j (j ) and prove the connectivity of the obtained bipartite graph R on {1, . . . , ri } ∪ {1 , . . . , rk }. vertices (p) = 1 implies that the edge {ji (p),jk (p)} We ﬁrst claim that the equality f α is present in R . Indeed, since f α(p) = 1, it holds that f (β) = 1, where β (p)

(p)

is obtained from α(p) by changing all αu to 1 for u = i, k. Suppose that γ is obtained from β by changing a 1 in αi to 0. One now observes that replacing αk with 1 in γ yields a vector γ with a known value f (γ ) = 0, since every αu , where u = i, is now replaced by 1, and αi is a lower one of the known projection fi . Monotonicity of f implies f (γ) = 0. Arguing as above, we see that f (δ) = 0, where δ is obtained from β by changing a 1 in αk to 0. The values of f on vectors β, γ, and δ are uniquely determined by its values on vectors from M and imply that f has a projection of the type x ∧ x , where fi,ji (p) and fk,jk (p) depend on x and x , respectively. Thus, R contains all edges {ji (p), jk (p)} for p = 1, . . . , t. It remains to prove that these edges imply the connectivity of R . Consider a graph G on 2t vertices {1, . . . , t} ∪ {1 , . . . , t }. Let G contain all the edges {p, p } for p = 1, . . . , t, edges {p, q} whenever p ∼i q, and {p , q } whenever p ∼k q . Contracting all the edges within {1, . . . , t} and {1 , . . . , t } yields a graph H,

Testing Monotone Read-Once Functions

127

which is known to be isomorphic to a subgraph of R . Clearly, H is connected if so is G. Contracting all the edges {p, p } in G yields a graph G on vertices {1, . . . , t} such that {p, q} is present in G if and only if p ∼i q or p ∼k q. Since i ∨ k = true, it follows that G is connected, and so are G, H and R . This concludes the proof. Corollary 2. For all non-constant monotone read-once functions f , T (f ) = T0 (f ) + T1 (f ) . Corollary 3. For a monotone read-once function f = (x1,1 ∨ . . . ∨ x1,r1 ) ∧ (x2,1 ∨ . . . ∨ x2,r2 ) ∧ . . . ∧ (xl,1 ∨ . . . ∨ xl,rl ) , where l ≥ 1 and all ri ≥ 1, the following equality holds: T (f ) = l + L(r1 , . . . , rl ) . Remark 4. The statements of Theorem 1 and Corollary 3 hold true if all symbols ∧ and ∨ are exchanged and so are Boolean constants 0 and 1. Provided that an algorithm for determining L(F ) is known, one can use a simple inductive procedure to determine the value of T (f ) for any arbitrary monotone read-once function f . The induction basis is given by the values of T0 (f ) and T1 (f ) for disjunctions and conjunctions of n ≥ 1 variables. Since L(F ) is evidently monotonically non-decreasing in all parameters in F , one can substitute lower and upper bounds for the unknown parameters to obtain lower and upper bounds on L(F ), respectively.

3

Obtaining Bounds on L(F )

Proposition 5. L(r1 , . . . , rl ) ≤ L(F ) ≤ L(r1 , . . . , rl ) + max (mi − ri ) − d, where 1≤i≤l

d = 1 if there exist numbers s = k such that s is a maximum point of mi − ri and rk ≥ 2, and d = 0 otherwise. Proof. The lower bound is obvious and the upper bound follows from the observation that in all non-trivial cases any equivalence relation i from the deﬁnition of t = L(r1 , . . . , rl ) has at least one equivalence class of size greater or equal to 2, so for each i such that mi > ri one needs less or equal to mi − ri − 1 new elements beyond 1, . . . , t. The only exception is the case when rk = 1 for all k = i. When obtaining bounds on L(F ), we often use graph-theoretic terminology, as given by the following lemma. (Note that when we speak of graphs, we always mean undirected graphs without loops or multiple edges.) Lemma 6. The number L(F ) is the smallest number t having the following property: there exist graphs G1 , . . . Gl on vertices {1, . . . , t} such that each Gi has exactly ri connected components of size greater or equal to ti,1 , . . . , ti,ri , and all graphs Gi ∪ Gk are connected whenever i = k.

128

D.V. Chistikov

The proof is trivial. Note that we can use arbitrary connected graphs as components of Gi . It is often convenient, though, to use only trees as these components; in this case all graphs Gi are required to be forests. Theorem 7. Suppose that F is a multiset of integer partitions mi = ti,1 + · · · + ti,ri for i = 1, . . . , l. Then the following inequality holds: l 2ri −1 − l + 1 + 1 . L(F ) ≥ max max mi , max ri + rk − 1, log2 i

i=k

i=1

Proof. Let t be the value of L(F ). One can easily see that t ≥ mi for all i = 1, . . . , l. Indeed, since Gi has to contain ri connected components of size at least ri ti,1 , . . . , ti,ri , it follows that t ≥ j=1 ti,j = mi . Now suppose that i = k and assume without loss of generality that both Gi and Gk are forests. Then the number of edges in these two graphs is t − ri and t−rk , respectively. Since Gi ∪Gk is connected, we see that (t−ri )+(t−rk ) ≥ t−1 and t ≥ ri + rk − 1. Finally, consider partitions of {1, . . . , t} into two non-empty sets S and S . The number of such partitions is 2t−1 −1. For each graph Gi having ri connected components there exist exactly 2ri −1 − 1 such partitions without edges between S and S in Gi . These sets of partitions must be disjoint for i = k, otherwise Gi ∪ Gk contains no S and S and, therefore, is disconnected. ledgesribetween t−1 −1 Hence, 2 − 1 ≥ i=1 (2 − 1), which gives the desired. In several cases the bounds of Theorem 7 turn out to be tight. Two next propositions show that all three expressions under max can give the exact value of L(F ) for some F . Proposition 8. If l = 2, then L(F ) = max{m1 , m2 , r1 + r2 − 1}. Proof. Let F consist of partitions m1 = t1 + · · · + tp and m2 = s1 + · · · + sq . By Theorem 7, L(F ) ≥ m, where m = max{m1 , m2 , p+q−1}. Our goal is to prove an equal upper bound. Assume without loss of generality that m1 = m2 ≥ p + q − 1. (If this is not the case, increase some of the numbers t1 , . . . , tp and s1 , . . . , sq appropriately so that m1 and m2 would reach m and observe that for the multiset F of the two obtained partitions it holds that L(F ) ≤ L(F ).) We claim that for any multiset F satisfying this condition and any appropriate graph G1 on m = m1 vertices there exists a graph G2 with the needed properties. The proof of this claim is by induction over q ≥ 1. For q = 1, the desired is straightforward. Indeed, since m = m1 and m = m2 = s1 , one can take a complete graph on m vertices for G2 . Now suppose that q ≥ 2. Assume that t1 ≤ t2 ≤ . . . ≤ tp and s = maxi si . If s = 1, then p = (p + q − 1) − (q − 1) ≤ m − q + 1 = q − q + 1 = 1. So, p = 1 and G1 is a complete graph on m vertices, similarly to the case above. If s ≥ 2, take connected components of size t1 , . . . , ts−1 and tp in G1 , choose one vertex from each of these components and form a clique of size s on these vertices in G2 . If p ≤ s, missing s − p vertices are chosen arbitrarily and we have proved the desired without the inductive assumption. If p > s, the problem is reduced

Testing Monotone Read-Once Functions

129

to a simpler one, with q = q − 1 (we use prime symbols for distinguishing a new instance of the problem from the old one), p = p−s+1, p +q −1 = (p+q−1)−s and m = m1 = m2 = m − s. Indeed, components of size t1 , . . . , ts−1 and tp in G1 are connected with a clique in G2 , whose s vertices are excluded from further consideration. The rest t1 = (t1 − 1) + . . . + (ts−1 − 1) + (tp − 1) vertices from these components (note that t1 ≥ 0 + . . . + 0 + 1 = 1) are considered to belong to the same component of G1 and so may be connected with, e. g., a clique in G1 . Thus, q is decreased by 1 and the property m = m1 = m2 ≥ p + q − 1 still holds. This concludes the proof. Proposition 9. L(2, . . . , 2) = log2 (l + 1) + 1. Proof. The lower bound is given by Theorem 7. To prove the upper bound, take all possible graphs Gi on vertices {1, . . . , t} having exactly two connected components and all edges within each component (any Gi is a union of two cliques). Clearly, if Gi and Gk are two such graphs, then Gi ∪ Gk is connected if and only if Gi = Gk . So, if t is ﬁxed, l can be chosen as large as 2t−1 − 1. Hence, t ≤ log2 (l + 1) + 1. We now present an example of using Theorem 1 for deriving exact values of T (f ). This example is directly related to the result of Proposition 8. We say that a formula F over {∧, ∨} is strictly alternating iﬀ it is either a variable or a disjunction (respectively, a conjunction) of exactly two strictly alternating formulae that have type ∧ (respectively, ∨). The structure of strictly alternating formulae can be represented by binary trees with alternating levels of internal vertices labeled with ∧ and ∨. By F ∗ we denote a formula obtained from F by exchanging all symbols ∧ and ∨. Proposition 10. Let f be a monotone read-once function expressed by a strictly alternating read-once formula F. By definition, put x y = 3 if x = y = 2 and x y = max{x, y} otherwise. Then T (f ) = E(F ) + E(F ∗ ), where E(F) is the value of the formula obtained from F by changing all symbols ∨ to +, all symbols ∧ to , and setting all variables’ values to 1. Proof. Use the inductive procedure of Theorem 1. For conjunctions and disjunctions, there is nothing to prove. For all other cases, use Proposition 8. Observe that if max{m1 , m2 } < r1 + r2 − 1, then r1 = r2 = 2, since each ri is less or equal to min{mi , 2}. It follows that m1 = m2 = 2, which gives the desired. Example 11. Suppose that formulae Fn are represented by perfect binary trees h with n = 2 leaves. For the correspondingread-once functions fn , if h ≥ 3, then T (fn ) = 3 n if h is even and T (fn ) = 9 2 / 4 · n if h is odd. Proof. Without loss of generality, denote by fn a read-once function expressed by a formula Fn of type ∧, and by fn∗ a read-once function expressed by Fn∗ . Clearly, T0 (fn ) = T1 (fn∗ ) and T1 (fn ) = T0 (fn∗ ). Straightforward application of Proposition 10 shows that T (f8 ) = 9 = 9 2 / 4 · 8 , T (f16 ) = 12 = 3 16 ,

130

D.V. Chistikov

which proves the induction basis. For n ≥ 8, Proposition 10 reveals that ∗ ) = 2 T0 (fn ) , T0 (f4n ) = 2 T0 (f2n ∗ T1 (f4n ) = T1 (f2n ) = 2 T1 (fn ) ,

and it follows that T (f4n ) = 2 T (fn) . This completes the proof. By F1 +F2 denote the sum of multisets F1 and F2 , i. e., a multiset which contains each element of F1 or F2 as many times as F1 and F2 do together. Simple decomposition gives the following upper bound on L(F1 + F2 ). Lemma 12. L(F1 + F2 ) ≤ L(F1 ) + L(F2 ) − 1. Proof. Suppose that t1 = L(F1 ) and t2 = L(F2 ). Let G11 , . . . , G1l1 and G21 , . . . , G2l2 be graphs from the alternative deﬁnition of L(F1 ) and L(F2 ) given by Lemma 6. Assume without loss of generality that each Gsi , where s = 1, 2, is a graph on vertices {(s, 1), . . . , (s, ts )}. Take each Gsi and extend it with a clique on vertices {(3 − s, 1), . . . , (3 − s, t3−s )}, and then identify vertices (1, 1) and (2, 1). The obtained graph His has t1 + t2 − 1 vertices and the same number of connected components as Gsi . The number of vertices in each component is greater or equal to that in Gsi . For all possible i = k, graphs His ∪ Hks are connected because so are Gsi ∪ Gsk . Moreover, all Hi1 ∪ Hk2 for any possible i, k are connected too, for they all contain cliques on vertices {(1, 1), . . . , (1, t1 )} and {(2, 1), . . . , (2, t2 )}, where (1, 1) and (2, 1) are one vertex. This means that L(F1 + F2 ) ≤ t1 + t2 − 1. The results of Theorem 1 and Lemma 12 lead to an inductive proof of the following known result: Theorem 13. For all monotone read-once functions f depending on n variables, T (f ) ≤ n + 1 . Proof. Use induction on n ≥ 1. For n = 1, the bound is clearly true. Suppose now that n ≥ 2. Assume without loss of generality that f = f1 ∧ . . . ∧ fl and fi = fi,1 ∨ . . . ∨ fi,ri , where all fi,j are monotone read-once functions of type ∧ depending on disjoint sets of variables, and fi,1 is a single variable whenever ri = 1. Let ni be the number of variables of fi . By the inductive assumption, T (fi) ≤ ni + 1. By Theorem 1, T1 (f ) ≤ L(F ), where F is the multiset of integer partitions T1 (fi,1 ) + · · · + T1 (fi,ri ) for i = 1, . . . , l. By Lemma 12, L(F ) ≤

l i=1

L({T1 (fi,1 ) + · · · + T1 (fi,ri )}) − l + 1 =

ri l i=1 j=1

T1 (fi,j ) − l + 1 .

Testing Monotone Read-Once Functions

131

Applying Theorem 1 three more times yields T1 (f ) ≤

l

T1 (fi ) − l + 1 ,

T0 (f ) =

i=1

and T (f ) ≤

l i=1

(T (fi ) − 1) + 1 ≤

l

T0 (fi ) ,

i=1 l

ni + 1 = n + 1 ,

i=1

which completes the proof. To prove more accurate individual upper bounds, we need the following notation. If m is a positive integer, then Zm 2 = { (x1 , . . . , xm ) | x1 , . . . , xm ∈ Z2 } is a vector space over Z2 = {0, 1}. For an arbitrary vector x ∈ Zm 2 , put supp x = { i | 1 ≤ i ≤ m, xi = 1 }. The following lemma gives an alternative deﬁnition of L(r1 , . . . , rl ). Lemma 14. The number L(r1 , . . . , rl ) − 1 is the smallest integer m having the following property: there exist linear subspaces V1 , . . . , Vl of Zm 2 such that dim Vi = ri − 1, Vi ∩ Vk = {0} for i = k and each Vi has a basis ei,1 , . . . , ei,ri −1 with supp ei,j ∩ supp ei,j = ∅ for j = j . The idea of the proof is that if i = 1, . . . , l, then sets supp ei,j for j = 1, . . . , ri −1 are equivalence classes of i not containing t = L(r1 , . . . , rl ). Details are left to the reader. Note that we can also reformulate the deﬁnition of L(F ) in a way similar to that of Lemma 14. Such a deﬁnition, though, is out of our scope now. We now aim to obtain an eﬃcient upper bound on L(r1 , . . . , rl ). For convenience, by L(e1 , . . . , es ) we denote the linear subspace spanned by vectors e1 , . . . , es . Proposition 15. If r1 ≥ r2 ≥ r3 , then L(r1 , r2 , r3 ) = r1 + r2 − 1. Proof. The lower bound follows from Theorem 7. To prove the upper bound, put m = r1 + r2 − 2. By ej denote a vector from Zm 2 with m − 1 zeros and an only one in jth position. Consider subspaces V2 = L(er1 , . . . , em ) , V1 = L(e1 , . . . , er1 −1 ) , V3 = L(e1 + er1 , e2 + er1 +1 , . . . , er3 −1 + er1 +r3 −2 ) . Since r3 is less or equal to both r1 and r2 , the sets Vi \ {0} are pairwise disjoint. Each Vi is spanned by ri − 1 linearly independent vectors without common ones, so, by Lemma 14, we get the needed upper bound. In the next proposition, the proof of the upper bound follows from a construction of [1] due to Voronenko, and the lower bound is given by Theorem 7. Proposition 16. If r1 ≥ . . . ≥ rl , then L(r1 , . . . , rl ) ≤ 2 p(max{r1 , l}) − 1 ≤ 4 max{r1 , l} − 3, where p(k) is the smallest prime greater or equal to k. In particular, if r1 = . . . = rl = l and l is prime, then L(l, . . . , l) = 2l − 1. Now we are ready to prove our main upper bounds.

132

D.V. Chistikov

Theorem 17. If r1 ≥ r2 ≥ . . . ≥ rl , then ⎧ ⎫ log2 (l+1) ⎨ ⎬ (ri − 1), 4 (max{r1 , l} − 1), (ri − 1) + 1 . L(r1 , . . . , rl ) ≤ min ⎩ ⎭ i=1

i=3k

Proof. First combine the results of Propositions 8 and 15 using Lemma 12. Put l = 3s + d, where d ∈ {1, 2, 3}, and observe that the diﬀerence L(r1 , . . . , rl ) − L(r3s+1 , . . . , r3s+d ) cannot be greater than s−1

L(r3i+1 , r3i+2 , r3i+3 ) − s =

i=0

s−1

(r3i+1 + r3i+2 − 1) − s =

i=0

(ri − 1) ,

1≤i≤3s i=3k

which gives the ﬁrst needed inequality. The second inequality follows from Proposition 16. To prove the third inequality, use Lemma 14 directly. Choose d = log2 (l + 1) as the number of digits in a binary representation of l. For i = 1, . . . , l by αs (i) denote sth least signiﬁcant bit in a d-bit binary representation α(i) = (αd (i) . . . α1 (i)) of i. Let π be any permutation on {1, . . . , l} such that π(s) = 2s−1 for s = 1, . . . , d. Put uπ(i) = ri − 1 for i = 1, . . . , l and choose m = d d s=1 uπ(s) = s=1 (rs − 1). For s = 1, . . . , d and j = 1, . . . , uπ(s) by fs,j denote a vector from Zm 2 with m− 1 zeros and an only one in (uπ(1) + . . .+ uπ(s−1) + j)th position. Take ei,j =

d

αs (i) fs,j ,

j = 1, . . . , ui ,

i = 1, . . . , l,

s=1

and consider subspaces Ui = L(ei,1 , . . . , ei,ui ) for i = 1, . . . , l. Clearly, dim Ui = ui ui d ui , for s=1 λj αs (i) fs,j = 0 and λj = 0 for j=1 λj ei,j = 0 implies j=1 all possible j, since vectors fs,j are linearly independent. (Note the special case i = 2q , where j can assume values greater than us , but it turns out that all αs (i) equal 0 except for one s and we still see that all λj must be equal to 0.) It is easily observed that for each i sets supp ei,j , where j = 1, . . . , ui , are disjoint. We claim that Ui ∩ Uk = {0} whenever i = k, which is evidently suﬃcient for obtaining the desired bound. Instead of using linear algebra in a straightforward way, we prove a special property of sets Ui . For each x ∈ Zm 2 , deﬁne sig x = { s | 1 ≤ s ≤ d, ∃ j : x ≥ fs,j , 1 ≤ j ≤ us }. Take an arbitrary non-0 vector x ∈ Ui . Observe that x=

ui j=1

λj ei,j =

ui j=1

λj

d s=1

αs (i) fs,j =

d s=1

αs (i)

ui

λj fs,j .

j=1

If αs (i) = 1, then j assumes the values 1, . . . , ui ≤ uπ(s) . Therefore, all vectors fs,j have ones in diﬀerent single components. It follows that sig x = supp α(i), where α(i) = (αd (i) . . . α1 (i)) is a d-bit binary representation of i. Hence, the sets Ui \ {0} are disjoint, which completes the proof.

Testing Monotone Read-Once Functions

133

In the next theorem, when we speak of almost all CNF- and DNF-expressible functions, these functions are regarded as mappings from {0, 1}n to {0, 1}. For each n, all mappings expressible by monotone read-once CNF or DNF are assigned equal non-zero probabilities. For instance, formulae (x1 ∨ x2 ) ∧ x3 and (x2 ∨ x1 ) ∧ x3 express the same function, diﬀerent from one expressed by (x1 ∨ x3 ) ∧ x2 . Theorem 18. For almost all monotone read-once CNF- and DNF-expressible functions f depending essentially on n variables, T (f ) ∼

n . ln n

Proof. Consider a monotone read-once CNF-expressible function f which depends essentially on n variables x1 , . . . , xn . One can easily see that there exists a one-to-one mapping φ between the set of all such functions and the set of all partitions of the set {1, . . . , n}. For a function f expressed by a CNF F , indices p and q belong to the same block in φ(f ) iﬀ they belong to the same clause in F. Denote by l the number of clauses in F. It is known that almost all partitions have asymptotically n/ ln n blocks, all of which have size less or equal to O(ln n) (see, e. g., [7]). One observes then that the upper bound of Theorem 17 is almost always less or equal to n n + o(1) · O(ln n) = O(ln2 n) = o , log2 ln n ln n so the value of T (f ) given by Corollary 3 is asymptotically equivalent to T0 (f ) = l ∼ n/ ln n.

4

Conclusions

We reduced the problem of deriving the value of T (f ) to several instances of another combinatorial problem, that of determining the smallest number of vertices L allowing the construction of a set of graphs with special properties. Our results give several explicit bounds on L numbers and allow to deduce the implied bounds on T (f ) easily. For almost all CNF- and DNF-expressible functions, these bounds determine the asymptotic behaviour of T (f ). For arbitrary readonce functions f , one can use Theorem 1 repeatedly to obtain both lower and upper bounds on T (f ). For several classes of functions our results determine the exact value of T (f ). Finally, we remark that one can easily indicate a special class of read-once functions which shows that it is impossible to derive the exact values of T (f ) for all f without computing L. Acknowledgements. The author wishes to thank Prof. Bruce M. Kapron from the University of Victoria, Canada, who kindly agreed to present this paper at IWOCA 2011. This research was supported by Russian Presidential grant MD– 757.2011.9.

134

D.V. Chistikov

References 1. Bubnov, S.E., Voronenko, A.A., Chistikov, D.V.: Some test length bounds for nonrepeating functions in the {&, ∨} basis. Computational Mathematics and Modeling 21(2), 196–205 (2010) 2. Chistikov, D.V.: Testing read-once functions over the elementary basis. Moscow University Computational Mathematics and Cybernetics (to appear) 3. Corneil, D.G., Lerchs, H., Stewart Burlingham, L.: Complement reducible graphs. Discrete Applied Mathematics 3(3), 163–174 (1981) 4. Gurvich, V.A.: On repetition-free Boolean functions. Uspehi Matematicheskih nauk 32(1), 183–184 (1977) (in Russian) 5. Karchmer, M., Linial, N., Newman, I., Saks, M., Widgerson, A.: Combinatorial characterization of read-once formulae. Discrete Mathematics 114(1-3), 275–282 (1993) 6. Ryabets, L.V.: Checking test complexity for read-once Boolean functions. Ser. Diskretnaya matematika i informatika, vol. 18. Izdatel’stvo Irkutskogo gosudarstvennogo pedagogicheskogo universiteta (2007) (in Russian) 7. Sachkov, V.N.: Probabilistic methods in combinatorial analysis. Encyclopedia of Mathematics and its Applications, vol. 56. Cambridge University Press (1997) 8. Voronenko, A.A.: Estimating the length of a diagnostic test for some nonrepeating functions. Computational Mathematics and Modeling 15(4), 377–386 (2004) 9. Voronenko, A.A.: On checking tests for read-once functions. In: Matematicheskie Voprosy Kibernetiki, Fizmatlit, Moscow, vol. 11, pp. 163–176 (2002) (in Russian) 10. Voronenko, A.A.: On the length of checking test for repetition-free functions in the basis {0, 1, &, ∨, ¬}. Discrete Mathematics and Applications 15(3), 313–318 (2005) 11. Voronenko, A.A.: Recognizing the nonrepeating property in an arbitrary basis. Computational Mathematics and Modeling 18(1), 55–65 (2007) 12. Voronenko, A.A., Chistikov, D.V.: Learning read-once functions individually. Uchenye zapiski Kazanskogo universiteta. Ser. Fiziko-matematicheskie nauki 151(2), 36–44 (2009) (in Russian) 13. Voronenko, A.A., Chistikov, D.V.: On testing read-once Boolean functions in the basis B5 . In: Proceedings of the XVII International Workshop “Synthesis and complexity of control systems”, pp. 24–30. Izdatel stvo Instituta matematiki, Novosibirsk (2008) (in Russian)

Complexity of Cycle Transverse Matching Problems Ross Churchley1 , Jing Huang2 , and Xuding Zhu3 1

2

Department of Mathematics and Statistics, University of Victoria, Victoria, B.C., Canada, V8W 3R4 rosschurchley@gmail.com Department of Mathematics and Statistics, University of Victoria, Victoria, B.C., Canada, V8W 3R4 huangj@uvic.ca 3 Department of mathematics, Zhejiang Normal University, Jinhua, Zhejiang, People’s Republic of China xudingzhu@gmail.com

Abstract. The stable transversal problem for a fixed graph H asks whether a graph contains a stable set that meets every induced copy of H in the graph. Stable transversal problems generalize several vertex partition problems and have been studied for various classes of graphs. Following a result of Farrugia, the stable transversal problem for each C with ≥ 3 is NP-complete. In this paper, we study an ‘edge version’ of these problems. Specifically, we investigate the problem of determining whether a graph contains a matching that meets every copy of H. We show that the problem for C3 is polynomial and for each C with ≥ 4 is NP-complete. Our results imply that the stable transversal problem for each C with ≥ 4 remains NP-complete when it is restricted to line graphs. We show by contrast that the stable transversal problem for C3 , when restricted to line graphs, is polynomial. Keywords: Stable transversal problem, transverse matching problem, algorithm, complexity.

1

Introduction

For a ﬁxed graph H, an H-transversal of a graph G is a vertex set T that meets every induced copy of H in G; in other words, G − T does not contain H as an induced subgraph. When such a set T is a stable set, it is called a stable Htransversal of G. While every graph has an H-transversal, stable H-transversals may not exist in a graph. The stable H-transversal problem ST(H) for a ﬁxed H asks whether a graph has a stable H-transversal. It is easy to see that a graph has a stable K2 -transversal if and only if it is bipartite and it has a stable K2 -transversal if and only if it is a split graph (cf. [4]). As both bipartite and split graphs are recognizable in polynomial time, ST(H) is polynomial when H has at most two vertices. Farrugia [3] proved that ST(H) is NP-complete when H has at least three vertices and is connected. It C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 135–143, 2011. c Springer-Verlag Berlin Heidelberg 2011

136

R. Churchley, J. Huang, and X. Zhu

follows that ST(C ) is NP-complete when ≥ 3, where C denotes the cycle with vertices. For graphs which have at least three vertices and are disconnected, there are polynomial as well as NP-complete cases, but the dichotomy of stable transversal problems has not been determined. Stable transversal problems have also been studied for various classes of graphs, cf. [7,9]. In this paper, we investigate an ‘edge version’ of stable transversal problems. The H-transverse matching problem TM(H) for a ﬁxed graph H asks whether a graph G has a matching M which meets every (not necessarily induced) copy of H in G, i.e., H is not a subgraph of G − M . Such a matching M will be called an H-transverse matching. We shall prove the following: Theorem 1. TM(C ) is polynomial when = 3 and NP-complete otherwise. Given a graph G = (V, E), the line graph L(G) of G is the graph with vertex set E and two vertices adjacent in L(G) if and only if the two corresponding edges have a common endvertex in G. With the sole exception of H = C3 , the transverse matching problem TM(H) is equivalent to the stable transversal problem ST(L(H)) for line graphs. Since L(H) = C if and only if H = C for each ≥ 4, Theorem 1 implies that ST(C ) remains NP-complete for line graphs for each ≥ 4. Due to the fact that C3 is the line graph of two diﬀerent graphs C3 and K1,3 , ST(C3 ) is not equivalent to TM(C3 ) for line graphs. However, we show that determining whether a graph G has a matching M which meets every copy of C3 and K1,3 in G is polynomial. Hence the problem ST(C3 ) is polynomial for line graphs and therefore we also obtain the following: Theorem 2. When restricted to line graphs, ST(C ) is polynomial for = 3 and NP-complete otherwise. We remark that the polynomial case stated in Theorem 2 is in sharp contrast to the fact that ST(C3 ) is NP-complete in general.

2

TM(C3 ) and ST(C3 ) for Line Graphs are Polynomial

A paw is the graph consisting of a triangle and an edge sharing a common vertex. Call a matching M pawssible if, for every paw consisting of triangle xyz and edge xw, xw ∈ M implies yz ∈ M . The lemma below follows immediately from the fact that any C3 -transverse matching contains at least one of the three edges in each triangle and is pawssible. Lemma 3. If a graph G has a C3 -transverse matching, then at least one of the three edges in each triangle is contained in a pawssible matching. In polynomial time we can check whether an edge e of G is contained in a pawssible matching and ﬁnd one if it exists. This can be done by letting Fe = {e} initially, then adding edges one by one to Fe which are ‘forced by’ paws, and ﬁnally checking if Fe is a matching. In the case when Fe is a matching, it is also a minimal pawssible matching containing e.

Cycle Transverse Matching Problems

137

Lemma 4. Suppose that M is a pawssible matching and e is an edge in G. If both M ∪ {e} and Fe are matchings, then M ∪ Fe is a pawssible matching where Fe is defined as above. Proof. From the deﬁnition of Fe , M ∪Fe may be viewed as the set obtained from M by including e initially and then adding edges which are ‘forced by’ paws. The process of adding edges ensures that M ∪ Fe is pawssible. We claim that it produces a matching. Indeed, suppose that a paw consists of triangle xyz and edge xw such that M ∪ {xw} is a matching. Since M is pawssible, M does not contain any edge incident with y or z as otherwise M would contain xz or xy, contradicting the assumption that M ∪ {xw} is a matching. Hence M ∪ {xw, yz} is also a matching. This means that the process of adding edges always produces matchings. So M ∪ Fe is a matching. Theorem 5. A graph G has a C3 -transverse matching if and only if every triangle has an edge that is contained in a pawssible matching. Proof. The necessity is treated in Lemma 3. For suﬃciency, suppose that every triangle has an edge that is contained in a pawssible matching. The assumption implies in particular that every triangle has an edge e for which Fe is a pawssible matching. We apply the following algorithm to construct a set M of edges in G: Initially, M = ∅. As long as G − M contains a triangle, ﬁnd an edge e which is contained in a triangle in G − M and for which Fe is a matching and enlarge M to include Fe . Clearly, the set M contains at least one edge from each triangle in G. Lemma 4 ensures that M obtained by the algorithm is a matching. Therefore M is a C3 -transverse matching in G. Theorem 5 and its proof suggest a polynomial time algorithm which determines if a graph G has a C3 -transverse matching and constructs one if it exists: We ﬁrst compute Fe for each edge e of G as described above. If for some triangle xyz, none of Fxy , Fyz , Fxz is a matching, then G does not have a C3 -transverse matching according to Theorem 5. Otherwise, the algorithm in the proof of Theorem 5, which can be implemented in polynomial time, constructs a C3 transverse matching. Corollary 6. TM(C3 ) is polynomial.

Next we show how to determine, in polynomial time, whether a graph has a matching which meets every copy of C3 and of K1,3 . It is well-known that a perfect matching (if exists) can be found in polynomial time (cf. [2,8]). We can apply such an algorithm to determine if a graph has a matching covering speciﬁed vertices. Lemma 7. Given a graph G and vertex set S, it can be determined in polynomial time whether G has a matching covering every vertex of S.

138

R. Churchley, J. Huang, and X. Zhu

Proof. We show how to convert the problem in the lemma into the problem of ﬁnding a perfect matching. Let G be a (disjoint) copy of G with f : G → G an isomorphism. Let G∗ be obtained from G ∪ G by adding the edge vf (v) if v ∈ V (G) − S. If M is a matching of G covering every vertex of S, then M ∪ f (M ) ∪ {vf (v) : v is not covered by M } is a perfect matching of G∗ . Conversely, any perfect matching of G∗ restricts to a desired matching of G. Thus G has a matching covering every vertex of S if and only if G∗ has a perfect matching. Clearly, no graph of maximum degree ≥ 4 contains a matching which meets every copy of K1,3 . So we may restrict the search of a matching among graphs of maximum degree at most three (i.e., subcubic graphs). Proposition 8. There exists a polynomial time algorithm to determine whether a subcubic graph has a matching that meets every copy of C3 and of K1,3 . Proof. We may assume without loss of generality that G is connected. We show how to reduce the problem in the proposition to the problem of determining whether a graph has a matching covering speciﬁed vertices, which can be solved in polynomial time according to Lemma 7. Speciﬁcally, we will construct a subcubic graph G and a set S ⊆ V (G ) such that G has a desired matching if and only if G has a matching covering S. Initially, we let G = G and let S consist of all vertices of degree 3 in G . If G has no triangle, then G together with S satisfy the desired properties. So assume that G contains triangles. We modify G and the set S recursively for every triangle. Each modiﬁcation on a triangle results in a subcubic graph and maintains the property that S consists of all vertices of degree three. Moreover, any matching covering S in the resulting graph must meet the triangle. Let abc be a triangle in G and a , b , c be the only other neighbours of a, b, c respectively, if they exist. If a , b , c exist and are the same vertex, then the graph is K4 which has a desired matching. If, without loss of generality, a = b exist and are distinct from c (if it exists), then we do nothing. Any matching covering a, b (which are in S) in the resulting graph meets the triangle abc. On the other hand, if a , b , c exist and are distinct we contract the triangle, identifying the vertices a, b, c in G and in S. Finally, if a , b , c are distinct but do not all exist, we contract the triangle but also remove the identiﬁed vertex from S. Clearly, G has a desired matching if and only if the resulting graph has a desired matching. By repeating the above reduction for every triangle in G , we either obtain K4 (in which case G has a desired matching) or a graph G and a set S such that G has a desired matching if and only if G has a matching covering S. Corollary 9. ST(C3 ) for line graphs is polynomial.

3

TM(C4 ) is NP-Complete

In this section, we show that TM(C4 ) is NP-complete even when it is restricted to bipartite graphs.

Cycle Transverse Matching Problems

139

Proposition 10. TM(C4 ) for bipartite graphs is NP-complete. Proof. We reduce from 4-SAT, which is well-known to be NP-complete [5]. Let C = {c1 , . . . cq } be a set of clauses each consisting of four variables from A = {a1 , a2 , . . . , ap , a1 , . . . , ap }. A valid truth assignment for C is a function f : A → {0, 1} such that f (ai ) = f (ai ) and f −1 (1) ∩ cj = ∅ for every i = 1, . . . p and j = 1, . . . , q. In other words, ai is the negation of ai and every clause has at least one true variable. We construct in polynomial time a bipartite graph H which admits a C4 -transverse matching if and only if such a satisﬁability function exists. There are two main gadgets in our reduction: one corresponding to each variable and one corresponding to each clause. The variable gadgets (see Fig. 1, upper left) are constructed as follows. Associate each ai , 1 ≤ i ≤ p with a path w0i w1i w2i w3i w4i ; three vertices v1i , v2i , v3i adjacent to w0i and w2i , w1i and w3i , and w2i and w4i , respectively; three more vertices ui1 , ui2 , ui3 ; and nine vertices i i i vk,1 , vk,2 , vk,3 each adjacent to the respective uik and vki . It is easy to check that the gadget admits C4 -transverse matchings containing w0i w1i and w2i w3i , or containing w1i w2i and w3i w4i , and that any such matching contains one of those pairs. The clause gadgets (see Fig. 1), on the other hand, are somewhat simpler than the variable gadgets. Each clause cj ∈ C is associated with a C8 : sj1 tj1 sj2 tj2 sj3 tj3 sj4 tj4 and two additional vertices r1j , r2j adjacent to tj1 , tj2 , tj3 and tj2 , tj3 , tj4 , respectively. It turns out that this gadget has a C4 -transverse leaving any three of si1 , si2 , si3 , si4 uncovered, but no C4 -transverse matching leaving all four uncovered. We complete the construction of H by connecting the clause gadgets to the variable gadgets. Let cj = {aj1 , aj2 , aj3 , aj4 }. If ajk = ai , add two new vertices xjk , ykj and edges xjk ykj , sjk ykj , w2i ykj , w1i xjk and w3i sjk (thus w1i w2i w3i sj2 ykj xjk is a C6 : see Fig. 1). On the other hand, if ajk = ai , do the same thing with the roles of w1i and w3i reversed. Suppose the resulting graph H has a C4 -transverse matching M . We interpret M as a truth assignment f according to its intersection with each variable gadget, setting 0 if w1i w2i , w3i w4i ∈ M f (ai ) = 1 if w0i w1i , w2i w3i ∈ M and f (ai ) = f (ai ). We must show that f −1 (1) ∩ cj = ∅ for all j = 1, . . . q. The above discussion of the clause gadgets implies that, for a ﬁxed j, the matching M contains at most three of the four edges sjk ykj , k = 1, 2, 3, 4; as M must cover at least one sjk with an edge from the clause gadget associated with cj . Suppose that ai = ajk ∈ cj . The above discussion of the variable gadgets implies that neither w2i ykj nor w3i sjk is in M , and since M covers the C4 : w2i w3i sjk ykj it must be the case that w2i w3i ∈ M . Consequently, ai ∈ f −1 (1) ∩ cj . A similar argument applies when ai = ajk ∈ cj , showing that ai ∈ f −1 (1) ∩ cj . It follows that f is a satisﬁability function. Conversely, suppose that f is a satisﬁability function for the clauses C. Then, as mentioned above, we can extend

140

R. Churchley, J. Huang, and X. Zhu

Fig. 1. Connecting the gadget corresponding to clause cj = {aj1 , aj2 , aj3 , aj4 } (right) with the gadget corresponding to the variable ai = aj2 (upper left)

M ={w1i w2i , w3i w4i : f (ai ) = 0} ∪ {w0i w1i , w2i w3i : f (ai ) = 1} ∪ {ykj sjk : f maps the kth variable in clause cj to 0} to a Ck -transverse matching of H, using the fact that M leaves at least one sjk uncovered for every j, and the clause gadget has a Ck -transverse matching leaving the other three uncovered. Finally, H has bipartition (X, V (H) \ X), where i i i , vk,2 , vk,3 : i = 1, . . . , p; k = 1, 2, 3} X = {w0i , w2i , w4i , vk,1

∪ {xjk , sjk : j = 1, . . . , q; k = 1, 2, 3, 4}. The construction of H takes O(p+q) time, so this reduction is polynomial. Therefore, the C4 -transverse matching problem for bipartite graphs is NP-complete.

4

TM(C) is NP-Complete for ≥ 5

A broadly similar approach can be taken to show that TM(C ) is NP-complete for each ≥ 5. As the variable gadgets are slightly diﬀerent depending on whether is odd or even, we treat these cases separately. However, both cases depend on the following useful structure. A u-v accordion path consists of edge-disjoint u-v paths ux1 w1 x2 . . . wk xk+1 v, uy1 w1 y2 . . . wk−1 yk v, and uy1 w1 y2 . . . wk yk+1 v, each having the same (even) length and sharing every second vertex. An example is given in Fig. 2. The length of an accordion path is the length (i.e. number of edges) of any of the paths comprising it. The importance of accordion paths comes from the following observation: any matching in a u-v accordion path fails to cover some u-v path of the same length k. More importantly, if a graph contains such an accordion path and an additional u-v path P of length − k, then any C -transverse matching contains at least one of the edges of P . We will ﬁnd this property very useful when constructing our gadgets.

Cycle Transverse Matching Problems

141

Fig. 2. An accordion path of length 6

Proposition 11. TM(C ) for bipartite graphs is NP-complete when ≥ 6 is even. Proof. The reduction is from 2 -SAT, using a similar strategy as the one in the previous section. This time, the clause gadget corresponding to each cj is simply a C : sj1 tj1 . . . sj/2 tj/2 . By deﬁnition, any C -transverse matching of the resulting graph contains at least one edge of this cycle and hence covers at least one sjk . The variable gadget corresponding to ai consists of a path w0i w1i w2i w3i w4i and three disjoint accordion paths of length − 2 from w0i to w2i , from w1i to w3i , and from w2i to w4i . The only minimal C -transverse matchings of this gadget are {w0i w1i , w2i w3i } and {w1i w2i , w3i w4i }. We connect the variable gadgets to the clause gadgets as follows. If cj = {aj1 , aj2 , aj3 , aj4 } and ajk = ai , add three new vertices xjk , ykj , zkj , edges xjk ykj , sjk ykj , w0i xjk , w1i zkj , w3i sjk , and an accordion path of length − 4 from zkj to ykj . Likewise, if ajk = ai , do the same except adding edges w1i sjk and w3i xjk instead of w3i sjk and w1i xjk . This process is illustrated in Fig. 3. As in the previous section, we can interpret a C4 -transverse matching M of the resulting bipartite graph H as a truth assignment f by 0 w1i w2i , w3i w4i ∈ M f (ai ) = 1 w0i w1i , w2i w3i ∈ M and f (ai ) = f (ai ). A similar argument to that in the proof of Proposition 10 shows that f is a satisﬁability function for C. Likewise, a satisﬁability function can be used to construct a C -transverse matching for H. The graph H is easily seen to be bipartite. When is odd, we can use a nearly identical reduction and proof to show that TM(C ) is NP-complete. The graph produced by the reduction is not bipartite in this case, for any matching in a bipartite graph is C transverse for odd . Proposition 12. TM(C ) is NP-complete when ≥ 5 is odd. Proof. We only describe the construction of H from an instance C of (k+1) 2 SAT. As in the proof of Proposition 11, the gadget corresponding to each clause cj is a cycle C : sj1 tj1 sj2 tj2 . . . sj(k+1)/2 . Each variable ai corresponds to a path w0i w1i w2i w3i w4i in such a way that any C -transverse matching contains either {w0i w1i , w2i w3i } or {w1i w2i , w3i w4i }; to ensure this property we add vertices ui , v i ,

142

R. Churchley, J. Huang, and X. Zhu

Fig. 3. Connecting the cycle corresponding to clause cj to the variable gadget corresponding to ai . Dashed lines indicate accordion paths.

edges ui w2i , ui w3i , ui w4i and ui vi , an accordion path of length − 1 from ui to v i , and accordion paths of length −3 from w0i , w1i , and w2i to ui . (See Fig. 4). As desired, the minimal C -transverse matchings of this gadget are {w0i w1i , w2i w3i , ui v i } and {w1i w2i , w3i w4i , ui v i }. The clause gadgets are connected with the appropriate variable gadgets in nearly the same way as in Proposition 11. If cj = {aj1 , aj2 , aj3 , aj4 } and ajk = ai , add two new vertices xjk , ykj , edges xjk ykj , sjk ykj , w0i xjk , w3i sjk , and an accordion path of length − 3 from w1i to ykj ; if ai is negated in cj , replace the edges w3i sjk and w1i xjk with w1i sjk and w3i xjk . The same argument of Propositions 10 and 11 shows that the resulting graph -SAT H has a C -transverse matching if and only if the original instance of (+1) 2 (+1) has a satisﬁability function. When ≥ 5, 2 -SAT is NP-complete. Therefore, the C -transverse matching problem is NP-complete.

Fig. 4. Connecting the cycle corresponding to cj to the variable gadget for ai . Dashed lines in the left-hand gadgets indicate accordion paths.

Cycle Transverse Matching Problems

5

143

Conclusion and Further Remarks

Theorem 1 follows from Corollary 6 and Propositions 10, 11, and 12. Theorem 2 follows from Theorem 1, Corollary 9, and the fact that ST(C ) for line graphs is equivalent to TM(C ) for each ≥ 4. We have classiﬁed in this paper the complexity of the transverse matching problems for cycles of ﬁxed lengths. Brandst¨adt [1] proved that determining whether a graph has a stable set which meets every cycle in the graph is an NP-complete problem even when it is restricted to bipartite graphs. We remark that an edge version of this problem is also NP-complete. Consider the class C of subcubic planar graphs having exactly two two vertices of degree two. It is an NP-complete problem to determine whether a graph in C contains a Hamiltonian path joining the two vertices of degree two [6]. Observe that such a path exists if and only if there is a matching that meets every cycle in the graph. Hence determining whether a graph in C contains a matching that meets every cycle in the graph is an NP-complete problem. Acknowledgements. The ﬁrst author would like to thank NSERC for the support through a Canadian Graduate Scholarship award. The second author would also like to thank NSERC for the support and is grateful to the hospitality from Department of Mathematics, Zhejiang Normal University - part of research was carried out during his visit to the department. The research of the third author is supported under grant ZJNSF NO. Z6110786. Finally, all three authors would like to thank Dr. Frank Ruskey for originally bringing the transverse matching problems to their attention.

References 1. Brandst¨ adt, A.: Partitions of graphs into one or two independent sets and cliques. Discrete Math. 152, 47–54 (1986) 2. Edmonds, J.: Paths, trees, and flowers. Canad. J. Math. 17, 449–467 (1965) 3. Farrugia, A.: Vertex-partitioning into fixed additive induced-hereditary properties is NP-hard. Electron. J. Combin. 11 (2004) 4. Foldes, S., Hammer, P.L.: Split graphs. In: Proc. 8th South-Eastern Conf. on Combinatorics, Graph Theory and Computing, pp. 311–315 (1977) 5. Garey, M.R., Johnson, D.S.: Computers and Intractability. W.H. Freeman and Company, San Francisco (1979) 6. Garey, M.R., Johnson, D.S., Tarjan, R.E.: The planar Hamiltonian circuit problem is NP-complete. SIAM J. Comput. 5, 704–714 (1976) 7. Ho´ ang, C.T., Le, V.C.: On P4 -transversals of perfect graphs. Discrete Math. 216, 195–210 (2000) 8. Micali, S., Vazirani, V.: An O( |V | · |E|) algorithm for finding maximum matching in general graphs. In: Proc. 21st IEEE Symp. Foundations of Computer Science, pp. 17–27 (1980) 9. Stacho, J.: On P4 -transversals of chordal graphs. Discrete Math. 308, 5548–5554 (2008)

Eﬃcient Conditional Expectation Algorithms for Constructing Hash Families Charles J. Colbourn Computing, Informatics, and Decision Systems Engineering Arizona State University PO Box 878809 Tempe, AZ 85287-8809, U.S.A. Charles.Colbourn@asu.edu

Abstract. Greedy methods for solving set cover problems provide a guarantee on how close the solution is to optimal. Consequently they have been widely explored to solve set cover problems arising in the construction of various combinatorial arrays, such as covering arrays and hash families. In these applications, however, a naive set cover formulation lists a number of candidate sets that is exponential in the size of the array to be produced. Worse yet, even if candidate sets are not listed, finding the ‘best’ candidate set is NP-hard. In this paper, it is observed that one does not need a best candidate set to obtain the guarantee — an average candidate set will do. Finding an average candidate set can be accomplished using a technique employing the method of conditional expectations for a wide range of set cover problems arising in the construction of hash families. This yields a technique for constructing hash families, with a wide variety of properties, in time polynomial in the size of the array produced.

1

Introduction

Let X be a ﬁnite set of size n, and let B be a collection of subsets of X. A set cover for the set system (X, B) is a collection B ⊆ B so that ∪B∈B B = X. Finding the smallest set cover is NP-hard [15], and hence approximation and heuristic techniques have been developed. Stein [20], Lov´ asz [16], and Johnson [14] (see also [5]) analyze a greedy algorithm and establish a useful upper bound on the sizes of set covers that it produces; we review the Stein-Lov´ asz-Johnson theorem and its constructive proof in Section 2. In terms of the sizes of X and B, the greedy method that they employ requires only polynomial run time. The Stein-Lov´ asz-Johnson method has been applied in establishing upper bounds on the sizes of numerous combinatorial arrays. In these contexts, however, the admissible sets B are often known implicitly rather than presented explicitly. Then the size of the input is simply |X|, and the run time of the greedy algorithm may be exponential in |X|, because |B| may be exponentially large with respect to |X|. This has limited the practical uses of such greedy methods for the actual construction of the set covers needed to produce the corresponding C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 144–155, 2011. c Springer-Verlag Berlin Heidelberg 2011

Conditional Expectation Algorithms

145

combinatorial arrays. Despite this, the Stein-Lov´asz-Johnson paradigm has been used to develop methods whose run time is polynomial in |X|. One method is to list only a small subset of the sets [7]. Another method employs an implicit representation of all of the sets; we outline two instances next. A ﬁrst example arises with covering arrays. Let N , k, t, and v be positive integers. Let C be an N × k array with entries from an alphabet Σ of size v; we typically take Σ = {0, . . . , v − 1}. When (ν1 , . . . , νt ) is a t-tuple with νi ∈ Σ for 1 ≤ i ≤ t, (c1 , . . . , ct ) is a tuple of t column indices (ci ∈ {1, . . . , k}), and ci = cj whenever νi = νj , the t-tuple {(ci , νi ) : 1 ≤ i ≤ t} is a t-way interaction. The array covers the t-way interaction {(ci , νi ) : 1 ≤ i ≤ t} if, in at least one row ρ of C, the entry in row ρ and column ci is νi for 1 ≤ i ≤ t. Array C is a covering array CA(N ; t, k, v) of strength t when every t-way interaction is covered. The goal here is to minimize N for given values of t, k, and v. Existence of a CA(N ; t, k, v) can be formulated as a set cover problem as follows. indices, let Σ be a set of size v, and let Let K be a set of k column X = Kt × Σ t . Then |X| = kt v t . Form a set B of v k sets as follows. The set corresponding to the k-tuple (x1 , . . . , xk ) ∈ Σ k contains element {γ1 , . . . , γt } × (ν1 , . . . , νt ) (where γi < γi+1 for 1 ≤ i < t) exactly when xγi = νi for 1 ≤ i ≤ t. k−t sets in B, and every set in B has size Every element of X appears in exactly v k . By the Stein-Lov´ a sz-Johnson theorem, there exists a CA(N ; t, k, v) with t k k vk t N ≤ vk−t (1 + ln t ) = v (1 + ln t ). A similar result was established in [6] without recourse to the Stein-Lov´asz-Johnson theorem. An explicit presentation of the set system involves listing vk kt elements, but X contains ‘only’ kt v t elements. When v and t are ﬁxed, the size of X is a polynomial in k. Still the number of sets in B remains exponential in k. In the speciﬁc case of covering arrays, Cohen et al. [6] exploit the fact that we need not list all sets in B. Rather we can generate sets one at a time, as needed. After some sets have been generated (each corresponding to rows of a partial covering array), certain elements are covered by sets already selected and the remaining elements are uncovered. Following the Stein-Lov´asz-Johnson paradigm, the next set to be selected should be one that covers the largest number of previously uncovered elements. There may be no need to list all possible sets explicitly in order to select one that covers this maximum number. Unfortunately, given a speciﬁc set of uncovered elements, it is not clear how to ﬁnd a set that covers the maximum number eﬃciently (in time polynomial in the number of elements). Indeed, in the covering array situation, this problem is itself NP-hard [3], even when t = 2. For covering arrays, Bryce and Colbourn [3,4] nevertheless developed an eﬃcient (time polynomial in k for ﬁxed v and t) algorithm for generating covering arrays with a number of rows meeting that of the Stein-Lov´ asz-Johnson theorem. To do this, they made two improvements. First they showed that the same bound is obtained when one chooses a set that covers the average number of uncovered elements at each stage, rather than the maximum. Then they developed a ‘density’ method (a form of the ‘method of

146

C.J. Colbourn

conditional expectations’, to be described in Section 5) to produce a set that covers at least the average number at each step, and to do so eﬃciently. A second example also involves an implicit representation of the sets. A hash family HF(N ; k, v), A = (aij ), is an N × k array; each cell contains one symbol from a set Σ of v symbols. A perfect hash family PHF(N ; k, v, t) is an HF(N ; k, v), in which in for every set C of at most t columns, there exists a row ρ for which |{aρc : c ∈ C}| = |C|. These have been explored for numerous applications (see [12,21], for example). Although perfect hash families were ﬁrst studied for applications in hashing [17], our reasons for interest in them are quite diﬀerent (see [9] for the principal applications in which we are interested). Hence this paper does not discuss the use of such hash families for hashing, despite their name. Take K to be a set of k column indices and X = Kt . Form a set B of vk sets, one for each k-tuple in Σ k . The set corresponding to the k-tuple (x1 , . . . , xk ) ∈ Σ k contains element {γ1 , . . . , γt } exactly when |{xγi : 1 ≤ i ≤ t}| = t. Then every element belongs to v k−t · v · (v − 1) · · · · · (v − t + 1) sets. Every set covers at most k by the Stein-Lov´ asz-Johnson theorem we ﬁnd that N ≤ t elements, and hence vt ln kt . Once again this yields an exponential time method. But 1+ v(v−1)···(v−t+1) again by showing that it suﬃces to ﬁnd a set that covers an average number of uncovered elements and developing a method of conditional expectations to ﬁnd such a set, Colbourn [8] developed an eﬃcient (time polynomial in k for ﬁxed t) algorithm for for the construction of perfect hash families with a number of rows meeting the given bound. Unfortunately, in each case the analysis is speciﬁc to the problem at hand: Diﬀerent proofs are employed both to show that it suﬃces to select a set for inclusion that covers at least the average number of uncovered elements, and to show that such a set can be found in time polynomial in |X|. Here we establish a substantial generalization of both methods. In Section 2, we review the statement and proof of the Stein-Lov´asz-Johnson theorem. Then we demonstrate that it always suﬃces to choose a set that covers the average number of elements in order to achieve the bound in the SteinLov´asz-Johnson theorem. This observation, while quite easy, seems not to have been explicitly stated or used in the literature. In Section 3, we describe numerous variants of hash families. Then in Section 4 develop a greedy construction method for these many variants. In Section 5, we apply the method of conditional expectations to make the construction of hash families eﬃcient.

2

The Stein-Lov´ asz-Johnson Paradigm

A greedy strategy for set cover problems has been widely used, starting with work of Stein [20], Lov´asz [16], and Johnson [14]. We give (one version of) the algorithm in Figure 1. The size of the set cover can be viewed either as the smallest value of i for α which we encounter Yi = 0, or it can be viewed as i=0 i , taking i = |Mi |. We consider the latter expression. First, ni−1 = ni −ii, and hence i = (ni −ni−1 )/i.

Conditional Expectation Algorithms

147

Greedy Set Cover(X, B): (|X| = n; |B| = c) Set r(x) = |{B : x ∈ B ∈ B}| for x ∈ X Set α = max{|B| : B ∈ B} and r = min{r(x) : x ∈ X} Set Mj = ∅ for 0 ≤ j ≤ α Set D0 = B and Y0 = X Set nα = |X| Set L = ∅ and i = 0 while Yi = ∅ do Set γi = |Di |; ρi = |Yi |; and αi = max{|B| : B ∈ Di } If i > 0 and αi < αi−1 set nαi = |Yi | Choose a set Di ∈ Di for which |Di | ≥ αi Set L = L ∪ {Di } Set Mαi = Mαi ∪ {Di } Set Yi+1 = Yi \ Di Set Di+1 = {B \ Di : B ∈ Di , B ⊆ Di } Set i = i + 1 Set n0 = 0 return L Fig. 1. The Greedy Algorithm

Because in each set system (Xi , Bi ), every element appears in at least r sets and every set has size at most i, rni ≤ ic. Moreover, α a n i−1 = i=1 i = i=1 i −n i nα−1 nα−2 n1 = nαα + α(α−1) + (α−1)(α−2) + · · · + 2·1 − n0 α 1 n Combining these, we obtain ≤ α + rc i=2 i , which yields the bound in the theorem of Stein [20], Lov´asz [16], and Johnson [14]: Theorem 1. [Stein-Lov´ asz-Johnson] Let (X, B) be an set system with |X| = n and |B| = c so that |B| ≤ α for every B ∈ B and |{B : x ∈ B ∈ B}| ≥ r for every x ∈ X. Then there is a collection B ⊆ B forming a set cover with sets n for some ≤ α + rc ln α ≤ rc (1 + ln α). A second analysis of Greedy Set Cover uses the fact that it terminates when Yi = ∅, or equivalently when ρi < 1. An element xj of Yi is not a member of ∪i−1 j=0 Dj , and hence r(xj ) is unchanged by the deletion of the elements already covered. Because r(xj ) ≥ r for all xj ∈ Yi , and γi ≤ c, the size of Di is at least rρi rρi c−r c . Then ρi+1 ≤ ρi − c = ρi c . Because this holds for every i > 0, we have c−r i i that ρi ≤ n c . We determine the smallest value of i for which n c−r < 1. c i c Equivalently, n < c−r . Taking logarithms base c/(c − r) of both sides, we have that logc/(c−r) n < i. This establishes: Theorem 2. Let (X, B) be an set system with |X| = n and |B| = c so that r(x) ≥ r for every x ∈ X. Then there is a collection B ⊆ B forming a set cover ln n with sets for some ≤ 1 + ln c/(c−r) .

148

C.J. Colbourn

This improves the constant in the bound over that of the Stein-Lov´ asz-Johnson c theorem when ln c−r ln α ≥ c−r ln n, but yields a weaker bound in other cases. c This apparent discrepancy is an artifact of the analyses, not the algorithms. When the set system (X, B) is provided as an explicit listing of the elements and sets, the running time of either method is a polynomial in the size of the input. Careful examination shows that the only operations that consider all of the sets in Di are the ones to select Di , and to remove all elements of Di to form Di+1 . To obtain an algorithm whose running time is polynomial in |X|, we cannot hope to examine (or even list) all sets in B. Our ﬁrst task, then, is to simplify the selection of the set Di . In fact, we show that selecting a set of average size yields the same results. At the same time, we equip B with a probability distribution, so that Pr[B] is the probability that set B ∈ B is selected. Average Set Cover(X, B): (|X| = n; |B| = c) Set r(x) = c {B∈B:x∈B} Pr[B] for x ∈ X x∈X r(x) Set r = min{r(x) : x ∈ X} and α = c Set Mj = ∅ for 0 ≤ j ≤ α Set D0 = B and Y0 = X Set nα = |X| Set L = ∅ and i = 0 while Yi = ∅ do

Set γi = |Di |; ρi = |Yi |; and αi =

x∈Yi

r(x)

c

If i > 0 and αi < αi−1 set nαi = |Yi | Choose a set Di ∈ Di for which |Di | ≥ αi and Pr[Di ] > 0 Set L = L ∪ {Di } Set Mαi = Mαi ∪ {Di } Set Yi+1 = Yi \ Di Set Di+1 = {B \ Di : B ∈ Di , B ⊆ Di } Set i = i + 1 Set n0 = 0 return L Fig. 2. The Average Algorithm

Average Set Cover, shown in Figure 2, is essentially the same method – with one important diﬀerence. Each set selected is only required to cover the average number of as yet uncovered elements of X rather than the maximum. Moreover, this average is weighted by the initial probability distribution selected on B. The analyses of Greedy Set Cover carry through for the average method as well. For the ﬁrst, we employed the fact that ni−1 = ni − ii , and hence i = (ni −ni−1 )/i; and the fact that rni ≤ ic. For the average method, ni−1 ≤ ni −ii , and hence i ≤ (ni − ni−1 )/i; and rni ≤ ic because i = rnc i . For the second, we employed only the fact that |Di | ≥ rρc i , which holds for the average method as well. Hence we have shown that

Conditional Expectation Algorithms

149

Theorem 3. Let (X, B) be a set system with |X| = n and |B| = c, for which Pr[B] is the probability that B ∈ B is selected. Let r(x) = c {B∈B:x∈B} Pr[B] x∈X r(x) and r = min{r(x) : x ∈ X}. Let β = . Then Average Set Cover c ln n produces a set cover B ⊆ B with sets, with ≤ min rc (1 + ln β), 1 + ln c/(c−r) . When the probability distribution is uniform (and in many other cases), β ≤ α, and hence Theorem 3 improves on Theorem 1. This may come as a surprise, because the original Stein-Lov´asz-Johnson method selects a largest set while the average method may select a smaller one. As we have noted, the discrepancy arises from the algorithm analysis, not from the algorithm itself. In practice, it is quite possible that selecting the maximum coverage yields a better result in the end that does selecting the average coverage. Nevertheless, Theorem 3 shows that the conclusion of Theorem 1 can be obtained by selecting the average. Whether the sets are listed explicitly or not, one potential beneﬁt of selecting a set with average rather than maximum coverage is that the average can be often be easily computed or bounded, and then ﬁnding any set with at least that average coverage suﬃces. We explore this next, for a broad class of combinatorial construction problems.

3

Variants of Hash Families

Let v = (v1 , . . . , vN ) be a tuple of positive integers. A hash family HF(N ; k, v), A = (aij ), is an N × k array; each cell contains one symbol, and for 1 ≤ ρ ≤ N , |{aρj : 1 ≤ j ≤ k}| ≤ vρ . When v1 = · · · = vN = v (i.e., the array is homogeneous), the result can be treated as an N × k array on v symbols; we employ the notation HF(N ; k, v). We permit heterogeneity here (i.e. that vi and vj are not necessarily equal when i = j), for two reasons. First, heterogeneity is useful in certain applications of hash families in so-called column replacement techniques [9,10,11]. Secondly, and more importantly, when we build a hash family one row at a time by the Stein-Lov´asz-Johnson strategy, it turns out to be an easy matter to change the number of permitted symbols in each row (by using a diﬀerent choice of Σ for each row). Naturally this renders the determination of the number of rows needed much more complicated, but it in no way complicates the algorithm for the construction of the hash family. Many variants of perfect hash families have been studied before. We mention a few, in order to indicate the types of requirements placed on the hash family. An HF(N ; k, v), A = (aij ), is perfect of strength t: denoted PHF(N ; k, v, t), when for every set C of at most t columns, there exists a row ρ for which |{aρc : c ∈ C}| = |C| (see [1,21], for example); (w1 , w2 , . . . , ws )-separating: denoted SHF(N ; k, v, (w1 , w2 , . . . , ws )), if when ever C is a set of si=1 wi columns and C1 , C2 , . . . , Cs is a partition of C with |Ci | = wi for 1 ≤ i ≤ s, there exists a row ρ for which aρx = aρy whenever x ∈ Ci , y ∈ Cj and i = j (see [2,22], for example).

150

C.J. Colbourn

W-separating: denoted SHF(N ; k, v, W) for W a set of tuples of nonnegative integers of the s form (w1 , w2 , . . . , ws ), if whenever (w1 , w2 , . . . , ws ) ∈ W, C is a set of i=1 wi columns, and C1 , C2 , . . . , Cs is a partition of C with |Ci | = wi for 1 ≤ i ≤ s, there exists a row ρ for which aρx = aρy whenever x ∈ Ci , y ∈ Cj and i = j (see [22], for example). (t, s)-distributing: denoted DHF(N ; k, v, t, s), if it is W-separating W conwith s taining every tuple (w1 , . . . , ws ) of nonnegative integers with i=1 wi = t. The deﬁnition of W-separating encompasses the remaining three, so we can treat this general situation. On occasion, we wish to further restrict the choice of rows that can be employed to provide the desired separation. There are at least two natural ways to do this. Let d = (d1 , . . . , dN ) and m = (m1 , . . . , mN ) be tuples of positive integers. An HF(N ; k, v), A = (aij ), is W-separating and d-scattering: if whenever (w1 , w2 , . . . , ws ) ∈ W, C is a set s of i=1 wi columns, and C1 , C2 , . . . , Cs is a partition of C with |Ci | = wi for 1 ≤ i ≤ s, there exists a row ρ for which aρx = aρy whenever x ∈ Ci , y ∈ Cj and i = j and the multiset {aρx : x ∈ C} contains no symbol more than dρ times. W-separating and m-strengthening: if whenever (w1 , w2 , . . . , ws ) ∈ W, C s is a set of i=1 wi columns, and C1 , C2 , . . . , Cs is a partition of C with |Ci | = wi for 1 ≤ i ≤ s, there exists a row ρ for which aρx = aρy whenever x ∈ Ci , y ∈ Cj and i = j and the multiset {aρx : x ∈ C} contains no more than mρ diﬀerent symbols. A justiﬁcation of the need for scattering or strengthening hash families is beyond the scope of this paper. Suﬃce it to say that O’Brien [19] proposed the scattering requirement and that strengthening generalizes the notion of (t, s)partitioning hash families (see [9]). There is evidently a wide variety of possible conditions that might be imposed on the hash family to be constructed, and we have surely not exhausted them here. To treat these and other variants, we proceed as follows. Let C = {γ1 , . . . , γt } be a set of columns. In constructing the ρth row, an alphabet Σρ of size vρ is available. A requirement is a partition of C into sets C1 , . . . , Cs . An assignment A ∈ Σρt for C is a determination of a value for each column in C. A constraint for requirement R is a logical predicate Pρ (A) : Σρt → {true, false}. In essence, a constraint speciﬁes which selections of symbols on the columns of C meet the requirement. A constraint could specify, for example, that a certain (w1 , . . . , ws )-separation is accomplished, that no more than mi symbols are used on these t columns, or that no symbol occurs more than di times. Indeed it could involve any combination of these, and a variety of other properties. The requirements in constructing a hash family are ﬁxed at the outset, but the constraints on meeting each requirement may vary depending on which row is being selected. Hence we employ constraints Pρ (A) for every assignment A to every requirement R, for 1 ≤ ρ ≤ N , in forming the hash family. From Theorem 3, one can immediately deduce bounds on the sizes of hash families in a general setting. We suppose that the candidate rows are selected

Conditional Expectation Algorithms

151

uniformly at random, and that the hash family needed is homogeneous with v symbols. Take c = vk and r = μvk in Theorem 3 to establish: Theorem 4. An HF(N ; k, v) satisfying q requirements exists whenever

1 ln q N ≥ min (1 + ln β), 1 + , μ ln 1/(1 − μ) taking δR to be the ratio of the number of assignments A to R that satisfy the constraint for R to the total number of assignments to R, μ to be the minimum of δR over all requirements R, and β to be the integer ceiling of the sum of δR over all requirements R. In Theorem 4, it may be puzzling that the bound does not appear to involve k. However, when requirements are placed on all of the k columns, the number q of requirements must be a function of k, and β is a function of q. The quantities in Theorem 4 can often easily be calculated; we give one example. Suppose that vi = v = 6, di = 3, and mi = 3 for 1 ≤ i ≤ N . Suppose that W = {(1, 4), (2, 3)}, and our objective is to produce a W-separating, d-scattering, and m-strengthening 1 HF(N ; k, 6). Write K = k(k − 1)(k − 2)(k − 3)(k − 4). There are k1 k−1 = 24 K 4 kk−2 1 requirements for the (1,4) separation, and 2 3 = 12 K for the (2,3) separation. Each has 65 = 7776 assignments. A (1,4) separation R has 840 separations 35 that meet the constraint, so δR = 324 . A (2,3) separation R has 510 separations 85 85 155 that meet the constraint, so δR = 1296 . Then μ = 1296 , and β = 15552 K. Then the hash family exists provided that N ≥ min

4

1296 (1 85

155K + ln 15552 ), 1 +

ln K 8 ln 1296 1211

.

Constructing a Hash Family

Following the paradigm of Average Set Cover, we proceed as follows. The set X is the set of all requirements, and N is (an upper bound on) the number of rows permitted. Then Average Hash Family(X, N, {Pρ (A, R)}), given in Figure 3, produces the desired hash family, or may fail if N is too small. Average Hash Family requires that we repeatedly select a next row for inclusion. For a requirement R ∈ Xρ , which is a set C = {γ1 , . . . , γt } of columns and a partition of C into sets C1 , . . . , Cs , and a candidate row x = (x1 , . . . , xk ) ∈ Σρk , R is covered by the row exactly when Pρ (Ax,R ) holds for the assignment Ax,R in which column γi contains symbol xγi for 1 ≤ i ≤ t. Select Average Row must ﬁnd a row x ∈ Σρk for which Pr[x] > 0 and |R ∈ Xρ : Pρ (Ax,R )}| is at least the average over all choices of row y. Suppose that we simply selected the row x at random (according to the probability distribution) from Σρk . Then Pr[x] > 0, and the expectation of |R ∈ Xρ : Pρ (Ax,R )}| is precisely the desired average, ⎛ ⎞ ⎛ ⎞ ⎝ P r[x] · ⎝ Pρ (Ax,R )⎠ = P r[x] · Pρ (Ax,R )⎠ , x∈Σρk

R∈Xρ

R∈Xρ

x∈Σρk

treating Pρ (Ax,R ) as a 0,1-indicator variable. This yields a randomized algorithm for producing hash families, but in some cases we can do better.

152

C.J. Colbourn

Average Hash Family(X, N, {Pρ (A, R)}) // {Pρ (A, R)} provides a predicate for each row ρ, each R ∈ X, // and each assignment A to R Set X1 = X and L = ∅ for ρ from 1 to N do y = Select Average Row(ρ, Xρ , {Pρ (A, R)}) Set L = L ∪ {y} Set Xρ+1 = Xρ \ {R ∈ Xρ : Pρ (Ay,R )} if XN +1 = ∅ return L else return fail Fig. 3. The Average Algorithm for Hash Families

5

The Method of Conditional Expectations

It suﬃces to calculate the expectation of Pρ (Ax,R ) for each R ∈ Xρ in order to determine the average sought. Nevertheless, we must also ﬁnd a row x ∈ Σρk that yields at least this average. To do this, we start with a row in which no entries have been chosen, and repeatedly choose one coordinate whose entry is unspeciﬁed in which to choose an entry. Our objective is to ensure that at each stage the expectation of ﬁnding a row that covers at least the average does not decrease. In other words, we want the conditional expectation, based on the selection of the entries already made, never to decrease. Hence we employ the fundamental idea in the method of conditional expectations [13,18]. We must deal with rows in which only some of the entries have been chosen. Suppose that (x1 , . . . , xk ) ∈ (Σρ ∪ { })k . We interpret an entry in Σρ to mean that the entry has been chosen, while the entry means that the entry has not yet been chosen. A row (y1 , . . . , yk ) ∈ Σρk is a completion of (x1 , . . . , xk ) if xi = yi or xi = for 1 ≤ i ≤ k. A row with s entries has vρs completions, and these are denoted by Bx . For two rows x and y, the probability that y occurs given that x occurs, Pr[y|x], is 0 whenever yi = xi but xi ∈ Σρ ; otherwise it is ( z∈By Pr[z])/( z∈Bx Pr[z]). The expected coverage ec(x) for a row x = (x1 , . . . , xk ) ∈ (Σρ ∪ { })k is z∈Bx Pr[z|x] · ( R∈Xρ Pρ (Az,R )). A row (y1 , . . . , yk ) ∈ (Σρ ∪ { })k is a j-successor of (x1 , . . . , xk ) if, for some 1 ≤ j ≤ k, it holds that xj = and yj ∈ Σρ , and that xi = yi for 1 ≤ i ≤ k when i = j. A row having a entry in the jth position has exactly vρ j-successors. Letting χ(R, x) be the probability that a completion z of x satisﬁes the predicate Pρ (Az,R ), we have ec(x) = R∈Xρ χ(R, x). The selection of a row is accomplished by Select Average Row in Figure 4, when furnished with a routine Expected Completions that calculates χ(R, x). r(i−1) has yγ = , and y(1) , . . . , y(vρ ) are its γ-successors, ec(r(i−1) ) = vWhen ρ (i) (i) (i−1) ) ≤ ec(r(i) ) for 1 ≤ i ≤ k. Now ec(r(0) ) is i=1 Pr[y |x]·ec(y ). Hence ec(r the expected number of elements of X covered by a row selected at random from Σρk according to the probability distribution. Moreover, ec(r(k) ) is the actual number of elements of X covered by the row r(k) , which therefore covers at least the expected number.

Conditional Expectation Algorithms

153

Select Average Row(ρ, Xρ , {Pρ (A, R)}) // {Pρ (A, R)} provides a predicate for each R ∈ X and assignment A to R Set r(0) = {}k for i from 1 to k do (i−1) Choose an coordinate γ for which rγ = Set maxcov = 0 and choice = ∅ for σ ∈ Σρ Let z be the γ-successor of r(i−1) with zγ = σ if Pr[z|r(i−1) ] > 0 Set cov = 0 for R ∈ Xρ cov = cov + Expected Completions(ρ, R, z) if cov ≥ maxcov {maxcov = cov; choice = z} Set r(i) = choice return r(k) Fig. 4. The Average Algorithm for Hash Families: Selecting a Row

It remains to compute χ(R, x) by Expected Completions for each requirement R and an arbitrary x ∈ (Σρ ∪ { })k . While this can be carried out for some diﬀerent probability distributions, in Figure 5 we treat only the case when the probability distribution is uniform. Expected Completions(ρ, R, x) // for the uniform distribution // R is the set C = {γ1 , . . . , γt } of columns and the partition C1 , . . . , Cs Let F = {γ ∈ C : xγ = } and F = C \ F Set count = 0 for each assignment A = {aγi : 1 ≤ i ≤ t} with aγi = xγi for γi ∈ F and aγi ∈ Σρ for γi ∈ F if Pρ (A, R) then count = count + 1 return count · (vρ )−|F | Fig. 5. The Average Algorithm for Hash Families: Expected Completions

Expected Completions relies on the fact whether or not a completion z of x satisﬁes predicate Pρ (Az,R ) depends only on the assignment to the coordinates C speciﬁed by R. Because every completion is equally probable, once the assignment to coordinates of C is speciﬁed, either every completion satisﬁes the predicate or none does. Therefore we can just treat each assignment to the coordinates of C. The routines in Figures 3, 4, and 5 implement the method of Figure 2 for a wide variety of hash families, producing a hash family of size no larger than that produced by applying the average algorithm directly. The improvement is that, by using a method of conditional expectations, the algorithm has running time polynomial in the number of requirements rather than the number of sets, when the (maximum) number of symbols v and the strength t are ﬁxed.

154

C.J. Colbourn

To see this, Expected Completions takes time O(v t ) = O(1). Then when there are r requirements, Select Average Row takes time O(k · v · r), but r is bounded by (kv)t , so the time is O(k t+1 ). When N rows are produced, Average Hash Family takes time O(N · k t+1 ). By Theorem 4, N is O(log k) when v and t are ﬁxed, and hence the running time is indeed a polynomial in k. (Surprisingly, the large constants suppressed in this analysis do not render the method impractical, as evidenced by [4,8]. But that is a story for another day.)

6

Conclusion

Being less greedy in solving set cover problems does not negate the guarantee on the size of the set cover obtained. Indeed, for general set cover problems, at each stage selecting a set that covers at least the average number of uncovered elements suﬃces. When all sets are listed explicitly, and all can be examined, ﬁnding a set with average coverage is not substantially easier than ﬁnding one with maximum coverage. However, if candidate sets are generated from a known probability distribution, ﬁnding – with high probability – a set with average coverage is an easy task. Focussing on set cover problems arising in the construction of hash families, we have shown that when the probability distribution is uniform, ﬁnding a set with average coverage admits an algorithm whose running time is polynomial in the size of the set cover produced. The method developed provides not only useful bounds on the sizes of hash families, but also an eﬃcient algorithm for their construction. We expect that this method will prove to be a practical one, in view of the similar but simpler method previously developed for perfect hash families [8]. Acknowledgments. Thanks to Daniel Horsley, Chris McLean, Peyman Nayeri, Devon O’Brien, and Violet Syrotiuk for helpful discussions. Thanks particularly to Daniel for suggesting the use of general probability distributions.

References 1. Alon, N.: Explicit construction of exponential sized families of k-independent sets. Discrete Math. 58, 191–193 (1986) 2. Blackburn, S.R., Etzion, T., Stinson, D.R., Zaverucha, G.M.: A bound on the size of separating hash families. J. Combin. Theory Ser. A 115(7), 1246–1256 (2008) 3. Bryce, R.C., Colbourn, C.J.: The density algorithm for pairwise interaction testing. Software Testing, Verification, and Reliability 17, 159–182 (2007) 4. Bryce, R.C., Colbourn, C.J.: A density-based greedy algorithm for higher strength covering arrays. Software Testing, Verification, and Reliability 19, 37–53 (2009) 5. Chv´ atal, V.: A greedy heuristic for the set-covering problem. Math. Oper. Res. 4(3), 233–235 (1979) 6. Cohen, D.M., Dalal, S.R., Fredman, M.L., Patton, G.C.: The AETG system: An approach to testing based on combinatorial design. IEEE Transactions on Software Engineering 23, 437–444 (1997) 7. Cohen, G., Litsyn, S., Z´emor, G.: On greedy algorithms in coding theory. IEEE Trans. Inform. Theory 42, 2053–2057 (1996)

Conditional Expectation Algorithms

155

8. Colbourn, C.J.: Constructing perfect hash families using a greedy algorithm. In: Li, Y., Zhang, S., Ling, S., Wang, H., Xing, C., Niederreiter, H. (eds.) Coding and Cryptology. World Scientific, Singapore (2008) 9. Colbourn, C.J.: Covering arrays and hash families. In: Information Security and Related Combinatorics. NATO Peace and Information Security, pp. 99–136. IOS Press (2011) 10. Colbourn, C.J., Torres-Jim´enez, J.: Heterogeneous hash families and covering arrays. Contemporary Mathematics 523, 3–15 (2010) 11. Colbourn, C.J., Zhou, J.: Improving two recursive constructions for covering arrays. Journal of Statistical Theory and Practice (2011) 12. Czech, Z.J., Havas, G., Majewski, B.S.: Perfect hashing. Theoret. Comput. Sci. 182, 1–143 (1997) 13. Erd˝ os, P., Selfridge, J.L.: On a combinatorial game. J. Combinatorial Theory Ser. A 14, 298–301 (1973) 14. Johnson, D.S.: Approximation algorithms for combinatorial problems. J. Comput. System Sci. 9, 256–278 (1974) 15. Karp, R.M.: Reducibility among combinatorial problems. In: Complexity of Computer Computations, pp. 85–103. Plenum, New York (1972) 16. Lov´ asz, L.: On the ratio of optimal integral and fractional covers. Discrete Math. 13(4), 383–390 (1975) 17. Mehlhorn, K.: Data Structures and Algorithms 1: Sorting and Searching. Springer, Berlin (1984) 18. Motwani, R., Raghavan, P.: Randomized algorithms. Cambridge University Press, Cambridge (1995) 19. O’Brien, D.J.: Exploring hash families and their applications to broadcast encryption. Master’s thesis, Arizona State University (2011) 20. Stein, S.K.: Two combinatorial covering theorems. J. Combinatorial Theory Ser. A 16, 391–397 (1974) 21. Stinson, D.R., Tran Van Trung, Wei, R.: Secure frameproof codes, key distribution patterns, group testing algorithms and related structures. J. Statist. Plann. Infer. 86, 595–617 (2000) 22. Stinson, D.R., Wei, R., Chen, K.: On generalized separating hash families. J. Combinat. Theory (A) 115, 105–120 (2008)

2-Layer Right Angle Crossing Drawings Emilio Di Giacomo1, Walter Didimo1 , Peter Eades2 , and Giuseppe Liotta1 1 Universit`a di Perugia, Italy {digiacomo,didimo,liotta}@diei.unipg.it 2 University of Sydney, Australia peter@cs.usyd.edu.au

Abstract. A 2-layer drawing represents a bipartite graph so that the vertices of each partition set are points of a distinct horizontal line (called a layer) and the edges are straight-line segments. In this paper we study 2-layer drawings where all edge crossings form right angles. We characterize which graphs admit this type of drawing, provide linear-time testing and embedding algorithms, and present a polynomial-time crossing minimization technique. Also, for a given graph G and a constant k, we prove that it is N P-complete to decide whether G contains a subgraph of at least k edges having a 2-layer drawing with right angle crossings.

1 Introduction The study of drawings of graphs where any two crossing edges form crossing angles that are not too small is among the emerging topics in Graph Drawing. This interest is motivated by recent experiments of Huang et al. [15,16], who show that crossing angles guarantee good readability properties only if they are “large enough” (approximatively larger than π3 ). These experiments therefore imply that non-planar drawings of graphs should not only be optimized in terms of classical parameters such as the number of edge crossings and the number of bends along the edges, but also in terms of the minimum angle formed by any two crossing edges. We study straight-line Right Angle Crossing drawings (or RAC drawings for short). In a RAC drawing any two crossing edges form π2 crossing angles. RAC drawings have been first introduced in [4], where it is proved that straight-line RAC drawings with n vertices have at most 4n−10 edges, which is a tight bound. Straight-line RAC drawings are also studied by Dujmovi´c et al. [7], who give an alternative proof of the 4n − 10 bound. The relationship between straight-line RAC drawings with 4n − 10 edges and 1-planar graphs is studied in [10]. Angelini et al. [2] investigate straight-line upward RAC drawings of digraphs. Van Kreveld [21] studies how much better a straight-line RAC drawing of a planar graph can be than any straight-line planar drawing of the same graph. Complete bipartite straight-line RAC drawable graphs are studied in [5]. Despite the growing literature about straight-line RAC drawings, no algorithms for computing such drawings have been described so far. Existing papers either establish combinatorial properties of RAC drawings (they typically address T´uran-type questions) or compute RAC drawings with bends along the edges. Also, deciding whether a

Work supported in part by MIUR of Italy under project AlgoDEEP prot. 2008TFBWL4.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 156–169, 2011. © Springer-Verlag Berlin Heidelberg 2011

2-Layer Right Angle Crossing Drawings

157

graph admits a straight-line RAC drawing is N P-hard in the general case [3] and it is not even known if this problem is in N P. In this paper we present the first efficient algorithms for straight-line RAC drawings. We focus on bipartite graphs and both consider the problem of deciding whether a bipartite graph admits a straight-line RAC drawing and the problem of computing one in the positive case. We also study how to efficiently compute straight-line RAC drawings of bipartite graphs with the minimum number of edge crossings. We adopt the widely accepted 2-layer drawing paradigm, in which the vertices of each partition set lie on a distinct horizontal layer. A limited list of papers on 2-layer drawings of bipartite graphs includes [9,13,17,20]; for more references see also [18]. A 2-layer RAC drawing is a 2-layer straight-line drawing with right angle crossings. An overview of our results is given below (n denotes the number of vertices of the input graph). – We characterize 2-layer RAC drawable graphs (Theorem 6). This is the counterpart for RAC drawings of the characterization of 2-layer planar drawings (see, e.g., [11,14,19]). Our characterization implies that 2-layer RAC drawings have at most 1.5n − 2 edges, which is a tight bound (Corollary 1); we also give an O(n)time algorithm that tests whether a graph has a 2-layer RAC drawing and, if so, it computes one. – We show an O(n2 log n)-time algorithm to compute a 2-layer RAC drawing with the minimum number of edge crossings (Theorem 7). The algorithm models the optimization problem as the one of computing a flow of minimum cost on a suitable network. We recall that computing a 2-layer drawing of a graph with the minimum number of crossings is N P-hard and that heuristics [9], approximation algorithms [13], FPT algorithms [6,8], and exact methods [17,20] for this problem have been described. – Finally, we study the complexity of computing the maximum 2-layer RAC drawable subgraph. We prove that for a given bipartite graph G and for a given k, it is N P-complete to decide whether G has a 2-layer RAC drawable subgraph with at least k edges (Theorem 8). This extends to RAC drawings the N P-completeness result for the maximum 2-layer planar subgraph problem [12].

2 Geometry and Combinatorics of 2-Layer RAC Drawings Let G = (V1 , V2 , E) be a bipartite graph. A 2-layer drawing of G has a fan crossing if there exist two adjacent edges that are both crossed by a third edge. For a given 2layer drawing of G, denote by i the horizontal line on which the vertices of Vi are drawn (i = 1, 2). We always assume that 1 is above 2 . Two 2-layer drawings of G are equivalent if they have the same left-to-right order πi of the vertices of Vi (i = 1, 2) along i . A 2-layer embedding is an equivalence class of 2-layer drawings and it is described by a pair of linear orderings (i.e., permutations) γ = (π1 , π2 ) of the vertices in V1 and V2 , respectively. If Γ is a drawing within class γ, we also say that γ is the embedding of Γ . Let Γ1 and Γ2 be 2-layer drawings of G with the same embedding γ. Two edges e and e cross in Γ1 if and only if they cross in Γ2 . We say that embedding γ has a crossing at edges e and e . Also, three edges e, e and e form a fan crossing in Γ1

158

E. Di Giacomo et al.

if and only if they form a fan crossing in Γ2 . Correspondingly, we say that embedding γ has a fan crossing at edges e, e , and e . Let γ = (π1 , π2 ) be a 2-layer embedding of a bipartite graph G. The first (last) vertex of π1 and the first (last) vertex of π2 are the leftmost vertices (rightmost vertices) of γ. The following result proves that the problem of computing a 2-layer RAC drawing of a bipartite graph G = (V1 , V2 , E) can be studied in purely combinatorial terms as the one of choosing a suitable pair (π1 , π2 ) of permutations of the vertices in V1 and V2 , disregarding details about the exact coordinates of the vertices. Theorem 1. Let G be a connected graph with n vertices. G is 2-layer RAC drawable if and only if it has a 2-layer embedding without fan crossings. Also, if γ is a 2-layer embedding of G without fan crossings, there exists an O(n)-time algorithm that computes a 2-layer RAC drawing of G with embedding γ. Sketch of Proof: The proof is by construction. The drawing algorithm assigns real coordinates to the vertices of G in such a way that the vertex ordering defined by γ on the two layers is preserved and each crossing edge has either 45-degree or -45-degree slope. Crossing edges have opposite slopes, so to form orthogonal crossings. A 2-layer embedding without fan crossings is a 2-layer RAC embedding. Based on Theorem 1, the problem of characterizing 2-layer RAC drawable graphs is equivalent to characterizing which graphs have a 2-layer RAC embedding. Note that, a graph is 2layer RAC drawable if and only if its connected components are 2-layer RAC drawable. Hence, from now on we assume to work on connected graphs. Given two vertices a and b of a path, we will denote by d(a, b) the distance between a and b on the path, that is, the number of edges from a to b along the path. Given a vertex v, the degree of v is the number of edges incident to v and is denoted as deg(v).

3 Characterization and Testing Algorithms We start by giving an intuition of the characterization of 2-layer RAC drawable graphs. In the more general case, a 2-layer RAC drawable graph consists of a set of non-trivial biconnected components1 and a set of tree components that are ordered along the two layers. Such an order is not, in fact, a total order because there can be some overlap between different tree components. For example, Fig. 1(b) shows a 2-layer RAC drawing of the graph G depicted in Fig. 1(a). G consists of two non-trivial biconnected components and five tree components (highlighted in Fig. 1(c)) that are ordered left-to-right along the two layers in the drawing; as shown in Fig. 1(d), the left-to-right order is not a total ordering because in some cases the tree components overlap as it happens for components T1 and T2 and for components T4 and T5 in the drawing of Fig. 1(b). In what follows we first characterize biconnected 2-layer RAC drawable graphs (Section 3.1), and then 2-layer RAC drawable trees (Section 3.2). These two characterizations will then be combined to characterize 2-layer RAC drawable graphs. The combination, however, is not straightforward because the drawings of the different components of G must satisfy additional properties in order to be assembled together. 1

A trivial biconnected component consists of a single edge.

2-Layer Right Angle Crossing Drawings 13

2

8 12

15

4

6

9

17

123 18 19

1 3

14

5

7

16

10

20

11

4

12 13 14

5

6

7 8 9 10

15

16

17

(a) 13

2

T1 T2 3

4 4

15

6

14

14

5

16

T3

17 17 17

B1

1

7

11

181920

(b) 8

12

159

T4 10

12

9

B2

10 20

18

12 19

10

T5

11

T1 3

T2

4

10 4

5

13

B1

14

15

T3

6

7

16

17 17 17

9 10

8

14

(c)

B2

10 18

11

T5

T4

19

20

(d) 9

1

5

2

3

6

7

4

8

(e)

1

6

3

8

9 5 9 2 9 7 9 4

9

(f)

Fig. 1. (a) A graph G. (b) A 2-layer RAC drawing Γ of G. (c) The biconnected components and the tree components of G. (d) The biconnected components and the tree components of G in Γ . (e) A graph G . (f) G does not admit a 2-layer RAC drawing.

In particular, it must be possible to order the components along the two layers in such a way that: (i) Each component shares vertices only with the components that immediately precede and follow it and with the components that overlap with it; (ii) The vertices shared by two consecutive components C1 and C2 (in this left-to-right order) must be the rightmost for C1 and the leftmost for C2 . For example, the graph G of Fig. 1(e) has a biconnected component (isomorphic to B1 in Fig. 1(c)) and a tree component (consisting of edge (3, 9)). Both components are 2-layer RAC drawable, but the biconnected component does not admit a 2-layer RAC drawing with the vertex 3 as leftmost or rightmost vertex; as a consequence whatever the position of vertex 9 will be, it is not possible to obtain a 2-layer RAC drawing of G (see Fig. 1(f)). For this reason, Sections 3.1 and 3.2 contain: (i) the characterizations of biconnected 2-layer RAC drawable graphs and 2-layer RAC drawable trees; (ii) the characterization of biconnected graphs that are 2-layer RAC drawable in such a way that two specified edges are the leftmost and the rightmost ones; (iii) the characterization of trees that are 2-layer RAC drawable so that two specified leaves are the leftmost and the rightmost ones. 3.1 Characterization of Biconnected Graphs Let G be a biconnected bipartite graph with at least two edges, and let e and e be two independent edges of G. If there exists a 2-layer RAC embedding γ of G such that the end-vertices of e are the leftmost vertices of γ and the end-vertices of e are the rightmost vertices of γ, we say that γ is a 2-layer RAC embedding of G with respect to e and e . Clearly, edges e and e cannot cross any edge in γ. A 2-layer RAC drawing with embedding γ is a 2-layer RAC drawing with respect to e and e . If G admits such a

160

E. Di Giacomo et al.

drawing, we say that G is 2-layer RAC drawable with respect to e and e (see Fig. 2(b)) A biconnected bipartite graph is a ladder if it consists of two paths of the same length u1 , u2 , . . . , u n2 and v1 , v2 , . . . , v n2 plus the edges (ui , vi ) (i = 1, 2, . . . , n2 ) (see Fig. 2(a)). The edges e = (u1 , v1 ) and e = (u n2 , v n2 ) are the extremal edges of the ladder. Theorem 2 characterizes those biconnected graphs that are 2-layer RAC drawable with respect to two independent edges. Theorem 3 is the counterpart of Theorem 2 without any fixed extremal edges. u1

u2

u3

u4

u5

u1 e

e v1

v2

v3

v4

v5

(a)

v2

u3

v4

e

e v1

u5

u2

v3

u4

v5

(b)

Fig. 2. (a) A ladder G. (b) A 2-layer RAC drawing of G with respect to e and e .

Theorem 2. Let G be a biconnected graph and let e and e be two independent edges of G. G is 2-layer RAC drawable with respect to e and e if and only if it is a spanning subgraph of a ladder with extremal edges e and e . Also, if G has n vertices, there exists an O(n)-time algorithm that tests whether G admits a 2-layer RAC drawing with respect to e and e and, if so, it computes such a drawing. Sketch of Proof: We prove that every 2-layer RAC embedding of G with respect to edges e and e is such that the edges of the external cycle are interlaced like shown in Fig. 2(b). These edges are the only edges that can cross in a 2-layer RAC drawing. Theorem 3. Let G be a biconnected graph. G is 2-layer RAC drawable if and only if it is a spanning subgraph of a ladder. Also, if G has n vertices, there exists an O(n)-time algorithm that tests whether G is 2-layer RAC drawable and, if so, it computes a 2-layer RAC drawing of G. 3.2 Characterization of Trees Roughly speaking, a 2-layer RAC drawing of a tree consists of a monotone “zig-zag” path between the two layers with some suitable sub-structures attached to its vertices (see Fig. 3(b)). In order to define the different types of sub-structures we define a sort of simplified version of the tree, called its weighted contraction. The characterization for trees relies on this concept. As explained at the beginning of this section, along with the characterization of 2-layer RAC drawable trees (Theorem 5), we give the characterization of 2-layer RAC drawable trees where two given vertices u and v are required to be a leftmost vertex and a rightmost vertex, respectively (Theorem 4). The latter characterization will be used in Subsection 3.3 to characterize 2-layer RAC drawable graphs. In Theorem 4 we focus on the case when u and v are two leaves for two reasons: (i) This is

2-Layer Right Angle Crossing Drawings

161

the only case needed for the characterization of 2-layer RAC drawable graphs that contain both non-trivial biconnected components and tree components; (ii) As Lemma 1 claims, any 2-layer RAC drawable tree admits a 2-layer RAC drawing where a leftmost vertex and a rightmost vertex are leaves. Let T be a tree and let u and v be two leaves of T . If there exists a 2-layer RAC embedding γ where u and v are a leftmost vertex and a rightmost vertex of γ, respectively, we say that γ is a 2-layer RAC embedding with respect to u and v. A 2-layer RAC drawing with embedding γ is a 2-layer RAC drawing with respect to u and v. If T admits such a drawing, we say that T is 2-layer RAC drawable with respect to u and v. Lemma 1. Let T be a 2-layer RAC drawable tree. There exists two leaves u and v such that T is 2-layer RAC drawable with respect to u and v. A weighted contraction of T is a weighted tree obtained from T by replacing each chain of length k > 1 with a single edge of weight k. We denote by wc(T ) the weighted contraction of T and by ω(a, b) the weight of an edge (a, b) of wc(T ). An edge of T that also belongs to wc(T ) has weight 1. The vertices of wc(T ) are a subset of the vertices of T and every vertex of wc(T ) has the same degree in T and in wc(T ). A path between two leaves u, v of T is a spine of T and is denoted by suv (T ). The path between u and v in wc(T ), denoted by scuv (T ), is a spine of wc(T ). The vertices of scuv (T ) are the spine vertices; the others are non-spine vertices (see also Fig. 3). wc(T )

T

1 1

u

v

u

3

2

1 1

(a)

u

3 3

v

v

1

(b)

Fig. 3. (a) A tree T and its weighted contraction wc(T ); the gray vertices are internal vertices of chains and disappear in wc(T ); the path between u and v in T (edges in bold) is a spine. (b) A 2-layer RAC embedding of T with respect to u and v.

Our characterization of a 2-layer RAC drawable tree is expressed in terms of properties of its weighted contraction. In order to do that, we look at what type of subtrees are “attached” to the vertices of the spine. For a given spine scuv (T ) of wc(T ), we define three kinds of subtrees in wc(T ), called k-fence, y-tree, and star-tree, respectively. Also, for a subtree T of any of the types above, we give the definition of feasibility of T , which expresses the possibility of representing the “non-contracted” version of T in a 2-layer RAC embedding with respect to the end-vertices, u and v, of the spine. We will prove that a tree T is 2-layer RAC drawable with respect to u and v if and only if every subtree “attached” to scuv (T ) is either a feasible k-fence, or a feasible y-tree, or a feasible star-tree. The three kinds of subtrees are defined as follows:

162

E. Di Giacomo et al.

– k-fence (refer to Fig. 4(a) and 4(c)). Let z0 , z1 , z2 , . . . , zk , zk+1 (k ≥ 2) be a maximal sequence of spine vertices such that: deg(zi ) = 3 (i ∈ {1, . . . , k}); ω(zi , zi+1 ) = 1 (i ∈ {1, . . . , k − 1}); deg(wi ) = 1, where wi is the non-spine vertex adjacent to zi (i ∈ {1, . . . , k}). The weighted subtree T induced by the vertices of {zi | i = 1, . . . , k} ∪ {wi | i = 1, . . . , k} is a k-fence of wc(T ). The subsequence z1 , z2 , . . . , zk is the chain root of T , each wi is a leaf of T . • A 2-fence is feasible if either ω(z1 , w1 ) ≤ ω(z0 , z1 ) + 1 and ω(z2 , w2 ) ≤ ω(z2 , z3 ) + 1 or ω(z2 , w2 ) ≤ ω(z0 , z1 ) and ω(z1 , w1 ) ≤ ω(z2 , z3 ). • A 3-fence is feasible if one of the following conditions holds: * the subtree induced by z1 , z2 , w1 , w2 is a feasible 2-fence and ω(z3 , w3 ) ≤ ω(z3 , z4 ) + 1; * the subtree induced by z2 , z3 , w2 , w3 is a feasible 2-fence and ω(z1 , w1 ) ≤ ω(z0 , z1 ) + 1; • A k-fence (k > 3) is feasible if the following conditions holds: * the subtree induced by z1 , z2 , w1 , and w2 is a feasible 2-fence; * the subtree induced by zk−1 , zk , wk−1 , and wk is a feasible 2-fence; (iii) If k ≥ 5, then ω(zi , wi ) ≤ 2 (i ∈ {3, . . . , k − 2}). – y-tree (refer to Fig. 4(d)). Let z be a degree-3 spine vertex of wc(T ) that does not belong to any k-fence and such that: (i) deg(w) = 3, where w is the nonspine vertex adjacent to z: and (ii) the vertices a, b = z adjacent to w have degree one. The weighted subtree T induced by z, w, a, b is a y-tree of wc(T ). Vertex z is the root, w is the internal vertex, and a, b are the leaves of T . Denote by z1 , z2 the spine vertices adjacent to z. Tree T is feasible if: (i) ω(z, w) = 1; (ii) either ω(w, a) ≤ ω(z1 , z) and ω(w, b) ≤ ω(z, z2 ) or ω(w, b) ≤ ω(z1 , z) and ω(w, a) ≤ ω(z, z2 ). – star-tree (refer to Fig. 4(e)). Let z be a spine vertex of wc(T ) that does not belong to either a k-fence or a y-tree and such that: (i) deg(z) ≥ 3; (ii) every non-spine vertex wi adjacent to z has degree one (i = 1, . . . , deg(z)). The weighted subtree T induced by z and all vertices wi is a star-tree of wc(T ). Vertex z is the root of T . Denote by z1 , z2 the spine vertices adjacent to z. Tree T is feasible if: (i) There exist at most two vertices wj , wh such that 1 < ω(z, wj ) ≤ ω(z1 , z) + 1 and 1 < ω(z, wh ) ≤ ω(z, z2 ) + 1; (ii) for every vertex wi ∈ / {wj , wh }, ω(z, wi ) = 1. A spine suv (T ) is feasible if for every vertex z ∈ scuv (T ) distinct from u and v one of the three conditions holds: (i) z belongs to the chain root of a k-fence; (ii) z is the root of exactly one feasible y-tree; (iii) z is the root of exactly one feasible star-tree. Theorem 4. Let T be a tree and let u, v be two leaves of T . Tree T is 2-layer RAC drawable with respect to u and v if and only if suv (T ) is a feasible spine. Also, if T has n vertices, there exists an O(n)-time algorithm that tests whether T admits a 2-layer RAC drawing with respect to u and v and, if so, it computes such a drawing. Sketch of Proof: The sufficiency is by construction: The spine is drawn as a monotone “zig-zag” path; the non-contracted version of each feasible substructure of the weighted contraction is embedded as shown in Fig. 5(a)– 5(f). The necessity is proved by case analysis on the vertices of degree larger than two in the weighted contraction of T .

2-Layer Right Angle Crossing Drawings z0

z1 3

z2 1

2 w1

z0

z3

3

2

3

z1 1

1

z1 3

4

z2 1

w1

z3 1

2 w2

2 w3

1

w2

4

z4 3

w3

(b) z4

1

z3

3

w1

w2

(a) z0

z2

163

z5 1

2 w4

z6 1

z1

z z2 4 1 2 4 w 1

a

b

2

w5

(c)

z1

z z2 4 2 5 1 1 3

w1 w2 w3 w4

(d)

(e)

Fig. 4. Feasible (a) 2-fence, (b) 3-fence, (c) 5-fence, (d) y-tree, and (e) star-tree

z0

z2 w1 z1

z3

z0

w2

w2

z2 z1

(a)

z0 w1

z0

w1

w2

z2 z1

z3 (d)

w 3z 5

w4 z6

w1

z4

z3

w3

z1

z

z2

w1

w2 w3

w4

(b)

z2 w2 w5z4 z1

z3

(c)

z1

z b

a

w (e)

z2

(f)

Fig. 5. 2-layer RAC embeddings for the non-contracted version of the feasible substructures of Fig. 4; (f)-(g) 2-fence, (h) 3-fence, (i) 5-fence, (j) y-tree, and (k) star-tree

Theorem 5. A tree T is 2-layer RAC drawable if and only if it admits a feasible spine. Also, if T has n vertices, there exists an O(n)-time algorithm that tests whether T is 2-layer RAC drawable and, if so, it computes a 2-layer RAC drawing of T . Sketch of Proof: The characterization is a consequence of Lemma 1 and Theorem 4. The existence of a linear time testing algorithm is proved by showing that a constant number of pairs of leaves as end-vertices of a feasible spine can be considered. 3.3 Characterization of 2-Layer RAC Graphs Intuitively, a general 2-layer RAC drawable graph is a chain of non-trivial biconnected components (each of them being the spanning subgraph of a ladder) alternated with trees having a feasible spine. Additionally, some other simple types of trees can be attached to the vertices of the extremal edges of a biconnected component (we call each of such trees an addendum). Fig. 6(a) shows a 2-layer RAC drawable graph and Fig. 6(d) depicts a 2-layer RAC embedding of G. More formally, a connected graph

164

E. Di Giacomo et al.

B2

Π2

B3 Π1 (a)

B1

B1 (b)

B2 Π1

B4

B3

B4

Π2 (c)

(d)

Fig. 6. (a) A graph G. Solid edges form skel(G). (b) skel(G) is feasible; for each component Bi , the gray vertices are the cut-vertices of G in Bi , and the bold edges are two edges e, e that cover all the cut-vertices in Bi and such that Bi is 2-layer RAC drawable with respect to e, e . (c) A 2-layer RAC embedding of skel(G). (d) A 2-layer RAC embedding of G.

G is outerplanarly biconnectible if it has two vertices {s, t} such that G ∪ (s, t) is outerplanar and biconnected. Let G be a bipartite graph that is neither biconnected nor a tree. The skeleton of G, denoted as skel(G), is the subgraph of G obtained by repeatedly removing the vertices of degree one. We denote by {B1 , . . . , Bk } the nontrivial biconnected components of skel(G). We say that skel(G) is feasible if skel(G) is outerplanarly biconnectible and each Bi (i = 1, . . . , k) contains two independent edges e and e such that: (a) Each cut-vertex of G in Bi is an end-vertex of e or e ; (b) Bi is 2-layer RAC drawable with respect to e and e . Fig. 6(a)-6(c) show a graph G, its (feasible) skeleton skel(G), and a 2-layer RAC embedding of skel(G). Observe that, if skel(G) is feasible then each Bi has at most four cut-vertices of G. Also, the components {B1 , . . . , Bk } form a sequence such that Bi and Bi+1 are connected by a path Πi from a vertex ui of Bi to a vertex vi of Bi+1 (i = 1, . . . , k − 1), where ui may coincide with vi . For each path Πi , we denote by Ti the tree consisting of Πi and all the subtrees of G rooted at each internal vertex of Πi . A path Πi is a bridge of skel(G) and tree Ti is the tree of Πi . If Πi is a single vertex then Ti coincides with Πi , and Πi is a degenerate bridge. It is easy to see that G is 2-layer RAC drawable only if skel(G) is feasible and each Πi is a feasible spine of Ti . However, for the characterization, we need additional conditions. Let T be a tree that is 2-layer RAC drawable with respect to two leaves u and v. We denote by ν(u, T ) the vertex closest to u along suv (T ) such that deg(ν(u, T )) ≥ 3 in T . If such a vertex does not exist then ν(u, T ) coincides with v. We can analogously define ν(v, T ). Let w be a cut-vertex of G that belongs to Bi (1 ≤ i ≤ k). Denote by

2-Layer Right Angle Crossing Drawings

165

T (w) the subtree of G rooted at w. Clearly G is the union of all Bi , all Ti , and all T (w), for each cut-vertex w of G that belongs to some Bi . Each tree T (w) is an addendum of skel(G). We now classify each addendum T (w) of skel(G) and correspondingly define the partner of T (w) (the partner is the tree that can overlap with T (w)). Also, we define the properties that each type of addendum must satisfy to be embedded correctly in a 2-layer RAC embedding of G whose skeleton is feasible (refer to Fig. 7): T (w)

x

T (w)

x

T (w) w

Bi

w

Bi+1

w

Bi

(a) type 1

z

Ti

Bi+1 Bi

(b) type 2

x

T (w)

Bk

T (w)

(d) type 4

z

z

Bi+1

x

T2(w)

Bk

Ti

(c) type 3

w w

w

w

z T1(w)

u

(e) type 5

Fig. 7. (a)-(e): Illustration of the different types of addendum. Each addendum in this picture is feasible

– If w coincides with the single vertex of a degenerate bridge, T (w) is a tree of type 1 and it has no partner. T (w) is feasible if it is a star centered at w. – If w coincides with an end-vertex of a non-degenerate bridge Πi , T (w) is a tree of type 2 and its partner is Ti . T (w) is feasible if it consists of a star centered at w plus at most one path from w to a leaf x such that d(w, x) ≤ d(w, z) + 1, where z = ν(w, Ti ). – If w is adjacent to an end-vertex w of a non-degenerate bridge Πi , T (w) is a tree of type 3 and its partner is Ti . T (w) is feasible if it consists of a path from w to a leaf x such that d(w, x) ≤ d(w , z), where z = ν(w , Ti ). – Otherwise, w is a cut-vertex of B ∈ {B1 , Bk } and one of the following cases applies: • w is adjacent to another cut-vertex w of G that belongs to B and that does not belong to any Πi , in which case T (w) and T (w ) are trees of type 4 and each of them is the partner of the other. T (w) and T (w ) are feasible if (i) w is a leaf of T (w) and there is another leaf u of T (w) such that T (w) is 2-layer RAC drawable with respect to u and w; (ii) T (w ) is a path from w to a leaf x such that d(w , x) ≤ d(w, z), where z = ν(w, T (w)). • w is not adjacent to a cut-vertex, in which case T (w) is of type 5 and has no partner. T (w) is feasible if it can be decomposed into subtrees T1 (w) and T2 (w) such that: (i) T1 (w) ∩ T2 (w) = {w} (T2 (w) may consist of w only); (ii) w is a leaf of T1 (w) and there is another leaf u of T1 (w) such that T1 (w)

166

E. Di Giacomo et al.

is 2-layer RAC drawable with respect to u and w; (iii) T2 (w) is a star centered at w plus at most one path from w to a leaf x, such that d(w, x) ≤ d(w, z) + 1, where z = ν(w, T1 (w)). Theorem 6. A graph G is 2-layer RAC drawable if and only if one of the following cases holds: (i) G is biconnected and it is a spanning subgraph of a ladder. (ii) G is a tree that admits a feasible spine. (iii) skel(G) is feasible, each path of skel(G) is a feasible spine of its tree, and each addendum of skel(G) is also feasible. Furthermore, if G has n vertices, there exists an O(n)-time algorithm that tests whether G is 2-layer RAC drawable and, if so, it computes a 2-layer RAC drawing of G. Sketch of Proof: The proof of the theorem combines the arguments used to prove Theorems 2-5. Fig. 8 shows how to embed each type of addendum. Bi

Bi+1

Bi

w

w

(a) type 1

x

w

(b) type 2

Bk w

w

z Bi+1 Bi w

z

x (d) type 4

x (c) type 3

Bk

w

z Bi+1

z

x (e) type 5

Fig. 8. (a)-(e) 2-layer RAC embedding for the different types of addendum

Since by Theorem 6, ladders are the densest graphs admitting a 2-layer RAC drawing, it is immediate to derive the following bound. Corollary 1. A 2-layer RAC drawable graph with n vertices has at most 1.5n−2 edges, which is a tight bound.

4 Optimization Problems In this section we consider two optimization problems that are naturally raised by the results in the previous sections. Namely, we consider both the problem of computing a 2-layer RAC drawing with the minimum number of edge crossings and the problem of extracting the maximum 2-layer RAC drawable subgraph of a given bipartite graph. We first show that if G is a 2-layer RAC drawable graph then a 2-layer RAC drawing of G with the minimum number of crossings can be computed in polynomial time. If

2-Layer Right Angle Crossing Drawings

167

G is a biconnected graph the problem is easy, because all crossings in any 2-layer RAC drawing of G are formed by the edges of the external cycle. Hence, every 2-layer RAC drawing of a biconnected component G with n > 2 vertices has (n − 2)/2 crossings. For reasons of space, we only show how to model the crossing minimization problem for a tree T , assuming that no k-fences are present in the weighted contraction of T . Suppose that T is a 2-layer RAC drawable tree with respect to two leaves u and v and let scuv (T ) = u = z0 , z1 , z2 , . . . , zh , zh+1 = v such that each zi is the root of a subtree T that is either a y-tree or a star-tree of wc(T ). In both cases, the non-contracted version of T contains at most two paths Πi,1 and Πi,2 , going from zi to two leaves xi,1 and xi,2 , respectively, such that d(zi , xi,1 ) > 1 and d(zi , xi,2 ) > 1. Note that, if T is a y-tree, Πi,1 and Πi,2 share the first edge. In a 2-layer RAC embedding γ of T , Πi,1 and Πi,2 are embedded one to the left and one to the right of zi , as explained in the previous sections (see Fig. 5(e), where zi = z, xi,1 = a, xi,2 = b, and Fig. 5(f), where zi = z, xi,1 = w1 , xi,2 = w4 ). If d(zi−1 , zi ) and d(zi , zi+1 ) are both greater than or equal to max{d(zi , xi,1 ) − 1, d(zi , xi,2 ) − 1}, then we can arbitrarily decide which path Πi,j goes to the left of zi and which one goes to the right of zi (j = 1, 2); in this case, we say that Πi,1 and Πi,2 are free paths, otherwise we say that they are constrained paths. The number of crossings that Πi,j forms with the spine suv (T ) is the same for each of the two choices, and it is equal to d(zi , xi,j ) − 1. However, the path Πi,j embedded to the left of zi may form some crossings with a path Πi−1,l (l = 1, 2) embedded to the right of zi−1 , if such a path exists; if so, the number of crossings between the two paths is at least d(zi , xi,j ) + d(zi−1 , xi−1,l ) − d(zi−1 , zi ) − 3, and the embedding constructed with our technique matches this number. Hence, our crossing minimization problem reduces to the problem of embedding each path Πi,j to the left or to the right of zi so that the total number of crossings between all paths is minimized. In the following we assume that for each vertex zi (i = 1, . . . , h) there are exactly two paths Πi,1 and Πi,2 . If not, we can attach to zi dummy paths of length 1, which can always be embedded without crossings. If γ is a 2-layer RAC embedding where Πi,j is to the left of zi and Πi−1,l is to the right of zi−1 we say that Πi,j and Πi−1,l are matched, and the cost of their matching equals max{0, d(zi, xi,j ) + d(zi−1 , xi−1,l ) − d(zi−1 , zi ) − 3}. Each path Πi,j is matched with some other path in γ, but the path to the left of z1 and the path to the right of zh (these paths do not cross any other path). Thus, if γ is a 2-layer RAC embedding with the minimum number of crossings, γ corresponds to a maximum matching among 2h − 2 paths with minimum total cost. Also, the path to the left of z1 in γ is the longest between Π1,1 and Π1,2 , unless Π1,1 and Π1,2 are constrained to be embedded in the other way. Similarly, the path to the right of zh is the longest between Πh,1 and Πh,2 , unless Πh,1 and Πh,2 are constrained to be embedded in the other way. To compute a 2-layer RAC embedding γ with the minimum number of crossings, we compute the corresponding optimal matching by solving a minimum cost flow problem on a suitable capacitated network N , having a single source and a single sink. Since N has O(n) vertices and edges, and since the value of the maximum flow is O(n), a maximum flow of minimum cost can be computed in O(n2 log n) time [1]. Theorem 7. Let G be a 2-layer RAC drawable graph. A 2-layer RAC embedding of G with the minimum number of crossings can be computed in O(n2 log n) time.

168

E. Di Giacomo et al.

As for the computation of the maximum 2-layer RAC drawable subgraph, we prove the N P-completeness of its associated decision problem, namely the following: M AXIMUM 2- LAYER RAC S UBGRAPH (M2LS): Given a bipartite graph G and a positive integer k, does G admit a 2-layer RAC drawable subgraph with k edges? Guessing an ordering of the vertices along the two layers proves that M2LS is in N P. The hardness is proved by reducing HP3 to M2LS, where HP3 is the problem of deciding whether a cubic graph has a Hamiltonian path. Theorem 8. M2LS is N P-complete

5 Open Problems We conclude the paper by listing some open problems that we consider worth to investigate. 1. Design heuristic methods or approximation algorithms for the Maximum 2-layer RAC Drawable Subgraph problem. 2. Study the problem of computing 2-layer drawings where the number of crossings that form π2 angles is maximized. 3. Study the problem of computing 2-layer drawings of a bipartite graphs where the minimum crossing angle is at least a given α such that 0 ≤ α < π2 .

References 1. Ahuja, R.K., Magnanti, T.L., Orlin, J.B.: Network Flows: Theory, Algorithms, and Applications. Prentice-Hall (1993) 2. Angelini, P., Cittadini, L., Di Battista, G., Didimo, W., Frati, F., Kaufmann, M., Symvonis, A.: On the perspectives opened by right angle crossing drawings. Journal of Graph Algorithms and Applications 15(1), 53–78 (2011) 3. Argyriou, E.N., Bekos, M.A., Symvonis, A.: The Straight-Line RAC Drawing Problem is ˇ a, I., Gyim´othy, T., Hromkoviˇc, J., Jefferey, K., Kr´alovi´c, R., Vukoli´c, M., NP-Hard. In: Cern´ Wolf, S. (eds.) SOFSEM 2011. LNCS, vol. 6543, pp. 74–85. Springer, Heidelberg (2011) 4. Didimo, W., Eades, P., Liotta, G.: Drawing Graphs with Right Angle Crossings. In: Dehne, F., Gavrilova, M., Sack, J.-R., T´oth, C.D. (eds.) WADS 2009. LNCS, vol. 5664, pp. 206–217. Springer, Heidelberg (2009) 5. Didimo, W., Eades, P., Liotta, G.: A characterization of complete bipartite RAC graphs. Inf. Process. Lett. 110(16), 687–691 (2010) 6. Dujmovi´c, V., Fellows, M.R., Hallett, M.T., Kitching, M., Liotta, G., McCartin, C., Nishimura, N., Ragde, P., Rosamond, F.A., Suderman, M., Whitesides, S., Wood, D.R.: A fixed-parameter approach to 2-layer planarization. Algorithmica 45(2), 159–182 (2006) 7. Dujmovi´c, V., Gudmundsson, J., Morin, P., Wolle, T.: Notes on large angle crossing graphs. In: Proceedings of the Sixteenth Symposium on Computing: the Australasian Theory, CATS 2010, vol. 109, pp. 19–24. Australian Computer Society, Inc. (2010) 8. Dujmovi´c, V., Whitesides, S.: An efficient fixed parameter tractable algorithm for 1-sided crossing minimization. Algorithmica 40(1), 15–31 (2004) 9. Eades, P., Kelly, D.: Heuristics for drawing 2-layered networks. Ars Comb. 21, 89–98 (1986) 10. Eades, P., Liotta, G.: Right angle crossing graphs and 1-planarity. In: EuroCG (2011)

2-Layer Right Angle Crossing Drawings

169

11. Eades, P., McKay, B., Wormald, N.: On an edge crossing problem. In: Proc. of 9th Australian Computer Science Conference, pp. 327–334 (1986) 12. Eades, P., Whitesides, S.: Drawing graphs in two layers. Theoretical Computer Science 131(2), 361–374 (1994) 13. Eades, P., Wormald, N.C.: Edge crossings in drawings of bipartite graphs. Algorithmica 11(4), 379–403 (1994) 14. Harary, F., Schwenk, A.: A new crossing number for bipartite graphs. Utilitas Mathematica 1, 203–209 (1972) 15. Huang, W.: Using eye tracking to investigate graph layout effects. In: APVIS, pp. 97–100 (2007) 16. Huang, W., Hong, S.-H., Eades, P.: Effects of crossing angles. In: PacificVis, pp. 41–46 (2008) 17. J¨unger, M., Mutzel, P.: 2-layer straightline crossing minimization: Performance of exact and heuristic algorithms. J. Graph Algorithms Appl. 1 (1997) 18. Mutzel, P.: An alternative method to crossing minimization on hierarchical graphs. SIAM J. on Optimization 11(4), 1065–1080 (2001) 19. Tomii, N., Kambayashi, Y., Yajima, S.: On planarization algorithms of 2-level graphs. Technical Report EC77-38, Inst. of Elect. and Comm. Eng. Japan (1977) 20. Valls, V., Mart´ı, R., Lino, P.: A branch and bound algorithm for minimizing the number of crossing arcs in bipartite graphs. Europ. J. of Oper. Res. 90(2), 303–319 (1996) 21. van Kreveld, M.: The Quality Ratio of RAC Drawings and Planar Drawings of Planar Graphs. In: Brandes, U., Cornelsen, S. (eds.) GD 2010. LNCS, vol. 6502, pp. 371–376. Springer, Heidelberg (2011)

Hamiltonian Orthogeodesic Alternating Paths Emilio Di Giacomo1, Luca Grilli1 , Marcus Krug2 , Giuseppe Liotta1 , and Ignaz Rutter2

2

1 Universit`a di Perugia, Italy {digiacomo,grilli,liotta}@diei.unipg.it Faculty of Informatics, Karlsruhe Institute of Technology (KIT), Germany {marcus.krug,rutter}@kit.edu

Abstract. Given a set of red and blue points, an orthogeodesic alternating path is a path such that each edge is a geodesic orthogonal chain connecting points of different colour and no two edges cross. We consider the problem of deciding whether there exists a Hamiltonian orthogeodesic alternating path, i.e., an orthogeodesic alternating path visiting all points. We provide an O(n log2 n)-time algorithm for finding such a path if no two points are horizontally or vertically aligned. We show that the problem is NP-hard if bends must be at grid points. Nevertheless, we can approximate the maximum number of vertices of an orthogeodesic alternating path on the grid by roughly a factor of 3. Finally, we consider the problem of finding orthogeodesic alternating matchings, cycles, and trees.

1 Introduction Let R and B be two disjoint point-sets in the plane with |R| ≤ |B|. We shall refer to points of R and B as red points and blue points, respectively. We say that the set P = R ∪ B is equitable if |B| − |R| ≤ 1 and it is balanced if |B| = |R|. An alternating path on a set of red and blue points P is a sequence of points p1 , . . . , ph alternatingly red and blue, such that pi and pi+1 (i = 1, . . . , h − 1) are connected by a straight-line segment and no two segments cross. The problem of computing an alternating path on a given equitable set of points in general position is a classical subject of investigation in the computational geometry field. Several papers are devoted to alternating paths containing all points of P ; this type of alternating paths are called Hamiltonian. Akiyama and Urrutia [3] studied Hamiltonian alternating paths on equitable point-sets in convex positions. They show that it is not always possible to compute a Hamiltonian alternating path on a given equitable point-set and give an O(n2 )-time algorithm that, given an equitable point-set, computes a Hamiltonian alternating path if it exists. Abellanas et al. [2] studied the case when points are not restricted to be in convex position; they prove that if either the convex hull of P consists of all the red points and no blue points or the two pointsets are linearly separable (i.e., there exists a straight line that separates the red from the blue points), then a Hamiltonian alternating path always exists. Kaneko, Kano, and Suzuki [7] studied the values of n for which every equitable set of n points admits a Hamiltonian alternating path and proved that this happens only for n ≤ 12 and n = 14; for any other value of n, there exist equitable point-sets that do not admit a Hamiltonian C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 170–181, 2011. c Springer-Verlag Berlin Heidelberg 2011

Hamiltonian Orthogeodesic Alternating Paths

171

alternating path. Cibulka et al. [5] described arbitrarily large equitable point-sets that admit a Hamiltonian alternating path for any colouring of the points. Non-Hamiltonian alternating paths have also been considered in the literature. In particular, the following problem has been investigated: given a set of n red and blue points P in the plane, what is the length (n) of the longest alternating path that can be defined on P ? Abellanas et al. [1] and Kynˇcl et al. [11] studied this problem on special cases of points in convex position and proved upper and lower bounds on the value of (n). Similar problems on red-blue points with graph families other than paths have also been studied. Abellanas et al. [2] investigate alternating spanning trees, i.e., spanning trees of red and blue point-sets such that each edge is a straight-line segment connecting points of different colours and no two edges cross, and prove that every point-set P = R ∪ B admits an alternating spanning tree whose maximum vertex degree is O( |B| |R| + log |R|). Kaneko, Kano, and Yoshimoto [8] consider Hamiltonian alternating cycles, but they allow edge crossings. They proved that at most n − 1 crossings are sufficient to compute a Hamiltonian alternating cycle and that this is the best possible in some cases. In this paper we study orthogeodesic alternating paths, i.e., crossing-free alternating paths where the edges are drawn as geodesic orthogonal chains instead of straight-line segments. A geodesic orthogonal chain is an orthogonal chain (i.e., a polygonal chain of horizontal and vertical segments) whose length is equal to the Manhattan distance of its endvertices. Since a geodesic orthogonal chain is a connection between two points that has the shortest length in the L1 metric, orthogeodesic alternating paths can be regarded as the counterpart in the L1 metric of alternating paths in the L2 metric. Kano [9] has recently studied equitable point-sets such that no two points are horizontally and vertically aligned. He shows that any of such point-sets admits a perfect matching connecting the red points to the blue ones such that every edge is “L-shaped”, that is it consists of exactly one horizontal and exactly one vertical segment. While it is easy to construct an equitable point-set for which a Hamiltonian orthogeodesic alternating path whose edges are all L-shaped does not exist, one may wonder whether every equitable point-set admits a Hamiltonian orthogeodesic alternating path in the L1 metric. Contribution. In this paper we describe an O(n log2 n)-time algorithm that computes a Hamiltonian orthogeodesic alternating path on an equitable set of red and blue points P such that no two points are horizontally or vertically aligned. The computed path has at most two bends per edge which is worst-case optimal. However, the bends along the edges may not have integer coordinates. For a contrast, we show that deciding whether a set of red and blue grid points P admits a Hamiltonian orthogeodesic alternating path with bends at grid points is NP-complete. We also consider several related questions. Namely, we prove that there exist point-sets that do not admit a Hamiltonian orthogeodesic alternating cycle and point-sets such that every alternating spanning tree is, in fact, a path; we describe a O(n log2 n)-time algorithm that computes an orthogeodesic alternating path of length (|P | + 2)/3 with bends at grid points; finally, we show that if points of P are allowed to be horizontally or vertically aligned then it is NPcomplete to decide whether a point-set P = R ∪ B with |B| = |R| has a perfect orthogeodesic alternating matching. This contrasts a recent paper by Kano stating that such a

172

E. Di Giacomo et al.

matching always exists if we are not allowed to place more than one point per horizontal or vertical line. For reasons of space some proofs are sketched or omitted.

2 Preliminaries An orthogonal chain is a polygonal chain of horizontal and vertical segments. A geodesic chain is an orthogonal chain whose length is equal to the Manhattan distance of its endvertices. A crossing between two geodesic chains is an intersection that occurs at an interior point of at least one of the two chains. Let P = R ∪ B be a set of red and blue points; we use c(p), x(p) and y(p) to denote the colour, the x-coordinate and the y-coordinate of point p ∈ P , respectively. An orthogeodesic path (cycle) is a drawing of a path (cycle) such that each edge is represented by a geodesic chain and edges intersect only at common endvertices. An orthogeodesic alternating path (cycle) on P is an orthogeodesic path (cycle) whose vertices are the points of P and each edge connects points of distinct colours. An orthogeodesic alternating path (cycle) is Hamiltonian if it contains all points of P . Clearly, for an orthogeodesic alternating path (cycle) to be Hamiltonian it is necessary that P is equitable (balanced). An orthogeodesic alternating spanning tree on a point-set P = R ∪ B is a spanning tree of P such that each edge is a geodesic chain connecting points of different colours and no two edges cross. Given a point-set P ⊆ P , the bounding box of P , denoted as B(P ), is the smallest axis-parallel rectangle enclosing P . Let p and q be two points such that B({p, q}) is a non-degenerate rectangle. A horizontal chain (vertical chain) is a two-bend geodesic chain such that the first and the last segment are horizontal (vertical). Notice that a horizontal chain (vertical chain) is uniquely determined when the x-coordinate (ycoordinate) of its vertical (horizontal) segment is specified. A point-set P = R ∪ B is a butterfly if it has the following properties: (i) for every two blue points p and q of P , x(p) < x(q) implies y(p) < y(q); (ii) for every two red points p and q of P , x(p) < x(q) implies y(p) < y(q); (iii) for every pair consisting of a blue point p and a red point q of P , x(p) > x(q) and y(p) < y(q) (see Figure 2(a)). When printed in black and white, the darker dots in our figures represent blue points while the light gray ones represent red points.

3 Hamiltonian Orthogeodesic Alternating Paths We describe now an algorithm to compute a Hamiltonian orthogeodesic alternating path on an equitable set of red and blue points such that no two points are horizontally or vertically aligned. We assume that points are not vertically or horizontally aligned in order to avoid straightforward counterexamples. Namely, it is easy to find point-sets that contain vertically or horizontally aligned points and that do not admit a Hamiltonian orthogeodesic alternating path. Consider, for example, a set of three points on the same vertical/horizontal line with two consecutive points of the same colour. The algorithm is a recursive algorithm that incrementally constructs the path. Consider a generic call of the algorithm. When such a call is activated, a connected subpath

Hamiltonian Orthogeodesic Alternating Paths

173

Π has already been constructed on a subset U of the input point-set P . Given a point p in U and a point q in the plane (not necessarily a point of P ), we say that q is leftconnectible to p if y(p) = y(q) and pq ∩ Π = {p}. The input of the recursive call is a balanced point-set P ⊆ P \ U and a point ql (not necessarily belonging to P ) to the left of B(P ). The point ql is called the enter point. The point-set P and the enter point ql are such that the intersection between B(P ∪ {ql }) and the path Π (if any) is completely contained in the left side of B(P ∪ {ql }). Also, ql is either an endvertex of Π or it is left-connectible to an endvertex of Π. The output of the recursive call is a Hamiltonian orthogeodesic alternating path Π on P ∪ {ql } with the following properties: (P1) ql is an endpoint of Π ; also, Π is completely contained in B(P ∪ {ql }) and the intersection between Π and the left side of B(P ∪ {ql }) is ql ; (P2) there exists a point qr , called exit point, on the right side of B(P ) such that c(qr ) = c(ql ); also, qr is either an endvertex of Π or it is left-connectible to an endvertex of Π . (P3) each geodesic chain in Π is drawn with at most two bends; Before describing the algorithm it is worth clarifying what is the input of the main call of the algorithm. If P is balanced, we extend P with a point ql to the left of B(P ) arbitrarily coloured red or blue. This point will be the enter point of the first recursive call. If P is unbalanced, we add a point r to the left of B(P ) in order to make it balanced; the colour of r is therefore red (recall that we are assuming |R| ≤ |B|). Then we can proceed as in the previous case, i.e., we add an enter point ql to the left of r arbitrarily coloured red or blue. The input is then ql and P ∪{r}. Clearly, at the end of the algorithm the added points and the chains incident to them will be removed. We are now ready to describe our recursive algorithm. Without loss of generality we assume that c(ql ) is blue. If |P | = 2 then we compute a drawing as follows (see Figure 1(a)). Let p be the point of the left side of B(P ) that has the same y-coordinate of the red point p of P (p and p may coincide). Connect point p to p with zero bends and to ql with a horizontal chain whose vertical segment has x-coordinate (x(ql ) + x(p ))/2. Also, connect p to the blue point r of P with a vertical chain whose horizontal segment has y-coordinate (y(p) + y(r))/2. Assume now that |P | > 2 and let pt , pb , pl , and pr be the points on the top, bottom, left, and right side of B(P ), respectively. Notice that some of these points may coincide. We distinguish the following cases, depending on the colour of pl : Case 1: c(pl ) is blue. We further distinguish the following sub-cases: Case 1.a: c(pt ) is red. Notice that, in this case pt = pl . Let pt be the top-left corner of B(P ). Connect point pt to pt with zero bends and to ql with a horizontal chain whose vertical segment has x-coordinate (x(ql ) + x(pt ))/2. Let r be the point of P immediately below pt . Connect pt and pl with a vertical chain whose horizontal segment has y-coordinate (y(pt ) + y(r))/2. Recursively apply the algorithm with input the point pl and the set P \ {pl , pt }. See Figure 1(b) for an illustration. Case 1.b: c(pb ) is red. Symmetric to Case 1.a. The drawing is obtained from Case 1.a by a vertical reflection. Case 1.c: c(pt ) = c(pb ) is blue. There are two sub-cases: Case 1.c.1: c(pr ) is red. First recursively apply the algorithm with input the point ql and the set P \ {pt , pr }. Let Π be the sub-path computed by the recursive call and let qr be its exit point. Connect qr to its corresponding extremal point with a horizontal segment if necessary and connect pr to qr with a horizontal chain whose vertical segment has x-coordinate (x(pr ) + x(qr ))/2.

174

E. Di Giacomo et al.

p

p ql

ql

pt

p ql

r

qr

r

ql

P

pt

pt qr

pl

pl

= qr

ql

P \ {pl , pt }

pl

qr

pt

P

pr

ql

qr

pl

pb

(a) Base case - input/output pt ql

pl

P

r

pr

pl

ql pb

Pl

qr

(b) Case 1.a - input/output

pr Pr qr

(d) Case 1.c.2 - input/output

pr ql pl

P

ql pl

P \ {pl , pr }

ql

(e) Case 2.a - input/output

pb

(c) Case 1.c.1 - input/output

pr qr

pr

P \ {pt , pr }

pl

pr P

r pl ql

Pl

qr

pr Pr qr

(f) Case 2.b - input/output

Fig. 1. The different cases of the algorithm. Case 1.b is a vertical reflection of Case 1.a. The squares in the pictures represents the enter points and the exit points of the different recursive calls.

Let r be the point of P immediately below pt . Connect pr and pt with a vertical chain whose horizontal segment has y-coordinate (y(pt ) + y(r))/2. See Figure 1(c) for an illustration. Case 1.c.2: c(pr ) is blue. Let r be the leftmost red vertex such that the set Pl = {p | p ∈ P ∧ x(p) ≤ x(r)} is balanced and let Pr = P \ Pl . Since point r cannot coincide with pr , both Pl and Pr are not empty. Also, Pr is balanced because so are P and Pl . Recursively apply the algorithm with input the point ql and the set Pl . Let Π be the sub-path computed by the recursive call and let qr be its exit point. Recursively apply the algorithm with input the point qr and the set Pr . See Figure 1(d) for an illustration. Case 2: c(pl ) is red. Based on the colour of pr , we distinguish the following subcases: Case 2.a: c(pr ) is blue. Connect ql to pl with a horizontal chain whose vertical segment has x-coordinate (x(ql )+x(pl ))/2. Recursively apply the algorithm with input the point pl and set P \ {pl , pr }. Let Π be the sub-path computed by the recursive call and let qr be its exit point. Connect qr to its corresponding extremal point with a horizontal segment if necessary and connect pr to qr with a horizontal chain whose vertical segment has x-coordinate (x(pr )+x(qr ))/2. See Figure 1(e) for an illustration. Case 2.b: c(pr ) is red. Let r be the leftmost blue vertex such that the set Pl = {p | p ∈ P ∧ x(p) ≤ x(r)} is balanced and let Pr = P \ Pl . Since point r cannot coincide with pr , both Pl and Pr are not empty. Also, Pr is balanced because so are P and Pl . Recursively apply the algorithm with input the point ql and the set Pl . Let Π be the sub-path computed by the recursive call and let qr be its exit point. Recursively apply the algorithm with input the point qr and the set Pr . See Figure 1(f) for an illustration. Theorem 1. Every equitable set of n red and blue points such that no two points are horizontally or vertically aligned admits a Hamiltonian orthogeodesic alternating path. Also, there exists an O(n log2 n)-time algorithm to compute such a path. Furthermore, the computed path has at most two bends per edge, which is worst-case optimal. Finally, if the input point-sets consists of grid points all bends are at half-integer grid points.

Hamiltonian Orthogeodesic Alternating Paths

175

Sketch of Proof: For reasons of space the proof that the algorithm described above correctly computes a Hamiltonian orthogeodesic alternating path on P is omitted. In this sketch of proof we only show that two bends per edge are worst-case optimal and that the algorithm can be implemented to run in O(n log2 n) time, where n := |P |. We start by proving that it is not always possible to obtain a Hamiltonian orthogeodesic alternating path such that every edge has at most one bend. Consider a butterfly P with at least four points and let Π be any Hamiltonian orthogeodesic alternating path on P . Let p be a blue point that is not an endpoint of Π (notice that at most one blue point is an endpoint of Π because |R| = |B|). Point p is connected to two red points q1 and q2 by two geodesic chains χ1 and χ2 , respectively, as depicted in Figure 2(b). One of the two chains, say χ1 , must have a horizontal segment incident to p while the other chain, that is χ2 , must have a vertical segment incident to p. If we use 1-bend geodesic chains, then χ1 has a vertical segment incident to q1 while χ2 has a horizontal segment incident to q2 . Since all red points are above and to the left of all the blue points, and since the two chains cannot cross, then x(q1 ) < x(q2 ). At least one of q1 and q2 must be connected to a blue point p distinct from p (recall that at most one red point is an endpoint of Π because |R| = |B|). If x(p ) < x(p) then the geodesic chain connecting q1 or q2 to p would cross chain χ1 ; If x(p ) > x(p) then the geodesic chain connecting q1 or q2 to p would cross chain χ2 . We now prove that the algorithm can be implemented to run in O(n log2 n) time. We sort the points with respect to their x- and y-coordinates and maintain respective arrays, such that each point p can be addressed by two integers h(p) and v(p) denoting the index of p in the horizontal and vertical array, respectively. Further, we maintain two spatial data structures with O(n log n) initialization time and O(log n) query time for orthogonal range queries [4] for the blue and red points, respectively. We assume that we are given the bounding box R of the instance P in the form of at most four points pl , pr , pt and pb on the bounding box of the instance, each of which is specified by two integers pointing to the position of the points in the horizonal and vertical array, respectively. First we consider all cases, except for Case 1.c.2 and Case 2.b. In these cases we compute the geodesic chain from two points p1 and p2 on the boundary of B(P ) and the sub-path computed for P := P \ {p1 , p2 }. In order to recurse on P we need to compute the extremal points of P , given an axis-aligned rectangle R ⊃ P with R ∩ {p1 , p2 } = ∅ that can easily be obtained from the extremal points of P and the horizontal and vertical arrays. Suppose that R is given by two intervals [i, j] and [k, l] where i, j, k and l are integers pointing to the horizontal and vertical arrays. First we determine the number of points m in R ∩ P using the spatial data structures. For each horizontal and vertical boundary of R that is not yet covered by a point, we perform a binary search on the horizontal and vertical arrays [i, j] and [k, l], respectively, in order to locate the extremal point in P along the axis orthogonal to the boundary line. In each iteration of the binary search we query the spatial data structures with the corresponding rectangle R to determine the number of points in R. If this number is equal to m and the boundary is defined by a point in P , then we have found an extremal point. Since the number of steps is at most log n and each step can be performed in O(log n), we can find the extremal points in O(log2 n) time.

176

E. Di Giacomo et al.

q1

q2

χ2

p

χ1

(a)

(b)

Fig. 2. (a) A butterfly. (b) Illustration for the proof of Theorem 1. If point p is connected to q1 and q2 with two 1-bend geodesic chains, then q1 and q2 cannot be connected to any other blue point by a geodesic chain without introducing a crossing.

Next, we describe how to split the point sets as in Cases 1.c.2 and 2.b. In both cases, we would like to split the current instance vertically into two balanced subsets. Since both cases can be treated similarly, we only describe Case 1.c.2. In this case, we would like to split the instance vertically such that the rightmost point in the left sub-instance is red. Given an integer i, we can count the number of red and blue points in the rectangle Ri defined by the horizontal interval [h(pl ), i] and the vertical interval [v(pb ), v(pt )] in time O(log n). Let f (i) be defined as the number of blue points in Ri minus the number of red points in Ri . Clearly, f (h(pl )) = 1 and f (h(pr ) − 1) = −1 since both c(pl ) and c(pr ) are blue and the instance is balanced. Since there is at most one point in each column, we have |f (i) − f (i + 1)| ≤ 1 for all i in the range. This implies that f must attain the value 0 in the interval (i, j) whenever f (i) > 0 and f (j) < 0 or vice versa. Using this observation, we can find an index i such that f (i) = 0 in the interval (h(pl ), h(pr )) in O(log2 n) using binary search. Whenever we encounter an index i such that f (i) = 0 and the rightmost point on the left sub-instance is a blue point, we continue with the binary search by considering the interval (h(pl ), i − 1). Note that f (i − 1) = −1 in this case. Having found an index i with the desired properties, we can find all points on the boundary of the bounding boxes of the two sub-instances in time O(log2 n) similar to the cases described above. Finally, note that each operation of the algorithm can be implemented to run in O(log2 n) time and is executed at most n times. Hence, the running time of the algorithm is in O(n log2 n).

4 Hamiltonian Orthogeodesic Alternating Paths on the Grid In the previous section, we have seen that any equitable set of red and blue points such that no two points are on a common horizontal or vertical line allows for a Hamiltonian orthogeodesic alternating path. A common requirement when computing orthogonal drawings is that the endpoints of each segment be represented by grid points, i.e., points with integer coordinates. A Hamiltonian orthogeodesic alternating path satisfying this requirement is said to be on the grid. Clearly, such a path can exist only if the points of P are grid points. The algorithm described above may not produce Hamiltonian orthogeodesic alternating paths on the grid even if the points of P are grid points. Namely, our algorithm sometimes needs to draw a horizontal chain connecting two points with

Hamiltonian Orthogeodesic Alternating Paths

177

consecutive x-coordinates. In this case the bends of the chain have a x-coordinate that is half-way between the x-coordinates of the two points. Clearly if the two points have consecutive integer x-coordinate, the bends will have a non-integer x-coordinate. The same happens with vertical chains between points having consecutive y-coordinates. One may wonder whether it is always possible to compute Hamiltonian orthogeodesic alternating paths on the grid. The following theorem shows that this is not possible. Theorem 2. For every n ≥ 5, there exists an equitable set of red and blue grid points of size n that does not admit a Hamiltonian orthogeodesic alternating path on the grid. Motivated by Theorem 2, we study the H AMILTONIAN O RTHOGEODESIC A LTERNATING PATH ON THE G RID problem, i.e., the problem of deciding whether an equitable set of grid points such that no two points are horizontally or vertically aligned, admits a Hamiltonian orthogeodesic alternating path on the grid. We show that this problem is NP-complete. Similar techniques can be used to show that it is NP-complete to decide whether there is a Hamiltonian orthogeodesic alternating cycle. If we are allowed to place more than one point on a horizontal or vertical line, we can show that it is NPcomplete to decide whether there exists an orthogeodesic alternating perfect matching. This contrasts a result by Kano [9] stating that such a matching always exists if we are not allowed to place more than one point per horizontal or vertical line. Theorem 3. H AMILTONIAN O RTHOGEODESIC A LTERNATING PATH is NP-complete.

ON THE

G RID

Sketch of Proof: We show that the problem is in NP by showing that it suffices to guess a linear number of bends for each of the edges. For reasons of space we omit the proof. We show NP-hardness by reduction from 3-PARTITION. Similar techniques have been used, for example, in [10]. An instance of 3-PARTITION consists of a multiset A = {a1 , . . . , a3m } of 3m positive integers, each in the range 3m (B/4, B/2), where B = ( i=1 ai )/m, and the question is whether there exists a partition of A into m subsets A1 , . . . , Am of A, each of cardinality 3, such that the sum of the numbers in each subset is B. Since 3-PARTITION is strongly NP-hard [6], we may assume that B is bounded by a polynomial in m. Given an instance A of 3-PARTITION, we construct a corresponding instance P = R ∪ B of the H AMILTONIAN O RTHOGEODESIC A LTERNATING PATH ON THE G RID problem such that P allows for a Hamiltonian orthogeodesic alternating path if and only if there exists a partition of A with the desired properties as follows. A sequence of diagonally aligned grid points√is called k-spaced if the Euclidean distance between subsequent points is exactly k 2. The point-set P consists of four different types of points, called hinge points, element points, mask points and partition points, and is aligned on a regular sawtooth-pattern with 3m + 2 teeth, numbered T0 , . . . , T3m+1 from left to right. The pointset, as well as the sawtooth-pattern and the teeth are illustrated in Figure 3. Let L be some integer to be√specified later. Each tooth Ti consists of a diagonal segment with slope 1 of √ length L 2, denoted by Si , and a diagonal segment with slope −1 of length (2L + 1) 2. Hence, the tips of the teeth are aligned along a line with negative slope such that the tip of Ti is below the lowest point of Si−1 for 1 ≤ i ≤ 3m + 1.

178

E. Di Giacomo et al.

ea 1 +

ch )

B

ea

(m in ts

io it rt

pa

n

po

in ts

(B

po k

as

T1

S1

m

1

2a

L+1

1

S0 T 0

+

m2 B

element points

L

+

4m

ch )

hinge points

L

2L + 1

S3m+1 T3m+1

Fig. 3. Pointset used in the reduction. Each shaded triangle constitutes a tooth Ti . All points are arranged on the ascending slope Si of Ti .

Along S0 , we align m2 B + 4m 2-spaced blue hinge points starting at the leftmost point of S0 . For each element ai we align 2ai + 1 1-spaced red element points along Si . Further, we align m sets of B 2-spaced blue partition points along S3m+1 , each acting as a partition. These partitions are separated by m − 1 sequences of mB + 1 2-spaced red mask points which will act as a sort of “dot mask” separating the partitions. The maximal sequences of blue points along S3m+1 are called partitions and the maximal sequences of red points along S3m+1 are called masks. By construction P contains m2 B + mB + 4m − 1 red and m2 B + mB + 4m blue points and, thus, is equitable with one more blue point. Hence, any alternating path must start and end with a blue point and all red points must be interior points. This implies that every red point must be connected to exactly two blue points. We now show that there is a partition of A if and only if the point-set contains a Hamiltonian orthogeodesic alternating path. Assume that we are given such a path. See Figure 4 for a high-level illustration. In each mask there must be one mask point that is connected to a blue hinge point on S0 . To see this, note that there are mB + 1 red mask points in each of the m − 1 masks, but only mB blue points in total on S3m+1 . Hence, at least one of the red mask points in each mask must be connected to a blue hinge point. Each edge between a mask point and a hinge point is called a partitioner. Since the element points corresponding to a single element are 1-spaced, no partitioner can pass between them. Hence, the partitioners will partition the element points according to the element sizes, such that all element points corresponding to a single element are contained in the same partition. Next, consider the element points. Let Di be the diagonal line through Si and let Hi+ and Hi− denote the upper and lower halfplanes defined by Di , respectively. We claim that each group of 2ai + 1 element points corresponding to element ai can have at most 2ai + 2 blue incidences in Hi+ . Each of these incidences is a geodesic chain starting either with a horizontal segment to the left or with a vertical segment towards the top.

Hamiltonian Orthogeodesic Alternating Paths

179

hinge points +

4m

m2 B

S1 S2

element points ⎫ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎬

Sa4 4

⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎭

S5 a5

S6 a6

2ai + 1

S7 a7

S3 a3

S8 a8

a2

a1

S0

S9 a9

B

S10 mask points partition points

Fig. 4. A high-level illustration of an examplary reduction from 3-PARTITION to H AMILTONIAN O RTHOGEODESIC A LTERNATING PATH ON THE G RID using the instance A1 = {a1 , a5 , a7 }, A2 = {a2 , a3 , a8 }, A3 = {a4 , a6 , a9 } (not to scale). Details are depicted in the circles.

These segments can be covered by gridpoints adjacent to the element points. As there are only 2ai + 2 such gridpoints, the claim holds. Since the group of element points corresponding to ai must have 4ai + 2 incidences in total, it must therefore have at least 2ai blue incidences in Hi− . Hence all element points must have 2mB blue incidences on S3m+1 in total. On the other hand, there are only mB blue points on S3m+1 , each of which must have two red incidences. This implies that element ai has exactly 2ai incidences in Hi− and that the blue partition points are connected only to the element points. Since there are B blue points in each of the partitions, the number of element points must add up to 2B, i.e., the corresponding elements add up to B and thus yield a valid 3-partition of A. Conversely, suppose that we are given a valid partition of A. Then we can find a Hamiltonian orthogeodesic alternating path as follows. Each geodesic chain is drawn as the bottommost geodesic that runs across all geodesics drawn so far as illustrated in Figure 4. We start with the leftmost element ai that is inserted in the first partition. We draw an alternating path starting at the leftmost hinge point using the first ai partition points, the first 2ai element-points corresponding to ai as well as the leftmost hinge points on S0 . After that, we connect the last element point only to the two next hinge points. Then we proceed in the same manner with the second and third elements that are inserted in the first partition. After that, we draw the partition starting at the current hinge point and going back and forth between the hinge points and mask points until we have connected all mask points of the first mask. The rest of the path is connected in a

180

E. Di Giacomo et al.

similar fashion. Since we are given a valid partition, the drawing will be a Hamiltonian path and by choosing L large enough, e.g., L = |P | + 1, we can make sure that there is enough space between the element points for all geodesic chains, so that the resulting drawing is planar. The following corollary can be obtained by similar techniques. Corollary 1. It is NP-complete to decide whether a given balanced set of red and blue grid points such that no two points are on a common horizontal or vertical line allows for a Hamiltonian orthogeodesic alternating cycle if bends are only allowed at grid points. Due to Kano [9] every balanced set of red and blue points such that no two points are on a common horizontal or vertical line contains a perfect orthogeodesic alternating matching consisting of L-shaped orthogonal chains. Hence such a matching is completely on the grid whenever the points are grid points. If we are given an arbitrary balanced set of red and blue grid points allowing points to be aligned on a common horizontal or vertical line, the problem becomes NP-complete. The proof is similar to the proof of Theorem 3 and can be found in the appendix. Theorem 4. Given an arbitrary balanced set of red and blue grid points, it is NPcomplete to decide whether there is a perfect orthogeodesic alternating matching on the grid.

5 Additional Results In this section we consider some questions naturally related with Theorems 1 and 3. First, we investigate whether the result of Theorem 1 can be extended to other families of graphs, such as cycles and trees having vertex degree larger than two. The following two theorems present counterexamples using equitable point-sets that are butterflies. Theorem 5. For every even n ≥ 4, there exists a balanced set of red and blue points of size n that does not admit a Hamiltonian orthogeodesic alternating cycle. Theorem 6. For every n ≥ 4, there exists a set of n red and blue points such that any orthogeodesic alternating spanning tree has maximum vertex degree 2. Motivated by Theorem 3, we consider the following optimization problem: Given an equitable set of red and blue grid points P such that no two points are on a common horizontal or vertical line, we wish to find a subset P ⊆ P of maximum size such that there is a Hamiltonian orthogeodesic alternating path for P on the grid. The following theorems show lower and upper bounds on the maximum size of P . Theorem 7. Let P be an equitable set of grid points. There is an O(n log2 n)-time algorithm that computes an equitable set P ⊆ P with |P | ≥ (|P | + 2)/3 that admits a Hamiltonian orthogeodesic alternating path on the grid. Theorem 8. The maximum number of points on any orthogeodesic alternating path on the grid for the butterfly with 2n points is at most n + 1.

Hamiltonian Orthogeodesic Alternating Paths

181

6 Open Problems The results of this paper suggest some problems that can be further investigated: – Based on the results of Theorems 2, 5, and 6, it may be worth characterizing those point-sets that admit an alternating path on the grid, an alternating cycle, and an alternating spanning tree, respectively. – Also, it would be interesting to close the gap between Theorem 7 and Theorem 8. – Finally, the concept of Hamiltonian orthogeodesic alternating path can be extended to the case that the point-set P is partitioned into k colour classes. In this case a point of one colour can be connected to any point of one of the other k−1 colours. Is it always possible to compute a Hamiltonian orthogeodesic alternating path in this multi-coloured setting? We recall here that the (straight-line) alternating paths on multi-coloured point-sets have been studied by Merino, Salazar, and Urrutia [12].

References 1. Abellanas, M., Garc´ıa, A., Hurtado, F., Tejel, J.: Caminos alternantes (in Spanish). In: X Encuentros de Geometr´ıa Computacional, Sevilla, Spanish, pp. 7–12 (2003) 2. Abellanas, M., Garcia-Lopez, J., Hern´andez-Pe˜nalver, G., Noy, M., Ramos, P.A.: Bipartite embeddings of trees in the plane. Discrete Applied Mathematics 93(2-3), 141–148 (1999) 3. Akiyama, J., Urrutia, J.: Simple alternating path problem. Discr. Math. 84(1), 101–103 (1990) 4. Chazelle, B.: Functional approach to data structures and its use in multidimensional searching. SIAM J. Comput. 17, 427–462 (1988) 5. Cibulka, J., Kynˇcl, J., M´esz´aros, V., Stolaˇr, R., Valtr, P.: Hamiltonian Alternating Paths on Bicolored Double-Chains. In: Tollis, I.G., Patrignani, M. (eds.) GD 2008. LNCS, vol. 5417, pp. 181–192. Springer, Heidelberg (2009) 6. Garey, M.R., Johnson, D.S.: Computers and Intractability. A Guide to the Theory of NPCompleteness. W.H. Freeman and Company (1979) 7. Kaneko, A., Kano, M., Suzuki, K.: Path coverings of two sets of points in the plane. In: Pach, J. (ed.) Towards a Theory of Geometric Graphs, vol. 342, pp. 99–111. American Mathematical Society (2004) 8. Kaneko, A., Kano, M., Yoshimoto, K.: Alternating Hamilton cycles with minimum number of crossings in the plane. Int. J. Comput. Geometry Appl. 10(1), 73–78 (2000) 9. Kano, M.: Discrete geometry on red and blue points on the plane lattice. In: Proc. of JCCGG 2009, pp. 30–33 (2009) 10. Katz, B., Krug, M., Rutter, I., Wolff, A.: Manhattan-Geodesic Embedding of Planar Graphs. In: Eppstein, D., Gansner, E.R. (eds.) GD 2009. LNCS, vol. 5849, pp. 207–218. Springer, Heidelberg (2010) 11. Kynˇcl, J., Pach, J., T´oth, G.: Long alternating paths in bicolored point sets. Discrete Mathematics 308(19), 4315–4321 (2008) 12. Merino, C., Salazar, G., Urrutia, J.: On the length of longest alternating paths for multicoloured point sets in convex position. Discrete Mathematics 306(15), 1791–1797 (2006)

Ranking and Loopless Generation of k-ary Dyck Words in Cool-lex Order Stephane Durocher1 , Pak Ching Li1 , Debajyoti Mondal1 , and Aaron Williams2 1

Department of Computer Science, University of Manitoba Department of Mathematics and Statistics, Carleton University {durocher,lipakc,jyoti}@cs.umanitoba.ca, haron@uvic.ca

2

Abstract. A binary string B of length n = kt is a k-ary Dyck word if it contains t copies of 1, and the number of 0s in every preﬁx of B is at most k−1 times the number of 1s. We provide two loopless algorithms for generating k-ary Dyck words in cool-lex order: (1) The ﬁrst requires two index variables and assumes k is a constant; (2) The second requires t index variables and works for any k. We also eﬃciently rank k-ary Dyck words in cool-lex order. Our results generalize the “coolCat” algorithm by Ruskey and Williams (Generating balanced parentheses and binary trees by prefix shifts in CATS 2008) and provide the ﬁrst loopless and ranking applications of the general cool-lex Gray code by Ruskey, Sawada, and Williams (Binary bubble languages and cool-lex order under review).

1 1.1

Background k-ary Dyck Words

Let B(n, t) be the set of binary strings of length n containing t copies of 1. A string B ∈ B(kt, t) is a k-ary Dyck word if the number of 0s in each preﬁx is at most k−1 times the number of 1s. Let Dk (t) be the set of k-ary Dyck words of length kt. For example, the k-ary Dyck words with k = t = 3 are given below D3 (3) = {111000000, 110100000, 101100000, 110010000, 101010000, 100110000, 110001000, 101001000, 100101000, 110000100, 101000100, 100100100}. The k-ary Dyck words of length kt have simple bijections with a number of combinatorial objects including k-ary trees with t internal nodes [2,3]. The 2ary Dyck words are known as balanced parentheses when 1 and 0 are replaced by ‘(’ and ‘)’ respectively, and the cardinality of D2 (t) is the tth Catalan number. A simple property of k-ary Dyck words is that they can be “separated” according to the following remark. We let αβ denote the concatenation of the binary strings α and β, and we say that α and β have the same content if they have equal length and an equal number of 1s. Remark 1. If αβ, γδ ∈ Dk (t) and α and γ have the same content, then αδ, βγ ∈ Dk (t). In other words, preﬁxes (or suﬃxes) of k-ary Dyck words with the same content can be separated and recombined. C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 182–194, 2011. c Springer-Verlag Berlin Heidelberg 2011

Ranking and Loopless Generation of k-ary Dyck Words in Cool-lex Order

1.2

183

Combinatorial Generation

Many computational problems require iterating through combinatorial objects of a given type and size without duplication. Generation algorithms store one object in a data structure, and create successive objects by modifying its contents. Constant-amortized time (CAT) and loopless algorithms create successive objects in amortized O(1)-time and worst-case O(1)-time, respectively. Memory for input parameters and the aforementioned data structure are ﬁxed expenses, and the algorithm’s remaining variables are additional variables. Index variables have values in {1, 2, . . . , n} when generating combinatorial objects of size O(n). Successive objects created by loopless algorithms diﬀer by a constant amount (in the chosen data structure) and the resulting order of objects is a Gray code. If successive objects diﬀer by operation ‘x’, then the order is an ‘x’ Gray code; in a 2-‘x’ Gray code successive objects diﬀer by at most two applications of ‘x’. In a cyclic Gray code the last object diﬀers from the ﬁrst object in same way. Suppose B = B1 B2 · · · Bn is a binary string of length n and 1 ≤ i ≤ j ≤ n. Informally, swap(B, i, j) exchanges the ith and jth bits of B, and shift(B, j, i) moves the jth bit of B leftwards into the ith position by moving the intermediate bits to the right. Formally, the swap and shift operations are deﬁned as follows: – swap(B, i, j) = B1 · · · Bi−1 Bj Bi+1 · · · Bj−1 Bi Bj+1 · · · Bn , and – shift(B, j, i) = B1 · · · Bi−1 Bj Bi Bi+1 · · · Bj−1 Bj+1 · · · Bn . When appropriate we shorten swap(B, i, j) to swap(i, j), and shift(B, j, i) to shift(j, i). Swaps are also known as transpositions with special cases including – adjacent-transpositions: swap(i, i+1), – two-close-transpositions: swap(i, i+1) or swap(i, i+2), and – homogeneous-transpositions: swap(B, i, j) where Bi = Bi+1 = · · · = Bj−1 . Preﬁx-shifts are usually deﬁned as operations of the form shift(j, 1). Swaps and preﬁx-shifts are eﬃcient operations for binary strings stored in arrays and computer words, respectively. Given an order of combinatorial objects, the rank of an object is its position in the order. Ranking determines the rank of a particular object in a given order, and unranking determines the object with a particular rank in a given order. 1.3

CoolCat Order

Balanced parentheses are among the most studied objects in combinatorial generation [3] but fewer results exist for k-ary Dyck words. Generation of Dk (t) was ﬁrst discussed by Zaks [10]. A general result by Pruesse and Ruskey implies that Dk (t) has a 2-adjacent-transposition Gray code [4] and a result by Canﬁeld and Williamson [1] proves that Dk (t) can be generated by a loopless algorithm1 . More recently, Vajnovszki and Walsh [9] found a two-close transposition Gray 1

Both results use that strings in Dk (t) correspond to linear-extensions of a poset with cover relations a1 ≺ · · · ≺ at , b1 ≺ · · · ≺ b(k−1)t , and ai ≺ b(k−1)(i−1)+1 for 1 ≤ i ≤ t.

184

S. Durocher et al.

code and created a loopless algorithm that requires twelve if-statements and O(n) additional variables stored in three additional arrays e, s, and p. Results on k-ary trees date back to Ruskey [5] and Trojanowski [8]. There are no preﬁx-shift Gray codes for Dk (t) (except when k, t ≤ 2). However, the ﬁrst bit of every k-ary Dyck word is 1, so we can instead deﬁne a prefix-shift as shift(i, 2) with the understanding that the redundant bit could be omitted from a computer word representation. Using this deﬁnition Ruskey and Williams [7] discovered an ordering of D2 (t) with the following properties: – it is both a cyclic preﬁx-shift Gray code, and a cyclic 2-swap Gray code that uses at most one adjacent-transposition and one homogeneous -transposition, – it can be generated by a loopless algorithm using only two if-statements and two additional index variables, and – the ordering has an eﬃcient ranking algorithm. Furthermore, the Gray code can be created by the “successor rules” in Table 1. More speciﬁcally, every string in D2 (t) has a preﬁx that matches a unique rule in (1a)-(1d) which describes how the preﬁx is changed to obtain the next string. Table 1 uses exponentiation for symbol repetition, and the order for D2 (4) is: 10111000, 11011000, 11101000, 10110100, 11010100, 10101100, 11001100, 11100100, 10110010, 11010010, 10101010, 11001010, 11100010, 11110000. For example, the matched preﬁx for 11001100 is 1i 0j 11 with i = 2 and j = 2. By (1a), shift(i+j+1, 2) (or swap(i+1, i+j+1)) creates the next string 11100100. Similarly, the matched preﬁx for 11100100 is 1i 0j 10 with i = 3 and j = 2. By (1c), shift(i+j+2, 2) (or swap(2, i+1) swap(i+j+1, i+j+2)) creates 10110010. Table 1. Rules for generating balanced parentheses D2 (t) from [7]. Preﬁxes change according to (1a)-(1d) by the speciﬁed shift or the equivalent swap(s). † j > 0.

(1a) (1b) (1c) (1d)

Current Preﬁx† 1i 0j 11 1i 0j 10 for i = j 1i 0j 10 for i > j 1i 0j for i = j = t

Next Preﬁx 1i+1 0j 1 1i+1 0j+1 101i−1 0j 1 101i−1 0j−1

Shift (i+j+1, 2) (i+j+1, 2) (i+j+2, 2) (i+j, 2)

Swap(s) (i+1, i+j+1) (i+1, i+j+1) (2, i+1) (i+j+1, i+j+2) (2, i+1)

Rules (1a) and (1b) can be combined (see [7]) since they perform the same operation and Rule (1d) simply transforms the ‘last’ string in the cyclic Gray code into the ‘ﬁrst’ string. The Gray code is also interesting because it generates Dk (t) according to a cyclic Gray code for B(kt, t) known as cool-lex order. That is, if α ∈ Dk (t) comes before β ∈ Dk (t) in the cool-lex order of B(kt, t), then α comes before β in the Gray code deﬁned by Table 1. The order and algorithm are named “CoolCat” after cool-lex order and the Catalan numbers. Theorem 1 ([7]). The balanced parentheses of length 2t in D2 (t) are generated in cool-lex order by the prefix-shift (or equivalent swap(s)) in Table 1.

Ranking and Loopless Generation of k-ary Dyck Words in Cool-lex Order

1.4

185

Bubble Languages and Cool-lex Order

A bubble language 2 is a set of binary strings L ⊆ B(n, t) with the following property: If B ∈ L where B = 1i 0j 01γ for some j ≥ 0, then 1i 0j 10 ∈ L. In other words, they are sets of binary strings with the same content in which the leftmost 01 of any string can be replaced by 10 to give another string in the set. This deﬁnition comes from Ruskey, Sawada, and Williams who showed that bubble languages generalize many combinatorial objects including binary necklaces and solutions to knapsack problems [6]. They substantially generalized Theorem 1 by proving that cool-lex order provides a cyclic Gray code for any bubble language. In particular, the successor rules in Table 2 generate all of these Gray codes. Lemma 1 ([6]). The k-ary Dyck words in Dk (t) are a bubble language. Furthermore, the k-ary Dyck prefixes in Dk (t, s) (see Section 4) are a bubble language. Proof. Replacing 01 by 10 cannot decrease the number of 1s in a string’s preﬁx. Table 2. Rules for generating a bubble language L from [6]. Strings change according to (2a)-(2e) by the speciﬁed shift or equivalent swap(s). † j > 0. ‡ h is the minimum value such that 1h 01i−h 0j 1γ ∈ L and g is the minimum value such that 1g 01i−g 0j−1 ∈ L. (2a) (2b) (2c) (2d) (2e)

Current String† Next String‡ 1 0 11γ 1i+1 0j 1γ i j i j+1 1 0 10γ for 1 0 1γ ∈ / L 1i+1 0i+1 γ i j i j+1 1 0 10γ for 1 0 1γ ∈ L 1h 01i−h 0j 1γ 1i 0j 1g 01i−g 0j−1 i j 10 1 1i+1 0j i j

Shift (i+j+1, 1) (i+j+1, 1) (i+j+2, h+1) (i+j, g+1) (i+j+1, 1)

Swap(s) (i+1, i+j+1) (i+1, i+j+1) (h+1, i+1) (i+j+1, i+j+2) (g+1, i+1) (i+1, i+j+1)

Theorem 2 ([6]). The strings in any bubble language are generated in cool-lex order by the shift (or equivalent swap(s)) in Table 2. We will examine how this result applies to k-ary Dyck words later in this article. In the meantime, observe that the rules in Table 2 refer to entire strings, and not just speciﬁc preﬁxes as in Table 1. This is due to the fact that bubble languages do not necessarily have the separability property mentioned in Remark 1. Also note that Table 2 produces a shift Gray code that is not necessarily a preﬁx-shift Gray code. On the other hand, the Gray code is still a 2-swap Gray code using at most one adjacent-transposition and one homogeneous-transposition. 1.5

New Results

We apply Theorem 2 to obtain a simple set of successor rules that generate a cyclic preﬁx-shift Gray code of k-ary Dyck words in Section 2. Then we use the Gray code as the basis for two loopless generation algorithms that store the 2

These are called “binary ﬁxed-density bubble languages” in [6].

186

S. Durocher et al.

current string in an array in Section 3. The ﬁrst algorithm works for constant k and requires only two additional index variables. The second algorithm works for arbitrary k and requires four if-statements and one array of O(n) additional index variables. In Section 4 we show how the Gray code can be eﬃciently ranked and unranked. With respect to the existing literature these results include – the ﬁrst preﬁx-shift Gray code for k-ary Dyck words [6], – the ﬁrst loopless algorithm for generating k-ary Dyck words that uses O(1) additional index variables (when k is constant), – a simpler loopless algorithm for generating k-ary Dyck words using 1/3 the if-statements and additional arrays as [9] (when k is arbitrary), and – the ﬁrst order of k-ary Dyck words that has a loopless generation algorithm as well as eﬃcient ranking and unranking algorithms. Our results also include the ﬁrst application of bubble languages to loopless generation and eﬃcient ranking and unranking. Due to the generalization from “CoolCat” to k-ary Dyck words, we name the order and algorithms “CoolKat”.

2

CoolKat Order

In this section we specialize the cool-lex Gray code for bubble languages to the special case of k-ary Dyck words of length kt. In particular, Theorem 3 will prove that k-ary Dyck words can be generated cyclically using the rules in Table 3. The resulting “CoolKat” order appears below for D3 (3) 101100000, 110100000, 101010000, 100110000, 110010000, 101001000, 100101000, 110001000, 101000100, 100100100, 110000100, 111000000. As in Table 1 for balanced parentheses, the rules in Table 3 refer to string preﬁxes and the stated shifts are preﬁx-shifts. Also, the rule (3d) refers only to the ‘last’ string 1t 0(k−1)t . In the second half of this section we optimize the swap rules in Table 3 for the array-based loopless algorithms in Section 3. Table 3. New rules for generating k-ary Dyck words Dk (t) in cool-lex order. These rules generalize those in Table 1 and specialize those in Table 2. † j > 0. Current Preﬁx† (3a) 1 0 11 (3b) 1i 0j 10 for (k−1)i = j (3c) 1i 0j 10 for (k−1)i > j (3d) 1i 0j for i = t, j = (k − 1)t i j

Next Preﬁx 1i+1 0j 1 1i+1 0j+1 101i−1 0j 1 101i−1 0j−1

Shift (i+j+1, 2) (i+j+1, 2) (i+j+2, 2) (i+j, 2)

Swap(s) (i+1, i+j+1) (i+1, i+j+1) (2, i+1) (i+j+1, i+j+2) (2, i+1)

Theorem 3. The k-ary Dyck words of length kt are generated in cool-lex order by the rules in Table 3.

Ranking and Loopless Generation of k-ary Dyck Words in Cool-lex Order

187

Proof. Since L = Dk (t) is a bubble language [6], Theorem 2 implies that its strings are generated by Table 2. We now compare each rule in Table 2 to its proposed specialization in Table 3. In the comparison, recall that (2a)-(2e) refer to entire strings, whereas (3a)-(3d) refer to preﬁxes, and that j > 0 is always assumed in 1i 0j 1. Current Next Shift Swap (2a) 1i 0j 11γ 1i+1 0j 1γ (i+j+1, 1) (i+1, i+j+1) (3a) 1i 0j 11 1i+1 0j 1 (i+j+1, 2) (i+1, i+j+1) If a k-ary Dyck word has preﬁx 1i 0j 11 and j > 0, then it must be that i > 0. Therefore, shift(i+j+1, 2) in (3a) is the special case of shift(i+j+1, 1) in (2a). Current Next Shift Swaps (2b) 1i 0j 10γ for 1i 0j+1 1γ ∈ / L 1i+1 0i+1 γ (i+j+1, 1) (i+1, i+j+1) (3b) 1i 0j 10 for (k−1)i = j 1i+1 0j+1 (i+j+1, 2) (i+1, i+j+1) Suppose 1i 0j 10γ is a k-ary Dyck word. Remark 1 implies that 1i 0j+1 1γ is not k-ary Dyck word if and only if (k−1)i = j. Therefore, the condition “for (k−1)i = j” in (3b) is a special case of the condition “for 1i 0j+1 1γ ∈ / L” in (2b). Next observe that i > 0 since k-ary Dyck words must begin with the symbol 1. Therefore, shift(i+j+1, 2) in (3b) is the special case of shift(i+j+1, 1) in (2b). Current Next‡ Shift Swaps i j+1 h (2c) 1 0 10γ for 1 0 1γ ∈ L 1 01i−h 0j 1γ (i+j+2, h+1) (i+j+1, i+j+2) (h+1, i+1) (3c) 1i 0j 10 for (k−1)i > j (i+j+2, 2) (i+j+1, i+j+2) (2, i+1) 101i−1 0j 1 ‡ h is the minimum value such that 1h 01i−h 0j 1γ ∈ L. i j

Suppose 1i 0j 10γ is a k-ary Dyck word. Remark 1 implies that 1i 0j+1 1γ is a k-ary Dyck word if and only if (k−1)i > j. Therefore, the condition “for (k−1)i > j” in (3c) is a special case of the condition “for 1i 0j+1 1γ ∈ L” in (2c). Next observe that Remark 1 implies that h = 1 is the minimum value such that 1h 01i−h 0j 1γ ∈ L. Therefore, the shifts and swaps in (3c) are special cases of those in (2c). Current Next‡ Shift Swaps g (2d) 1i 0j 1 01i−g 0j−1 (i+j, g+1) (g+1, i+1) (3d) 1i 0j for i = t, j = (k − 1)t 101i−1 0j−1 (i+j, 2) (2, i+1) ‡ g is the minimum value such that 1g 01i−g 0j−1 ∈ L.

By similar reasoning as above, g = 1 is the minimum value such that 1g 01i−g 0j−1 is a k-ary Dyck word. Current Next Shift Swaps (2e) 1i 0j 1 1i+1 0j (i+j+1, 1) (i+1, i+j+1) This general rule for bubble languages does not apply to k-ary Dyck words because k-ary Dyck words cannot have 1 as the last symbol.

188

2.1

S. Durocher et al.

Optimized Swap Rules

Table 4 gives swap rules that are equivalent to those in Table 3. In these rules, swap(i+1, i+j+1) is performed when creating the successor of every string (except 1t0(k−1)t ). This allows more compact array-based algorithms in Section 3. Table 4. Equivalent swap rules for generating k-ary Dyck words. These swap rules diﬀer slightly from those in Table 3 and allow for a more eﬃcient algorithm.† j > 0. Current Preﬁx† (4a) 1 0 11 (4b) 1i 0j 10 for (k−1)i = j (4c) 1i 0j 10 for (k−1)i > j (4d) 1i 0j for i = t, j = (k − 1)t i j

Next Preﬁx 1i+1 0j 1 1i+1 0j+1 101i−1 0j 1 101i−1 0j−1

Swap(s) (i+1, i+j+1) (i+1, i+j+1) (i+1, i+j+1) (2, i+j+2) (2, i+1)

Corollary 1. Dk (t) is generated in cool-lex order by the rules in Table 4. Proof. The swap(s) are identical to those in Table 3 except for (4c) below. Current Preﬁx Next Preﬁx Swap(s) (3c) 1i 0j 10 for (k−1)i > j 101i−1 0j 1 (i+j+1, i+j+2) (2, i+1) (4c) 1i 0j 10 for (k−1)i > j 101i−1 0j 1 (i+1, i+j+1) (2, i+j+2) When B ∈ Dk (t) has preﬁx 1i 0j 10 with j > 0, then the relevant bit values are 1 if i > 1 B[2] = B[i+1] = 0, B[i+j+1] = 1, and B[i+j+2] = 0. 0 if i = 1, If i > 1, then (3c) and (4c) both change the preﬁx to 101i−1 0j 1. If i = 1, then (3c) and (4c) both change the preﬁx to 1i 0j 01 = 10j 1i−1 01 via swap(i+j+1, i+j+2).

3

Loopless Algorithms

In this section we provide two loopless algorithms for generating k-ary Dyck words in cool-lex order: coolkat (for “small” k) and coolKat (for “large” k). 3.1

Algorithm for Constant k

We begin with coolkat, which is a simple algorithm that uses only two additional index variables. We prove its correctness in Theorem 4 and then prove that it is loopless for constant k in Theorem 5. Theorem 4. Algorithm coolkat(k, t) generates each successive k-ary Dyck word of length kt in cool-lex order.

Ranking and Loopless Generation of k-ary Dyck Words in Cool-lex Order Procedure coolkat(k, t) 1: 2: B ← array(1t 0(k−1)t ) 3: x ← t 4: y ← t 5: visit() 6: while x < k(t − 1) + 1 7: B[x] ← 0 8: B[y] ← 1 9: x ←x+1 10: y ←y+1 11: if B[x] = 0 then 12: if x − 2 = k(y − 2) then 13: 14: while B[x] = 0 15: x ←x+1 16: end 17: 18: else 19: B[x] ← 1 20: B[2] ← 0 21: if y > 3 then 22: x←3 23: end 24: y←2 25: end 26: end 27: visit() 28: end

189

Procedure coolKat(k, t) 1: A ← array(0t−2 ) 2: B ← array(1t 0(k−1)t ) 3: x ← t 4: y ← t 5: visit() 6: while x < k(t − 1) + 1 7: B[x] ← 0 8: B[y] ← 1 9: x←x+1 10: y ←y+1 11: if B[x] = 0 then 12: if x − 2 = k(y − 2) then 13: if B[x + 1] = 1 then 14: A[y − 2] ← 0 15: end 16: A[y − 2] ← A[y − 2] + 1 17: x ← x + A[y − 2] 18: else 19: B[x] ← 1 20: B[2] ← 0 21: if y > 3 then 22: x←3 23: end 24: y←2 25: end 26: end 27: visit() 28: end

Algorithms 1: coolkat(k, t) and coolKat(k, t) generate k-ary Dyck words of length kt in cool-lex order for any k, t ≥ 1 (with 1t 0(k−1)t visited ﬁrst). Proof. We prove that the “main loop” on lines 6-28 always modiﬁes B according to Table 4 by induction on the number of iterations. The ﬁrst iteration visits 1t 0(k−1)t and the second iteration begins with y = 2, x = 3, and B = 101t−1 0(k−1)t−1 , which is correct by (4c). The second iteration provides a base case for the following main-loop invariant: If B has preﬁx 1i 0j 1 for j > 0 on line 6, then y = i + 1 and x = i + j + 1. Inductively suppose this invariant holds for the mth iteration and consider the next iteration. Lines 7-8 apply swap(i+1, i+j+1), which is the ﬁrst swap listed in each of (4a)-(4c). Lines 9-10 increment the additional variables to y = i + 2 and x = i + j + 2. Now consider the possible paths through the algorithm. – If B[x] = 1 on line 11, then the mth string in cool-lex order had preﬁx 1i 0j 11. By (4a) the successor has already been obtained by swap(i+1, i+j+1). Furthermore, y = i + 2 and x = i + j + 2 correctly satisfy the invariant.

190

S. Durocher et al.

– If B[x] = 0 on line 11, then the mth string in cool-lex order had preﬁx 1i 0j 10. • If x − 2 = k(y − 2) on line 12, then j = (k − 1)i by simple algebra. By (4b) the successor has already been obtained by swap(i+1, i+j+1). Furthermore, y = i + 2 is correct. Since B now has preﬁx 1i+1 0j+1 , x is greater than its current value of i + j + 2. The loop on line 14 scans the remainder of the B to determine the correct value of x. • If x − 2 < k(y − 2) on line 12, then j < (k − 1)i. Lines 19-20 correctly apply swap(2, i + j + 2) by (4c) and change the preﬁx of B to 101i−1 0j 1. ∗ If y > 3 on line 21, then i > 1 and x = 2 is correctly set by line 22. ∗ If y = 3 on line 21, then i = 1 and the current value of x = i + j + 2 is already correct. Finally, y = 2 is correctly set by line 24. This induction continues until B = 1t−1 0(k−1)(t−1) 10k−1 since this is the only string in Dk (t) for which x ≥ k(t − 1) + 1 by the loop-invariant x = i + j + 1. By (4b) the successor of 1t−1 0(k−1)(t−1) 10k−1 is 1t 0(k−1)t , which was the ﬁrst string visited. Therefore, coolkat(k, t) visits every string in Dk (t). Now we analyze coolkat. We need to show that the loop on line 14 runs a constant number of times when generating k-ary Dyck words for constant k. Towards this goal we present the following lemma. Lemma 2. If 1i 0j 10γ is a k-ary Dyck word and j = (k − 1)i, then γ does not have 0k−1 as a prefix. Proof. A k-ary Dyck word cannot have 1i 0(k−1)i 10k as a preﬁx.

Theorem 5. Algorithm coolkat(k, t) uses two additional variables, and when k is a constant each successive string is created in worst-case O(1)-time. Proof. The algorithm uses the input values k and t, and stores the current k-ary Dyck word in the array B. Otherwise, the only additional variables are x and y. Therefore, the stated memory requirements are correct. Next consider the run-time of creating each successive string in B. Notice that the only loop inside of the main loop on lines 6–28 is on 14. This loop is run when the current string stored in B at line 6 has a preﬁx equal to 1i 0(k−1)i 10. By Lemma 2, the next k bits in B cannot all be 0. Therefore, the line 14 runs at most k times. If k is treated as a constant, then this loop can be replaced by a constant number of nested if-statements. Therefore, when k is a constant, successive strings are created in worst-case O(1)-time. 3.2

Algorithm for Arbitrary k

To obtain a loopless algorithm for arbitrary k we perform the loop on line 14 with in O(1)-time by introducing an additional array of index variables A. Theorem 6. coolKat(k, t) is a loopless algorithm that generates each successive k-ary Dyck word of length kt in cool-lex order and uses only t index variables.

Ranking and Loopless Generation of k-ary Dyck Words in Cool-lex Order

191

Proof. Observe that coolkat and coolKat diﬀer only in line 1 and lines 13-17. These lines are executed in coolKat when B begins the main-loop with a preﬁx of the form 1i 0(k−1)i 10. By line 16, the A array is updated so that A[i] contains the number of 0s that follow the preﬁx of the form 1i 0(k−1)i 1. A formal proof of correctness requires an understanding of the recursive formulation of cool-lex order presented in Section 4 and is omitted.

4

Ranking and Unranking

In this section we generalize k-ary Dyck words, discuss cool-lex order recursively, and then eﬃciently rank and unrank k-ary Dyck words in cool-lex order. A string B ∈ B(s+t, t) is a k-ary Dyck prefix if the number of 0s in each preﬁx is at most k−1 times the number of 1s. Notice that k-ary Dyck preﬁxes with t 1s can have s ≤ (k−1)t 0s, whereas k-ary Dyck words with t 1s must have s = (k−1)t 0s. Let Dk (t, s) be the k-ary Dyck preﬁxes in B(s+t, t). Thus, Dk (t, s) = {B ∈ B(s + t, t) | B0(k−1)t−s ∈ Dk (t)}. Let Nk (t, s) be the cardinality of Dk (t, s). Also let v = (k−1)(t−1) in this section. The signiﬁcance of this value is that every B ∈ Dk (t, s) has suﬃx 0s−v if s > v. Lemma 3. Nk (t, s) = 0 if t = 0, Nk (t, s) = 1 if t > 0 and s = 0, and otherwise Nk (t−1, s) + Nk (t, s−1) if 1 ≤ s ≤ v; kt+1 Nk (t, s) = 1 if v < s ≤ (k − 1)t. kt+1 t Proof. Dk (0, s) = ∅ and Dk (t, 0) = {1t} if t > 0. If 1 ≤ s ≤ v, then B1 ∈ Dk (t, s) ⇐⇒ B ∈ Dk (t−1, s) and B0 ∈ Dk (t, s) ⇐⇒ B ∈ Dk (t, s−1). Thus, Nk (t, s) = Nk (t−1, s)+Nk (t, s−1). If v < s ≤ (k−1)t, then all strings in Dk (t, s) kt+1 1 end in 0 and B ∈ Dk (t, s) ⇐⇒ B0(k−1)t−s ∈ Dk (t). Thus, Nk (t, s) = kt+1 t by the bijection between Dk (t) and k-ary trees with t internal nodes [3,10]. Ruskey, Sawada, Williams [6] prove that the following recursive formula gives the cool-lex order of any bubble language L. The formula is explained below. C(t−1, 1, 10s−1 γ), . . . , C(t−1, s−j, 10j γ), 1t 0s γ if t > 0; (1a) C(t, s, γ) = s 0 γ if t = 0. (1b) If 1t 0s γ ∈ L and γ doesn’t begin with 0, then C(t, s, γ) is the cool-lex order for the strings in L with suﬃx γ. The “ﬁxed-suﬃx” γ is extended in turn in (1) to 10s−1 γ, 10s−2 γ, . . . , 10j γ where j is the minimum value such that 10j γ is the suﬃx of a string in L. Notice that γ is extended by 10i for decreasing i with one exception: The single string resulting from i = s (namely, 1t 0s γ = 1t−1 10s γ = C(t−1, 0, 10s γ)) is last instead of ﬁrst. In fact, this is the only diﬀerence between cool-lex order and conventional “co-lex order” (see [3] for lexicographic orders). The entire cool-lex order for some L with 1t 0s ∈ L is C(t, s, ). Now we specialize cool-lex order to k-ary Dyck preﬁxes. Let the coolKat order for L = Dk (t, s) be denoted Dk (t, s, ) = C(t, s, ).

192

S. Durocher et al.

Lemma 4. CoolKat order is Dk (t, s, γ) = if t = 0, and otherwise Dk (t−1, 1, 10s−1 γ), . . . , Dk (t−1, s, 1γ), 1t0s if s ≤ v; Dk (t, s, γ) = s−1 s−v t s Dk (t−1, 1, 10 γ), . . . , Dk (t−1, v, 10 γ), 1 0 if v < s ≤ (k−1)t. Proof. L = Dk (t, s) is a bubble language, so Dk (t, s, γ) follows from (1) by giving the minimum j such that 10j is the suﬃx of a string in L. If s ≤ v, then j = 0 by 1t−1 0s 1 ∈ L. If v < s ≤ (k − 1)t, then j = s − v by 1t−1 0s 10s−v ∈ L. Now we eﬃciently rank and unrank k-ary Dyck preﬁxes with examples after Theorems 7 and 8. With respect to an ordered set of strings L = B1 , B2 , . . . , Bm , the rank of Bi is rank(Bi , L) = i−1, and unrank(i−1, L) = Bi for 1 ≤ i ≤ m. For convenience let R(B, L) = rank(B, L)+ 1. Also let Dk (t, s) denote Dk (t, s, ). Theorem 7. If B = α10m ∈ Dk (t, s) for possibly empty α and m ≥ 0, then ⎧ Nk (t, s) if B = 1t 0s ; ⎪ ⎪ ⎨ s−m−1

Nk (t−1, i) if B =1t 0s and s≤v; R(B, Dk (t, s)) = R(α, Dk (t−1, s−m))+ ⎪ i=1 ⎪ ⎩ R(β, Dk (t, v)) otherwise, where β is the first t + v bits of B. Proof. If B = 1t 0s , then R(B, Dk (t, s)) = Nk (t, s) since B is last in Dk (t, s) by Lemma 4. If B = 1t 0s and 0 ≤ s ≤ v, then Dk (t−1, i) appears before B in Dk (t, s) for 1 ≤ i ≤ s−m−1 by Lemma 4. If s > v, then by Lemma 4 each string of Dk (t, v) appears as a preﬁx of the corresponding string in Dk (t, s), i.e., Dk (t, s) = Dk (t, v, 0s−v ). Therefore, R(B, Dk (t, s)) = R(β, Dk (t, v)). With respect to an ordered set of strings L, let U(x, L) = unrank(x−1). Theorem 8

⎧ t s 10 if x = Nk (t, s); ⎪ ⎪ ⎨ y

s−y−1 Nk (t−1, i), Dk (t−1, y+1))10 if x i=1 Nk (t−1, i).

Proof. If x = Nk (t, s), then U(x, Dk (t, s)) is the last string in Dk (t, s) and by Lemma 4, U(x, Dk (t, s)) = 1t 0s . We now consider the case when x < Nk (t, s) and 0 ≤ s ≤ v. Let p be an integer,

p−1 Nk (t−1, i). such that U(x, Dk (t, s)) is in Dk (t, p, 10s−p ). By Lemma 4, x > i=1 It is now straightforward to observe that y = p − 1. Therefore, U(x, Dk (t, s)) =

y U(x − i=1 Nk (t − 1, i), Dk (t−1, y + 1))10s−y−1 . The remaining case is x < Nk (t, s) and s > v. By Lemma 4, each string of Dk (t, v) appears as a preﬁx of the corresponding string in Dk (t, s), i.e., Dk (t, s) = Dk (t, v, 0s−v ). Therefore, U(x, Dk (t, s)) = U(x, Dk (t, v))0s−v .

Ranking and Loopless Generation of k-ary Dyck Words in Cool-lex Order

193

We precompute and store the values of Nk (t, s) in a table so that for any value of k, t, s, we can obtain Nk (t, s) in O(1) time. As a result we obtain O(t + s)time ranking and unranking algorithms for k-ary Dyck words using Theorems 7 and 8, respectively. For example, the following table illustrates the ﬁrst few values of Nk (t, s) for k = 5. In the ranking and unranking process we assume that such tables for small ﬁxed values of k are computed in advance. Thus for the corresponding precomputed values, we can obtain Nk (t, s) in O(1) time. N5 (t, s) t=1 t=2 t=3

s=0 1 1 1

s=1 1 2 3

s=2 1 3 6

s=3 1 4 10

s=4 s=5 s=6 s=7 s=8 s=9 s=10 s=11 s=12 1 5 5 5 5 5 15 20 25 30 35 35 35 35 35

We now compute R(100100010, D5(3, 6)) and U(16, D5 (3, 6)) as follows:

6−1−1 R(100100010, D5(3, 6)) = R(1001000, D5(2, 5)) + i=1 N5 (2, i)

= R(100, D5 (1, 2)) + 5−3−1 N5 (1, i) + 4i=1 N5 (2, i) i=1

1

4 = N5 (1, 2) + i=1 N5 (1, i)+ i=1 N5 (2, i) = 16.

4 U(16, D5 (3, 6)) = U(16 − i=1 N5 (2, i), D5 (2, 5))106−4−1 = U(2, D5 (2, 5))10 = U(2, D5 (2, 4))05−(2−1)(5−1) 10

= U(2 − 1i=1 N5 (1, i), D5 (1, 2))104−1−1 010 = U(1, D5 (1, 2))100010 = 100100010. Acknowledgements. We thank Frank Ruskey for helpful conversations.

References 1. Canﬁeld, E., Williamson, S.: A loop-free algorithm for generating the linear extensions of a poset. Order 12, 57–75 (1995) 2. Heubach, S., Li, N.Y., Mansour, T.: A garden of k-Catalan structures (2008), http://www.scientificcommons.org/43469719 3. Knuth, D.E.: The Art of Computer Programming: Generating all Trees and History of Combinatorial Generation, vol. 4. Addison-Wesley (2006) 4. Pruesse, G., Ruskey, F.: Generating the linear extensions of certain posets by transpositions. SIAM Journal on Discrete Mathematics 4(3), 413–422 (1991) 5. Ruskey, F.: Generating t-ary trees lexicographically. SIAM Journal on Computing 7(4), 424–439 (1978) 6. Ruskey, F., Sawada, J., Williams, A.: Binary bubble languages and cool-lex order, 13 pages (2010) (under review)

194

S. Durocher et al.

7. Ruskey, F., Williams, A.: Generating balanced parentheses and binary trees by preﬁx shifts. In: Proceedings of the 14th Computing: The Australasian Theory Symposium (CATS 2008), NSW, Australia, January 22-25, vol. 77, pp. 107–115 (2008) 8. Trojanowski, A.E.: Ranking and listing algorithms for k-ary trees. SIAM Journal on Computing 7(4), 492–509 (1978) 9. Vajnovszki, V., Walsh, T.: A loop-free two-close Gray-code algorithm for listing k-ary Dyck words. Journal of Discrete Algorithms 4(4), 633–648 (2006) 10. Zaks, S.: Generation and ranking of k-ary trees. Information Processing Letters 14(1), 44–48 (1982)

Two Constant-Factor-Optimal Realizations of Adaptive Heapsort Stefan Edelkamp1, , Amr Elmasry2 , and Jyrki Katajainen2, 1

2

TZI, Universit¨ at Bremen, Germany Department of Computer Science, University of Copenhagen, Denmark

Abstract. In this paper we introduce two eﬃcient priority queues. For both, insert requires O(1) amortized time and extract -min O(lg n) worstcase time including at most lg n + O(1) element comparisons, where n is the number of elements stored. One priority queue is based on a weak heap (array-based) and the other on a weak queue (pointer-based). In both, the main idea is to temporarily store the inserted elements in a buﬀer, and once it is full to move its elements to the main queue using an eﬃcient bulk-insertion procedure. By employing the new priority queues in adaptive heapsort, we guarantee, for several measures of disorder, that the formula expressing the number of element comparisons performed by the algorithm is optimal up to the constant factor of the high-order term. We denote such performance as constant-factor optimality. Unlike some previous constant-factor-optimal adaptive sorting algorithms, adaptive heapsort relying on the developed priority queues is practically workable. Keywords: Priority queues, weak heaps, weak queues, adaptive sorting, adaptive heapsort, constant-factor optimality.

1

Introduction

A sorting algorithm is adaptive if it changes its performance according to the presortedness within the input. When sorting n elements, the running time of such algorithm is O(n) for sequences that are sorted or almost sorted, and O(n lg n) for sequences that have a high degree of disorder. It is important to note that such algorithms do not know in advance about the amount of existing disorder. In the literature, several measures of disorder that characterize the input sequence have been considered [18]. An adaptive sorting algorithm is said to be asymptotically optimal, or simply optimal, if its running time asymptotically matches the lower bound derived using the number of input elements and the amount of disorder as parameters. In this paper we focus on a stronger form of optimality. We call an asymptotically-optimal algorithm constant-factor-optimal, if the number of element comparisons performed matches the information-theoretic

Partially supported by DFG grant ED 74/8-1. Partially supported by the Danish Natural Science Research Council under contract 09-060411 (project “Generic programming—algorithms and tools”).

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 195–208, 2011. c Springer-Verlag Berlin Heidelberg 2011

196

S. Edelkamp, A. Elmasry, and J. Katajainen

lower bound up to the constant factor hidden behind the big-Oh notation, i.e. the constant factor multiplied by the high-order term. Some of the known measures of disorder are the number of oscillations Osc [15], the number of inversions Inv [14], the number of runs Runs [14], the number of blocks Block [3], and the measures Max , Exc and Rem [3]. Some measures dominate the others: every Osc-optimal algorithm is Inv optimal and Runs optimal; every Inv -optimal algorithm is Max optimal [15]; and every Block -optimal algorithm is Exc optimal and Rem optimal [3]. Natural mergesort, described by Knuth [14, Section 5.2.4], is an example of an adaptive sorting algorithm that is constant-factor-optimal; this is with respect to the measure Runs. For a sequence X = x1 , x2 , . . . , xn , the number of inversions is the number of pairs of elements that are in the wrong order, i.e. Inv(X) = |{(i, j) | 1 ≤ i < j ≤ n and xi > xj }| [14, Section 5.1.1]. An with respect to the optimal algorithm measure Inv sorts a sequence X in Θ(n lg Inv(X)/n +n)time. The optimality is implied by the information-theoretic lower bound Ω(n lg Inv (X)/n +n) known for the number of element comparisons performed by any sorting algorithm with respect to the parameters n and Inv [12]. A constant-factor-optimal algorithm should perform at most n lg Inv (X)/n + O(n) element comparisons. Several adaptive sorting algorithms are known to be asymptotically optimal with respect to the measure Inv . The known approaches are inspired by insertionsort [7,8,12,19,20,23], quicksort [16], mergesort [8,21], or heapsort [6,15]. However, only a few of the known algorithms are constant-factor-optimal; these are the insertionsort-based and mergesort-based algorithms of Elmasry and Fredman [8], and the heapsort-based algorithm of Levcopoulos and Petersson [15] when implemented with the multipartite priority queue of Elmasry et al. [10]. Most of these algorithms are complicated and have never been implemented. Adaptive heapsort [15] is optimal with respect to all the aforementioned measures of disorder. We recall the description and analysis of adaptive heapsort in Section 2. In this paper we present two new realizations of adaptive heapsort. Our main motivation is to use, instead of a worst-case eﬃcient priority queue [10], a simpler priority queue that can support insert in O(1) amortized time and extract-min in O(lg n) worst-case time including at most lg n + O(1) element comparisons. From these bounds and the analysis given in [15], the constant-factor optimality follows for the following measures of disorder: Osc, Inv , Runs, and Max . Our main contribution is to present two priority queues with the required performance guarantees. The ﬁrst priority queue improves over a weak heap (an array-based priority queue described in the context of sorting by Dutton [4] and further analysed by Edelkamp and Wegener [5]). We modify and analyse this priority queue in Section 3. The second priority queue improves over a weak queue (a binomial queue implemented using binary trees as suggested by Vuillemin [24]). We modify and analyse this priority queue in Section 4. The simple—but powerful—tool we used in both data structures is a buﬀer, into which the new elements are inserted. When the buﬀer becomes full, all its elements are moved to the main queue. In accordance, for both priority queues, we give an eﬃcient bulk-insertion procedure.

Two Constant-Factor-Optimal Realizations of Adaptive Heapsort

197

We demonstrate the eﬀectiveness of our approach by comparing the new realizations to the best implementations of known eﬃcient sorting algorithms (splaysort [20] and introsort [22]). Our experimental settings, measurements, and outcomes are discussed in Section 5.

2

Adaptive Heapsort

In this section we describe the basic version of adaptive heapsort [15] and summarize the analysis of its performance. The algorithm begins by building the Cartesian tree [25] for the input X = x1 , . . . , xn . The root of the Cartesian tree stores xk = min{x1 , . . . , xn }, the left subtree of the root is the Cartesian tree for x1 , . . . , xk−1 , and the right subtree of the root is the Cartesian tree for xk+1 , . . . , xn . Such a tree can be built in O(n) time [11] by scanning the input in order and inserting each element xi into the existing tree as follows. The nodes along the right spine of the tree (the path from the root to the rightmost leaf) are traversed bottom up, until a node with an element xj that is not larger than xi is found. In such case, the right subtree of the node of xj is made the left subtree of the node of xi , and the node of xi is made the right child of the node of xj . If xi is smaller than all the elements on the right spine, the whole tree is made the left subtree of the node of xi . This procedure requires at most 2n − 3 element comparisons [15]. The algorithm proceeds by moving the smallest element at the root of the Cartesian tree into a priority queue. The algorithm then continues by repeatedly outputting and deleting the minimum from the priority queue. After each deletion, the elements at the children of the Cartesian-tree node corresponding to the deleted element are inserted into the priority queue. As for the priorityqueue operations, n insert and n extract-min operations are performed. But, the heap will be small if the input sequence has a high amount of existing order. The following improvement to the algorithm [15] is both theoretically and practically eﬀective; even though, in this paper, it only aﬀects the constant in the linear term. Since at least n/2 of the extract-min operations are immediately followed by an insert operation (deleting a node that is not a leaf of the Cartesian tree must be followed by an insertion), every such extract-min can be combined with the following insert . This can be implemented by replacing the minimum of the priority queue with the new element and thereafter reestablishing the heap properties. Accordingly, the cost for half of the insertions will be saved. The worst-caserunning time of the algorithm is O(n lg Osc(X)/n + n) = O(n lg Inv (X)/n + n) [15]. For a constant β, the number com of element parisons performed is βn lg Osc(X)/n + O(n) = βn lg Inv (X)/n + O(n). Levcopolous and Petersson suggested using a binary heap [26], which results in β = 3 (can be improved to β = 2.5 by combining extract-min and insert whenever possible). By using a binomial queue [24], we get β = 2. By using a weak heap [4], we get β = 2 (can be improved to β = 1.5 by combining extract-min and insert). By using the complicated multipartite priority queue [10], we indeed get the optimal β = 1. The question then arises whether we can achieve the constant-factor optimality, i.e. β = 1, and in the meantime ensure practicality!

198

S. Edelkamp, A. Elmasry, and J. Katajainen

In addition to the priority queue, the storage required by the algorithm is 2n extra pointers for the Cartesian tree. (We need not keep parent pointers since, during the construction, on the right spine of the tree we can temporarily revert each right-child pointer to point to the parent.) We also need to store the n elements inside the nodes of the Cartesian tree, either directly or indirectly.

3

Weak Heaps with Bulk Insertions

A weak heap [4] is a binary tree, where each node stores an element. A weak heap is obtained by relaxing the requirements of a binary heap [26]. The root has no left child, and the leaves are found at the last two levels only. The height of a weak heap that has n elements is therefore lg n + 1. The weak-heap property enforces that the element stored at a node is not larger than all the elements stored in the right subtree of that node. In our implementation, illustrated in Fig. 1, besides the element array a an array r of reverse bits is used, i.e. ri ∈ {0, 1} for i ∈ {0, . . . , n − 1}. We use ai to refer to either the element at index i of array a or to a node in the corresponding tree structure. A weak heap is laid out such that, for ai , the index of its left child is 2i + ri , the index of its right child is 2i + 1 − ri , and (assuming i = 0) the index of its parent is i/2. Using the fact that the indices of the left and the right children of ai are exchanged when ﬂipping ri , subtrees can be swapped in constant time by setting ri ← 1 − ri . The distinguished ancestor of ai , i = 0, is the parent of ai if ai is a right child, and the distinguished ancestor of the parent of ai if ai is a left child. We use d -ancestor (i) to denote the index of such ancestor. The weak-heap property enforces that no element is smaller than that at its distinguished ancestor. To insert a new element e, we ﬁrst add e to the next available array entry, making it a leaf in the heap. To reestablish the weak-heap property, as long as e is smaller than the element at its distinguished ancestor, we swap the two elements and repeat this for the new location of e. It follows that insert requires O(lg n) time and involves at most lg n element comparisons. a)

0

b) 0

1

2

3

4

5

6

7

8

9

8

12

8 12 27 10 47 49 53 46 75 80 26 1 42 6

min heap

1

10 11 12

min buﬀer

53

3

2

10

27

7

5

46 49

4

47

10

8

26

75 80

9

Fig. 1. A weak heap of size 11 and a buﬀer of size 2: a) the array representation and b) the corresponding tree representation of the weak heap; the nodes, for which the reverse bits are set, are highlighted

Two Constant-Factor-Optimal Realizations of Adaptive Heapsort

199

The subroutine link combines two weak heaps into one weak heap conditioned on the following settings. Let ai and aj be two elements in a weak heap, such that ai is not larger than all the elements in the left subtree of aj . Conceptually, aj and its right subtree form a weak heap, while ai and the left subtree of aj form another weak heap. (Note that ai could be at any location of the array.) If aj < ai , the subroutine link swaps the two elements and ﬂips rj ; otherwise it does nothing. As a result, aj will not be larger than any of the elements in its right subtree, and ai will not be larger than any of the elements in the subtree rooted at aj . All in all, link requires O(1) time and involves one element comparison. To perform extract-min, the element stored at the root of the weak heap is swapped with that stored at the last occupied array entry. To restore the weakheap property, repeated link operations are performed that involve the current root of the weak heap; the details follow. The last node on the left spine (the path from a node to the leftmost leaf) of the right child of the root is identiﬁed. Starting from the child of the root, this is done by repeatedly traversing left children until reaching a node that has no left child. The path from this node to the child of the root is traversed upwards, and link operations are repeatedly performed between the root of the weak heap and the nodes along this path. The correctness of the extract-min operation follows from the fact that, after each link , the element at the root of the heap is not larger than all the elements in the left subtree of the node to be considered in the next link . Thus, extract-min requires O(lg n) time and involves at most lg n element comparisons. The cost of insert can be improved to an amortized constant. The key idea is to use a buﬀer that supports constant-time insertion. The buﬀer can be implemented as a resizable array. Additionally, a pointer to the minimum element in the buﬀer is maintained. The maximum size of the buﬀer is set to lg n, where n is the total number of elements stored. A new element is inserted into the buﬀer as long as its size is below the threshold. Once the threshold is reached, a bulk insertion is performed by moving all the elements of the buﬀer to the weak heap. For the extract-min operation, the minimum of the buﬀer is compared with the minimum of the weak heap, and accordingly the operation is performed either in the buﬀer or in the weak heap. Deleting the minimum of the buﬀer is done by removing the minimum and scanning the buﬀer to determine the new minimum. Almost matching the bounds for the weak heap, deleting the minimum of the buﬀer requires O(lg n) time and involves at most lg n− 2 element comparisons. Thus, extract-min involves at most lg n + 1 element comparisons. Let us now consider how to perform a bulk insertion in O(lg n) time (see Fig. 2). First, we move the elements of the buﬀer to the next available entries of the array that stores the weak heap. The main idea is to reestablish the weak-heap property bottom-up level-by-level. Starting with the inserted nodes, for each node we link its distinguished ancestor to it. We then consider the parents of these nodes on the next upper level, and for each parent we link its distinguished ancestor to it, restoring the weak-heap property up to this level. This is repeated until the number of nodes that we need to deal with at a level is two (or less). At this point, we switch to a more eﬃcient strategy. For each of

200

S. Edelkamp, A. Elmasry, and J. Katajainen input: a: array of elements, r: array of bits, buﬀer : array of elements right ← size(a) + size(buﬀer ) − 1 left ← max{size(a), right/2} while size(buﬀer ) > 0 size(a)++ a[size(a) − 1] ← buﬀer [size(buﬀer ) − 1] size(buﬀer )-size(r)++ r[size(r) − 1] ← 0 while right > left + 1 for j ∈ {right , right − 1, . . . , left} i ← d-ancestor (j) if a[j] < a[i] swap(a[i], a[j]) r[j] ← 1 − r[j] left ← left/2 right ← right /2 for j ∈ {left, right} while j = 0 i ← d-ancestor (j) if a[j] < a[i] swap(a[i], a[j]) r[j] ← 1 − r[j] j←i Fig. 2. The pseudo-code for bulk insertion in a weak heap

these two nodes, we reestablish the weak-heap property by traversing the path from such node towards the root. If the value of the current node x is smaller than that at its distinguished ancestor, we link the distinguished ancestor to x. We then repeat after setting x to be its old distinguished ancestor. The correctness of the bulk-insertion procedure follows since, before considering the ith level, the value at any node below level i is not smaller than that at its distinguished ancestor. Hence, the value at the distinguished ancestor of a node x at level i is guaranteed not to be larger than the value at any node of the left subtree of x; this ensures the validity of the link operations to be performed at level i. Once we reach the root, the weak-heap property is valid for all nodes. Let k be the number of elements moved from the buﬀer to the weak heap by the bulk-insertion procedure. The number of element comparisons performed at the ith iteration equals the number of link operations at the ith last level of the weak heap, which is at most (k − 2)/2i−1 + 2. Here, we use the fact that the number of parents of a contiguous block of b elements in the array of a weak heap is at most (b−2)/2+2. Since the number of iterations is at most lg n, the total n i−1 number of element comparisons is less than lg ·k + 2) < 2k + 2lg n. i=1 (1/2 When k = lg n, the number of element comparisons is less than 4lg n; this accounts for four comparisons per element in the amortized sense. Due to the

Two Constant-Factor-Optimal Realizations of Adaptive Heapsort

201

bulk insertion and the check for whether the minimum of the buﬀer is up to date or not, insert involves amortized ﬁve element comparisons in total. The running time of the bulk insertion is dominated by the localization of the distinguished ancestors of the involved nodes. To ﬁnd the distinguished ancestor of a node, we repeatedly go to the parent and check whether the current node is its right child or not. We call such an operation an ancestor check. We separately consider two parts of the procedure. The ﬁrst part comprises the process of ﬁnding the distinguished ancestors for the levels with more than two involved nodes. Recall that the total number of those nodes at the ith last level is k/2i−1 + O(1), for a total of 2k + o(k). Among the nodes involved, at most (2k + o(k))/2j need j ancestor checks to get to the distinguished ancestor, where j ≥ 1. This accounts for at most j≥1 j/2j−1 · (k + o(k)) < 4(k + o(k)) = 4lg n + o(lg n) ancestor checks. The second part comprises two path traversals towards the root, which involve at most 2lg n ancestor checks in total. We conclude that the amortized cost accounted per element is a constant.

4

Weak Queues with Bulk Insertions

In this section we resort to a binomial queue that is implemented using binary trees [24]; we call this variant a weak queue. This data structure is a collection of perfect weak heaps (binomial trees in the binary-tree form), where the size of each tree is a power of two. The binary representation of n speciﬁes the sizes of the perfect weak heaps that are present. A 1-bit at position r indicates that a perfect weak heap of size 2r is present. The rank of a perfect weak heap of size 2r is r. In our implementation, illustrated in Fig. 3, every node stores a pointer to its left child, a pointer to its right child, and (a pointer to) an element. Two perfect weak heaps of rank r can be linked to form a perfect weak heap of rank r + 1, by making the root that has the smaller element the root of the resulting weak heap, the other root the right child of the new root, and the previous right child of the new root the left child of the other root.

min queue

1

42

53

8

75 80

12

min buﬀer

27

10 26

46 49

47

Fig. 3. A buﬀer of size 2 and a weak queue of size 11 (1011 in binary)

202

S. Edelkamp, A. Elmasry, and J. Katajainen

To insert a node into a weak queue, we let the new node form a single-node tree. This may trigger a sequence of link operations until no two trees of the same rank exist. Still, the amortized cost per insert is a constant [24]. To perform extract-min, we scan the roots of the perfect weak heaps to ﬁnd the minimum. We then borrow the root of the smallest tree; let that root be x. In accordance, every node on the left spine of x’s right subtree becomes the root of a perfect weak heap, and these heaps are added to the collection. Hereafter, we detach the root with the minimum value; let that root be y. Now every node on the left spine of y’s right subtree is the root of a perfect weak heap. Using repeated link operations, the node x is combined with the roots of these heaps to create a perfect weak heap that has the same size as the heap rooted at y before the deletion. (A link operation is performed between x and the root of the smallest such heap, and the resulting heap is repeatedly linked with the next larger remaining heap, and so on.) It follows that extract -min requires O(lg n) time and involves at most 2lg n − 2 element comparisons. To speed things up, we maintain preﬁx-minimum pointers for the roots of the perfect weak heaps (for the origin of this idea, consult [10] and the references therein). The preﬁx-minimum pointer of the root of a heap of size 2r points to the root with the smallest value among the heaps of size 2j for j ≤ r. The overall minimum can be located by following the preﬁx-minimum pointer of the root of the largest heap. Now we have to borrow a node such that the preﬁx-minimum pointers need not be updated. As before, the borrowed node is repeatedly linked with the roots of the heaps resulting from detaching the minimum node. This requires r element comparisons if the rank of the deleted node is r. We still have to update the preﬁx-minimum pointers. The key idea is that we only need lg n − r element comparisons to update the preﬁx-minimum pointers of the larger heaps. Hence, extract-min involves at most lg n element comparisons. If we implement insert in the normal way, we then have to update the preﬁxminimum pointers; this would require a logarithmic number of element comparisons. Our way out is again to rely on bulk insertions (see Fig. 4). We collect at most lg n elements into a buﬀer, where n is the total number of elements stored. The buﬀer is implemented as a circular singly-linked list, having its minimum ﬁrst. When the buﬀer becomes full, we clear it by repeatedly inserting its elements into the weak queue in the normal way, without updating the preﬁxminimum pointers. After ﬁnishing these insertions, the preﬁx-minimum pointers are updated once. For the bulk insertion, an amortized analysis accounts for a constant amortized cost per element, involving amortized two element comparisons. Since it is necessary to maintain the minimum of the buﬀer, an insertion into the buﬀer involves one element comparison. This together with the bulk insertion accounts for three element comparisons per insert. We have to implement borrowing carefully so that it does not invalidate the preﬁx-minimum pointers. While performing no element comparisons, it takes O(lg n) time. If the buﬀer is non-empty, a node is borrowed from there. Otherwise, a node is borrowed from the main queue. If the size of the smallest heap is larger than one, the last node from the left spine of the right subtree of its

Two Constant-Factor-Optimal Realizations of Adaptive Heapsort

203

input: Q: queue of perfect weak heaps, buﬀer : list of nodes while size(buﬀer ) > 0 x ← pop(buﬀer ) insert(Q, x) update-preﬁx -minimum-pointers(Q) Fig. 4. The pseudo-code for bulk insertion in a weak queue. For a list, subroutine pop removes and returns its last node. For a queue, subroutine insert adds the given node to the queue and makes the necessary linkings leaving at most one heap per rank. Subroutine update-preﬁx -minimum-pointers updates all the preﬁx-minimum pointers as they may not be up to date after insert operations.

root is borrowed. The root and the other nodes on the left spine are added as new roots to the main structure, and the preﬁx-minimum pointers associated with each of them is set to point to the old root (rooting a heap of size one now). Otherwise, the smallest heap is a singleton. This singleton is borrowed if the preﬁx-minimum pointer of the second smallest heap does not point to it. Otherwise, these two roots are swapped and the current singleton is borrowed. For the extract-min operation, the minimum of the buﬀer is compared with the minimum of the weak queue, and accordingly the operation is performed either in the buﬀer or in the weak queue. After these modiﬁcations, extract-min involves at most lg n + 1 element comparisons.

5

Experimental Findings

We implemented two versions of adaptive heapsort, one using a weak heap and another using a weak queue. In this section we discuss the settings and outcomes of our performance tests. In these tests we measured the actual running time of the programs and the number of element comparisons performed. The main purpose for carrying out these experiments was to validate our theoretical results. Our implementation of adaptive heapsort using a weak heap was array-based. Each entry of the array representing the Cartesian tree stored a copy of an element and two references to other entries in the tree. The arrays representing the weak heap and the buﬀer stored references to the Cartesian tree, and a separate array was used for the reverse bits. In total, the space usage per element was three references, a copy of the element, and one bit. Dynamic memory allocation was avoided by preallocating all arrays from the stack. Users should be aware that, due to the large space requirements, the algorithm has a restricted utility depending on the amount of memory available. In our implementation of adaptive heapsort using a weak queue, some nontrivial enhancements were made. First, we used two pointers per node: one pointing to the left child and another to the right child. As advised by Vuillemin [24], because of the lack of parent pointers, we reverted the left-child pointers to temporarily point to the parents while performing repeated linkings in extract -min. Second, we used an array of pointers to access the roots of the trees. This array

204

S. Edelkamp, A. Elmasry, and J. Katajainen

also infers the ranks of these roots; the nodes themselves did not store any rank information. Third, we used the same nodes to store the pointers needed by the Cartesian tree and the buﬀer. Fourth, all memory was preallocated from the stack. In total, the space usage per node was four pointers and a copy of an element; another O(lg n) space was used by the array of root pointers and the array of preﬁx-minimum pointers. Accordingly, this implementation used even more memory than the version employing a weak heap. To select suitable competitors for our implementations, we consulted some earlier research papers concerning the practical performance of inversion-optimal sorting algorithms [9,20,23]. Based on this survey, we concluded that splaysort performs well in practice. In addition, the implementation of Moﬀat et al. [20] is highly tuned, practically eﬃcient, and publicly available. Consequently, we selected their implementation of splaysort as our primary competitor. In the aforementioned experimental papers, splaysort has been reported to perform better than other tree-based algorithms (e.g. AVL-sort [7]), cache-oblivious algorithms (e.g. greedysort [1]), and partition-based algorithms (e.g. splitsort [16]). When considering comparison-based sorting, one should not ignore quicksort [13]. Introsort [22] is a highly tuned variant of quicksort that is known to be fast in practice. It is based on half-recursive median-of-three quicksort, it coarsens the base case by leaving small subproblems unsorted, it calls insertionsort to ﬁnalize the sorting process, and it calls heapsort if the recursion depth becomes too large. Using the middle element as a candidate for the pivot, and using insertionsort at the back end, make introsort adaptive with respect to the number of element comparisons (though not optimally adaptive with respect to any known measure of disorder). Quicksort and its variants are also known to be optimally adaptive with respect to the number of element swaps performed [2]. For these reasons, we selected the standard-library implementation of introsort shipped with our C++ compiler as our secondary competitor. In the experiments, the results of which are discussed here (see Figs. 5–8), we used 4-byte integers as input data. The results were similar for diﬀerent input sizes; for the reported experiments the number of elements was ﬁxed to 107 and 108 . We ensured that all the input elements were distinct. Integer data was suﬃcient to back up our theoretical analysis. However, for other types of input data, the number of element comparisons performed and the number of cache misses incurred may have more signiﬁcant inﬂuence on the running time. We performed the experiments on one core of a desktop computer (model Intel i/7 CPU 2.67 GHz) running Ubuntu 10.10 (Linux kernel 2.6.32-23-generic). This computer had 32 KB L1 cache memory, 256 KB L2 cache memory, 8 MB (shared) L3 cache memory, and 12 GB main memory. With such memory capacity, there was no need to use virtual memory. We compiled all programs using GNU C++ compiler (gcc version 4.4.3 with option -O3). To generate the input data, we used two types of generators: Repeated Swapping. We started with a sorted sequence of the integers from 1 to n, and repeatedly performed random transpositions of two consecutive elements. This generator was used to produce data with few inversions.

Two Constant-Factor-Optimal Realizations of Adaptive Heapsort Running times (n = 107) 1.2

0.8

#element comparisons / n

time / n [s]

Comparison counts (n = 107)

splaysort introsort adaptive heapsort (weak queue) adaptive heapsort (weak heap)

1

0.6 0.4 0.2 0

101

102

103

104 105 #inversions

106

205

107

108

40 35 30 25 20 15 10 5 0

splaysort introsort adaptive heapsort (weak queue) adaptive heapsort (weak heap)

101

102

103

104 105 #inversions

106

107

108

Fig. 5. Repeated swapping, n = 107 : CPU time used and the number of element comparisons performed by diﬀerent sorting algorithms

18 16 14 12 10 8 6 4 2 0 107

7 Comparison counts (n = 10 )

splaysort introsort adaptive heapsort (weak queue) adaptive heapsort (weak heap)

108

109

1010 1011 #inversions

1012

#element comparisons / n

time / n [s]

7 Running times (n = 10 )

1013

40 35 30 25 20 15 10 5 0 107

splaysort introsort adaptive heapsort (weak queue) adaptive heapsort (weak heap)

108

109

1010 1011 #inversions

1012

1013

Fig. 6. Controlled shuﬄing, n = 107 : CPU time used and the number of element comparisons performed by diﬀerent sorting algorithms

Controlled Shuﬄing [9]. We started with a sorted sequence of the integers from 1 to n, and performed two types of perturbations; we call the sequences resulting from these two phases local and global shuﬄes. For local shuﬄes, the sorted sequence was broken into n/m consecutive blocks each containing m elements (except possibly the last block), and the elements of each block were randomly permuted. For global shuﬄes, the sequence produced by the ﬁrst phase was broken into m consecutive blocks each containing n/m elements (except possibly the last block). From each block one element was selected at random, and these elements were randomly permuted. A small value of m means that the sequence is sorted or almost sorted, and a large value of m means that the sequence is random. Given a parameter m, this shuﬄing results in a sequence with expected Θ(n · m) inversions. Since in both cases the resulting sequence is a permutation of the integers from 1 to n, the number of inversions could be easily calculated as ni=1 |xi − i|/2. The experiments showed that our realizations of adaptive heapsort perform a low number of element comparisons. For both versions, the number of element comparisons was about the same, as already veriﬁed analytically. When

206

S. Edelkamp, A. Elmasry, and J. Katajainen Comparison counts (n = 108)

splaysort introsort adaptive heapsort (weak queue) adaptive heapsort (weak heap)

101

102

103

104 105 106 #inversions

107

#element comparisons / n

time / n [s]

Running times (n = 108) 9 8 7 6 5 4 3 2 1 0

108

40 35 30 25 20 15 10 5 0

splaysort introsort adaptive heapsort (weak queue) adaptive heapsort (weak heap)

101

102

103

104 105 106 #inversions

107

108

Fig. 7. Repeated swapping, n = 108 : CPU time used and the number of element comparisons performed by diﬀerent sorting algorithms

8 Running times (n = 10 )

splaysort introsort adaptive heapsort (weak queue) adaptive heapsort (weak heap)

time / n [s]

250 200 150 100 50 0 108

109

1010 1011 1012 1013 1014 1015 #inversions

50 #element comparisons / n

300

8 Comparison counts (n = 10 )

splaysort introsort adaptive heapsort (weak queue) adaptive heapsort (weak heap)

40 30 20 10 0 108

109

1010 1011 1012 1013 1014 1015 #inversions

Fig. 8. Controlled shuﬄing, n = 108 : CPU time used and the number of element comparisons performed by diﬀerent sorting algorithms

the number of inversions was small, splaysort performed about the same number of element comparisons as the two realizations of adaptive heapsort. When the number of inversions was large, splaysort performed a few more element comparisons than the two realizations of adaptive heapsort. In all our experiments, introsort was a bad performer with respect to the number of element comparisons; it showed very little adaptivity and came last in the competition. As to the running time, the weak-heap version of adaptive heapsort was faster than the weak-queue version; about 60% faster when the number of inversions was small and about 20% faster when the number of inversions was large. The running times of splaysort were larger than the ones of the weak-heap version for almost all experiments. For random data, splaysort performed worst, and adaptive heapsort could be up to a factor of 15 slower than introsort. (In our supplementary experiments, for random data, normal heapsort was only a factor of 2–6 slower than introsort depending on the input size.) In most experiments, introsort was the fastest sorting method; it was only beaten by the weak-heap version when the number of inversions was very small (less than n).

Two Constant-Factor-Optimal Realizations of Adaptive Heapsort

6

207

Conclusions

We studied the optimality and practicality of adaptive heapsort. We introduced two new realizations for it, which are theoretically optimal and practically workable. Even though our realizations outperformed the state-of-the-art implementation of splaysort, the C++ standard-library introsort was faster for most inputs, at least on integer data. Despite decades of research, there is still a gap between the theory of adaptive sorting and the actual computing practice. In spite of the optimality with respect to several measures of disorder, the high number of cache misses is not on our side. Compared to earlier implementations of adaptive heapsort, a buﬀer increased the locality of memory references and thus reduced the number of cache misses incurred. Still, introsort has considerably better cache behaviour. Earlier research has pointed out [9] that existing cache-eﬃcient adaptive sorting algorithms are not competitive. The question arises whether constant-factor optimality with respect to the number of element comparisons can be achieved side by side to cache eﬃciency. Another drawback of adaptive heapsort is the extra space required by the Cartesian tree. In introsort the elements are kept in the input array, and sorting is carried out in-place. Overheads attributable to pointer manipulations, and a high memory footprint in general, deteriorate the performance of any implementation of adaptive heapsort. This is in particular true when the amount of disorder is high. As to the memory requirements, we used about 4n extra words of storage for pointers and n extra space for copies of elements. An in-place algorithm that is optimal with respect to the measure Inv exists [17], but it is not practical. The question arises whether the memory eﬃciency of adaptive heapsort can be improved without sacriﬁcing the optimal adaptivity. In another extension, one should carry out experiments on data types for which element comparisons are more expensive than other operations. We are not far away from n lg n element comparisons when the amount of disorder is high. (Our best bound on the number of element comparisons is n lg 1+Osc(X)/n + 5.5n.) The question arises whether the constant factor for the linear term in the number of element comparisons can be improved; that is, how close we can get to the information-theoretic lower bound up to low-order terms.

Source Code The programs used in the experiments are available via the home page of the CPH STL (http://cphstl.dk/) in the form of a PDF document and a tar ﬁle.

References 1. Brodal, G.S., Fagerberg, R., Moruz, G.: Cache-Aware and Cache-Oblivious Adaptive Sorting. In: Caires, L., Italiano, G.F., Monteiro, L., Palamidessi, C., Yung, M. (eds.) ICALP 2005. LNCS, vol. 3580, pp. 576–588. Springer, Heidelberg (2005) 2. Brodal, G.S., Fagerberg, R., Moruz, G.: On the Adaptiveness of Quicksort. ACM J. Exp. Algorithmics 12, Article 3.2 (2008)

208

S. Edelkamp, A. Elmasry, and J. Katajainen

3. Carlsson, S., Levcopoulos, C., Petersson, O.: Sublinear Merging and Natural Mergesort. Algorithmica 9(6), 629–648 (1993) 4. Dutton, R.D.: Weak-heap Sort. BIT 33(3), 372–381 (1993) 5. Edelkamp, S., Wegener, I.: On the Performance of Weak-Heapsort. In: Reichel, H., Tison, S. (eds.) STACS 2000. LNCS, vol. 1770, pp. 254–266. Springer, Heidelberg (2000) 6. Elmasry, A.: Priority Queues, Pairing and Adaptive Sorting. In: Widmayer, P., Triguero, F., Morales, R., Hennessy, M., Eidenbenz, S., Conejo, R. (eds.) ICALP 2002. LNCS, vol. 2380, pp. 183–194. Springer, Heidelberg (2002) 7. Elmasry, A.: Adaptive Sorting with AVL Trees. In: IFIP Int. Fed. Inf. Process., vol. 155, pp. 315–324. Springer, New York (2004) 8. Elmasry, A., Fredman, M.L.: Adaptive Sorting: An Information Theoretic Perspective. Acta. Inform. 45(1), 33–42 (2008) 9. Elmasry, A., Hammad, A.: Inversion-sensitive Sorting Algorithms in Practice. ACM J. Exp. Algorithmics 13, Article 1.11 (2009) 10. Elmasry, A., Jensen, C., Katajainen, J.: Multipartite Priority Queues. ACM Trans. Algorithms 5(1), Article 14 (2008) 11. Gabow, H.N., Bentley, J.L., Tarjan, R.E.: Scaling and Related Techniques for Geometry Problems. In: 16th Annual ACM Symposium on Theory of Computing, pp. 135–143. ACM, New York (1984) 12. Guibas, L.J., McCreight, E.M., Plass, M.F., Roberts, J.R.: A New Representation for Linear Lists. In: 9th Annual ACM Symposium on Theory of Computing, pp. 49–60. ACM, New York (1977) 13. Hoare, C.A.R.: Quicksort. Comput. J. 5(1), 10–16 (1962) 14. Knuth, D.E.: Sorting and Searching, The Art of Computer Programming, 2nd edn., vol. 3. Addison Wesley Longman, Reading (1998) 15. Levcopoulos, C., Petersson, O.: Adaptive Heapsort. J. Algorithms 14(3), 395–413 (1993) 16. Levcopoulos, C., Petersson, O.: Splitsort: An Adaptive Sorting Algorithm. Inform. Process. Lett. 39(4), 205–211 (1991) 17. Levcopoulos, C., Petersson, O.: Exploiting Few Inversions When Sorting: Sequential and Parallel Algorithms. Theoret. Comput. Sci. 163(1-2), 211–238 (1996) 18. Mannila, H.: Measures of Presortedness and Optimal Sorting Algorithms. IEEE Trans. Comput. C-34(4), 318–325 (1985) 19. Mehlhorn, K.: Sorting Presorted Files. In: Weihrauch, K. (ed.) GI-TCS 1979. LNCS, vol. 67, pp. 199–212. Springer, Heidelberg (1979) 20. Moﬀat, A., Eddy, G., Petersson, O.: Splaysort: Fast, Versatile, Practical. Software Pract. Exper. 126(7), 781–797 (1996) 21. Moﬀat, A., Petersson, O., Wormald, N.C.: A Tree-based Mergesort. Acta Inform. 35(9), 775–793 (1998) 22. Musser, D.R.: Introspective Sorting and Selection Algorithms. Software Pract. Exper. 27(8), 983–993 (1997) 23. Saikkonen, R., Soisalon-Soininen, E.: Bulk-Insertion Sort: Towards Composite Measures of Presortedness. In: Vahrenhold, J. (ed.) SEA 2009. LNCS, vol. 5526, pp. 269–280. Springer, Heidelberg (2009) 24. Vuillemin, J.: A Data Structure for Manipulating Priority Queues. Commun. ACM 21(4), 309–315 (1978) 25. Vuillemin, J.: A Unifying Look at Data Structures. Commun. ACM 23(4), 229–239 (1980) 26. Williams, J.W.J.: Algorithm 232: Heapsort. Commun. ACM 7(6), 347–348 (1964)

A Unifying Property for Distribution-Sensitive Priority Queues Amr Elmasry1, , Arash Farzan2 , and John Iacono3, 1

3

Computer Science Department, University of Copenhagen, Denmark elmasry@diku.dk 2 Max-Planck-Institut f¨ ur Informatik, Saarbr¨ ucken, Germany afarzan@mpi-inf.mpg.de Polytechnic Institute of New York Univerity, Brooklyn, New York, USA jiacono@poly.edu

Abstract. We present a priority queue that supports the operations: insert in worst-case constant time, and delete, delete-min, find-min and decrease-key on an element x in worst-case O(lg(min{wx , qx } + 2)) time, where wx (respectively, qx ) is the number of elements that were accessed after (respectively, before) the last access of x and are still in the priority queue at the time when the corresponding operation is performed. Our priority queue then has both the working-set and the queueish properties; and, more strongly, it satisﬁes these properties in the worst-case sense. We also argue that these bounds are the best possible with respect to the considered measures. Moreover, we modify our priority queue to satisfy a new unifying property — the time-ﬁnger property — which encapsulates both the working-set and the queueish properties. In addition, we prove that the working-set bound is asymptotically equivalent to the uniﬁed bound (which is the minimum per operation among the static-ﬁnger, static-optimality, and working-set bounds). This latter result is of tremendous interest by itself as it had gone unnoticed since the introduction of such bounds by Sleater and Tarjan [10]. Together, these results indicate that our priority queue also satisﬁes the static-ﬁnger, the static-optimality and the uniﬁed bounds.

1

Introduction

Distribution-sensitive data structures are those structures for which the time bounds to perform operations vary depending on the sequence of operations performed [8]. These data structures typically perform as well as their distributioninsensitive counterparts on a random sequence of operations in the amortized sense. Yet, when the sequence of operations follows some particular distributions (for example, having temporal or spatial locality), the distribution-sensitive data structures perform signiﬁcantly better.

Supported by fellowships from Alexander von Humboldt and VELUX foundations. Research partially supported by NSF grants CCF-0430849, CCF-1018370, and an Alfred P. Sloan fellowship, and by MADALGO—Center for Massive Data Algorithmics, a Center of the Danish National Research Foundation, Aarhus University.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 209–222, 2011. c Springer-Verlag Berlin Heidelberg 2011

210

A. Elmasry, A. Farzan, and J. Iacono

The quintessential distribution-sensitive data structure is the splay tree [10]. Splay trees seem to perform very eﬃciently (much faster than O(lg n) search time on a set of n elements) over several natural sequences of operations. There still exists no single comprehensive distribution-sensitive analysis of splay trees; instead, there are theorems and conjectures that characterize their distributionsensitive properties. These properties include: static ﬁnger, static optimality, sequential access, working set, uniﬁed bound, dynamic ﬁnger, and uniﬁed conjecture [1,3,4,10,11]. As deﬁned in [10], the “uniﬁed bound” is the per-operation minimum of the static-optimality, static-ﬁnger, and working-set bounds. By the “uniﬁed conjecture”, we follow the deﬁnition given in [1], which subsumes both the dynamic-ﬁnger and working-set bounds (The reason for such name is that the splay trees are conjectured to attain such bound.). We refer the reader to [1] and also [10] for a thorough deﬁnition and discussion of these properties. There are implication relationships between the distribution-sensitive properties, as illustrated in Figure 1. Implications depicted by “−→” were known in previous work, and the ones depicted by “=⇒” are contribution of this paper. In particular, we prove in Section 2 the implication of the uniﬁed bound from the working-set bound. This indicates that the working-set bound and the uniﬁed bound are asymptotically equivalent. In the course of the proof, we show that the sum of the working-set bounds on two sequences is asymptotically the same as the working-set bound of any interleaving sequence of these two sequences; this result is of independent interest. A sequence X is an interleaving sequence of two sequences Y and Z if and only if X is composed of all the elements of Y and Z in the same order they appear in their respective sequences. We defer the full discussion of the previously-known implications shown in Figure 1 to a full version of this paper. Distribution-sensitive data structures are not limited to search trees. Priority queues have also been designed and analyzed in the context of distributionsensitivity [2,5,7,8,9]. In the comparison model, it is easy to observe that a priority queue with constant insertion time cannot have the sequential-access property (and hence cannot as well have the dynamic-ﬁnger property). For otherwise, a sequence of insertions followed by a sequence of minimum-deletions lists the elements in sorted order in linear time. Alternatively, the working-set property has been of main interest for priority queues. Informally, the working-set property states that elements that have been recently operated on are faster to operate on subsequently compared to the elements that have not been accessed in the recent past. Iacono [7] proved that pairing-heaps [6] satisfy the working-set property as follows; in a heap of maximum size n, it takes O (lg(min {nx , n} + 2)) amortized time to delete the minimum element x, where nx is the number of operations performed since x’s insertion. Funnel-heaps are I/O-eﬃcient heaps for which it takes O (lg(min {ix , n} + 2)) to delete the minimum element x, where ix is the number of insertions made since x’s insertion. Elmasry [5] gave a priority queue supporting the deletion of the minimum element x in O (lg(wx + 2)) worst-case time, where wx is the number of elements inserted after the insertion of x and are still present in the priority queue when x is deleted (note that

A Unifying Property for Distribution-Sensitive Priority Queues

Unified conjecture

Time Finger

Queueish

Working set

211

Unified bound

Static optimality

Dynamic finger

Sequential access

Static finger

Priority queues

Dictionaries

Fig. 1. The implication relationships between various distribution-sensitive properties. The implications depicted by “=⇒” are contribution of this paper.

wx ≤ ix ≤ nx ). We brieﬂy review this priority queue in Section 3. None of the aforementioned priority queues supports delete within the working-set bound. In Section 4, we present a priority queue that supports insert in worst-case constant time, and supports delete, delete-min, and decrease-key in O (lg(wx + 2)) worst-case time. One natural sequence of operations is the ﬁrst-in-ﬁrst-out type. Data structures sensitive to these sequences must operate fast on elements that have been least recently accessed. This distribution-sensitive property is referred to as the “queueish” property in [9]. In the context of priority queues, such property states that the time to perform delete or delete-min on an element x is O (lg (qx + 2)), where qx is the number of elements inserted before x and are still present in the priority queue when x is deleted. Note that qx = n − wx , where n is the number of elements currently present in the priority queue. It is shown in [9] that no binary search tree can be sensitive to this property. However, a priority queue with the queueish property is presented in the same paper [9]. It remained open whether there exists a priority queue sensitive to both the working-set and the queueish properties. We resolve the question aﬃrmatively by presenting such a priority queue in Section 5. In Section 6, we introduce the time-ﬁnger property for priority queues. This property encapsulates the queueish and the working-set properties, and thus also captures the uniﬁed-bound, staticoptimality, and static-ﬁnger properties. As these properties are the complete list of the distribution-sensitive properties known for priority queues, we refer to the time-ﬁnger property as the “unifying property for priority queues”. In consequence, we modify our priority queue to satisfy this unifying property.

212

2

A. Elmasry, A. Farzan, and J. Iacono

From the Working-Set Bound to the Unified Bound

Consider a suﬃciently long sequence of access operations X = x1 , x2 . . . , xm performed on a given data set of elements. The static-finger property [10] indicates that, for any ﬁxed item f (the ﬁnger), the amortized time to perform xi is O(lg(dX (i, f ) + 2)), where dX (i, f ) is the diﬀerence in order within the data set between the item corresponding to xi and the ﬁnger f . More speciﬁcally, for an access sequence X, the total access time m for a structure with the static-ﬁnger property is O( lg(dX (i, f ) + 2)). i=1

The static-optimality property (entropy bound) [10] indicates that, for an access sequence X, where the item corresponding to xi is accessed hX (i) times, m the total access time is O( lg( hXm(i) + 1)). i=1

The working-set size wX (i), for an operation xi in sequence X, is deﬁned as the number of distinct elements accessed since the last access to the item corresponding to xi , or from the beginning of the sequence if this is the ﬁrst access to xi . The working-set property [10] indicates that the total access time m for a sequence X is O( lg(wX (i) + 2)). i=1

Iacono [8] observed that the working-set property implies the static-optimality and static-ﬁnger properties. Therefore, the working-set property is the strongest of the three properties. However, the unified bound [10] indicates an apparently (but not indeed) stronger property. The uniﬁed bound states that the total access time for a sequence X and any ﬁxed ﬁnger f is m m O lg min dX (i, f ) + 2, + 1, wX (i) + 2 . (1) hX (i) i=1 For the rest of this section, we show that the working-set bound is asymptotically equivalent to the uniﬁed bound. First, we show that the sum of the workingset bounds of two sequences is asymptotically the same as the bound for the sequence that results when those two sequences are arbitrarily interleaved. This result will be needed to prove the main claim of this section, and is interesting in its own right. Theorem 1. Let X be an access sequence and let Y and Z be two subsequences that partition X. Stated another way, X is an interleaving of Y and Z. Then, ⎛ ⎞ |X| |Y | |Z| lg(wX (i) + 2) = Θ ⎝ lg(wY (i) + 2) + lg(wZ (i) + 2)⎠ . i=1

i=1

i=1

Proof. The Ω(.) direction is immediate, and thus we focus on the O(.) direction. We use ηi to map the indices of Y to X: yi is the operation that corresponds to xηi . The function βi is analogously deﬁned to map the indices of Z to X.

A Unifying Property for Distribution-Sensitive Priority Queues

213

Let be the largest index such that < i and xi and x access the same element. That is, x is the previous access to the same element as that accessed by xi . Let WX (i) be the set of indices r such that xr is the ﬁrst access to that element in the range x+1 .. xi−1 . Note that WX (i) is the set envisioned by the concept of the “working set” of xi and is constructed so that |WX (i)| = wX (i). Observe that the t-th largest index in WX (i) has a working-set size at least wX (i) − t. Let WX be the set of the wX (i)/2 largest indices of WX . Therefore, the working-set size for each index in WX is at least wX (i)/2. Let Ai be formally deﬁned as:

Ai = j | wX (ηj ) > wY2 (j) and i = lg(wX (ηj ) + 2) . That is, the set Ai consists of the indices of the access operations in Y for which the logarithm of the working-set size of the corresponding access in X is more than double that value for the access in Y , and in addition the working-set size in X is in the range [2i .. 2i+1 ). All sets Ai are thus disjoint, and all indices j in [1 .. |Y |] are in some set Ai unless the logarithm of the working-set size for yj at most doubles as a result of the merge with Z. Now, pick some index j ∈ Ai . Consider the indices in WX (ηj ) and WX (ηj ). Some of these indices come from Y , and some from Z. However, the vast majority come from Z, since the total number is at least the number from Y squared. Very conservatively, at least half of the indices in WX (ηj ) correspond to the Z sequence. We say that these indices of Z are covered by the element j at level i; this set is represented by Ci (j) and is deﬁned as: Ci (j) = {k | βk ∈ WX (ηj )} .

We can bound |Ci (j)| from above as: |Ci (j)| ≤ |WX (ηj )| = wX (ηj ) < 2i+1 , and it can be bounded from below as: |Ci (j)| ≥

1 1 1 |W (ηj )| ≥ wX (ηj ) ≥ 2i = 2i−2 . 2 X 4 4

By construction, for any ﬁxed value k, there are less than 2i+1 indices j such that k ∈ Ci (j). Let Ci be the covered set of the union of all Ci (j), for all j ∈ Ai . It follows that |Ci | ≥ (2i−2 · |Ai |)/2i+1 = |Ai |/8. Also, following the fact that |Ci (j)| = Ω(2i ), each index k ∈ Ci (j) has a working-set size of wZ (k) = Ω(2i ). Hence, ∞ i=1

|Z| |Ci | · i = O( lg(wZ (k) + 2)). k=1

214

A. Elmasry, A. Farzan, and J. Iacono

Putting this information together gives |Y |

lg(wX (ηj ) + 2) −

j=1

|Y |

2 lg(wY (j) + 2) = O(|Y | +

j=1

= O(|Y | +

∞ i=1 ∞

|Ai | · i) |Ci | · i)

i=1

⎛

|Z|

= O ⎝|Y | +

⎞ lg(wZ (k) + 2)⎠ .

k=1

Analogously, we have |Z|

lg(wX (βk ) + 2) −

k=1

|Z|

⎛ 2 lg(wZ (k) + 2) = O ⎝|Z| +

|Y |

⎞ lg(wY (j) + 2)⎠ .

j=1

k=1

Adding the last two equations, we get |Y |

lg(wX (ηj )+2)+

j=1

|Z|

⎛ lg(wX (βk )+2) = O ⎝

|Y |

lg(wY (j) + 2) +

j=1

k=1

|Z|

⎞ lg(wZ (k) + 2)⎠ .

k=1

The theorem follows because |Y |

lg(wX (ηj ) + 2) +

j=1

|Z|

lg(wX (βk ) + 2) =

|X|

lg(wX (i) + 2).

i=1

k=1

Now, we prove the main result of the section. Theorem 2. The working-set bound is asymptotically equivalent to the unified bound. Proof. Clearly, the uniﬁed bound implies the working-set bound as m i=1

lg min dX (i, f ) + 2,

m + 1, wX (i) + 2 hX (i)

≤

m

lg(wX (i) + 2).

i=1

The other direction requires more eﬀort. We begin by partitioning X into two subsequences Y and Z, by placing in Y all operations xi where wX (i) + 2 = min dX (i, f ) + 2, hXm(i) + 1, wX (i) + 2 and the remainder in Z. We use ηi to map the indices of Y to X: yi is the element that came from xηi . The function βi is analogously deﬁned to map the indices of Z to X. Then:

A Unifying Property for Distribution-Sensitive Priority Queues

m

lg min dX (i, f ) + 2,

i=1

=

|Y |

lg(wX (ηi ) + 2) +

i=1

⎛

= Ω⎝ ⎛ = Ω⎝

m + 1, wX (i) + 2 hX (i)

|Z|

|Y |

lg(wY (i) + 2) +

|Z|

i=1

i=1

|Y |

|Z|

lg(wY (i) + 2) +

i=1

lg min dX (βi , f ) + 2,

i=1

⎛ ⎝1 + lg

max

⎛ ⎝1 + lg

max

i=1

(2) m +1 hX (βi )

1 hX (βi ) 1 dX (βi ,f )+1 , m

(3) ⎞⎞ ⎠⎠

1 1 , hXm(βi ) (dX (βi ,f )+1)2

=Ω

m

(4)

⎞⎞ ⎠⎠

⎛ ⎞ |Y | |Z| |Z| +1 ⎠ = Ω⎝ lg(wY (i) + 2) + lg h Z (i) i=1 i=1 ⎛ ⎞ |Y | |Z| = Ω⎝ lg(wY (i) + 2) + lg(wZ (i) + 2)⎠ i=1

215

(5)

(6)

(7)

i=1

lg(wX (i) + 2)

(8)

i=1

Equation 3 splits one sum into two using the partitioning of X into Y and Z. The left term of Equation 4 is obtained by replacing wX with wY , which can only cause a decrease. The right sum of Equation 4 follows from the fact that 1 min(x, y) = max(1/x,1/y) . The only change in Equation 5 is the square in the denominator; because this is inside a logarithmit makes no asymptotic diﬀer(βi ) ence. The formula 1/ max (dX (βi1,f )+1)2 , hXm now has two nice properties:

First, it depends solely on the element corresponding to xβi (not on the value of i). Second, summed over all distinct elements, the sum is O(1). Hence, this is a static-optimality type weighting scheme. It follows from information theory that the second sum of Equation 6 is asymptotically bounded from below by the entropy of the access frequencies of the elements, and this yields Equation 6. To get from Equation 6 to Equation 7, the fact that the static-optimality bound is big-Omega of the working-set bound is used; this is Theorem 10 of [8]. Moving from Equation 7 to Equation 8 requires the observation that the sum of the working-set bounds of two sequences is asymptotically the same as the workingset bound of an interleaving sequence of both; this is Theorem 1.

3

A Priority Queue with the Working-Set Property

Our priority queue builds on the priority queue in [5], which supports insert in constant time and delete-min within the working-set bound. The advantage

rank 0

rank 1

rank 1

rank 2

rank 2

A. Elmasry, A. Farzan, and J. Iacono

rank (r-1)

216

Fig. 2. The recursive structure of a (2, 3) binomial tree of rank r: Subtrees rooted at the children of the root are (2, 3) binomial trees. The sequence of ranks of such children forms a non-decreasing sequence from right to left such that each value from 0, 1, . . . , r − 1 occurs either once or twice.

of the priority queue in [5] over those in [2,6,7] is that it satisﬁes the stronger working-set property, in which elements that are deleted do not count towards the working set. Next, we outline the structure of this priority queue. The priority queue in [5] comprises heap-ordered (2, 3) binomial trees. As deﬁned in [5], the subtrees of the root of a (2, 3) binomial tree of rank r are (2, 3) binomial trees; there are one or two children having ranks 0, 1, . . . , r − 1, ordered in a non-decreasing rank order from right to left. It is easy to verify that the rank of any (2, 3) binomial tree is Θ (lg n), where n is the number of nodes. Figure 2 illustrates the recursive structure of a (2, 3) binomial tree. The ranks of the (2, 3) binomial trees of the priority queue are as well nondecreasing from right to left. For the amortized solution, there are at most two (possibly zero) trees per rank. For the worst-case solution, the number of trees per rank obey an extended-regular number system that imposes stronger regularity constraints, which implies that the ranks of any two adjacent trees diﬀer by at most 2 (see [5] for the details of the number system). The root of every (2, 3) binomial tree has a pointer to the root with the minimum value among the roots to its left, including itself. Such prefix-minimum pointers allow for ﬁnding the overall minimum element in constant time, with the ability to maintain such pointers after deleting the minimum in time proportional to the rank of the deleted node. Figure 3 illustrates the structure of our priority queue. Two primitive operations are split and join. A (2, 3) tree of rank r is split to two or three trees of rank r − 1; this is done by detaching the one or two children of the root having rank r − 1. On the other hand, two or three (2, 3) trees of rank r − 1 can be joined to form a (2, 3) tree of rank r; this is done by making the root(s) with the larger value the leftmost child(ren) of the one with the smallest value. To join a tree of rank r − 1 and a tree of rank r − 2, we split the ﬁrst tree then join all the resulting trees; the outcome is a tree whose rank is either r − 1

A Unifying Property for Distribution-Sensitive Priority Queues

rank i

rank 2

rank1

217

rank 0

Fig. 3. (2, 3) binomial trees comprise the priority queue: The rank of the trees are non-decreasing from right to left. Preﬁx-minimum pointers are maintained at the roots of the trees. Each tree root points to the minimum root to the left of it, including itself.

or r. With these operations in hand, it is possible to detach the root of a (2, 3) binomial tree of rank r and reconstruct the tree again as a (2, 3) binomial tree with rank r − 1 or r; this is done by repeated joins and splits starting from the rightmost subtrees of the deleted root to the leftmost (see [5] for the details). A total order is maintained indicating the time the elements were inserted. We impose that if a binomial tree T1 is to the right of another T2 , then all elements in T1 must have been inserted after those in T2 . Furthermore, within an individual binomial tree, we aim that the preorder traversal of elements with a right-to-left precedence to subtrees would indicate the insertion time of these elements. However, when performing join operations, we occasionally disobey this ordering by possibly reversing the order of two entire subtrees. To get the right ordering, it is enough to maintain a reverse bit with every node x; such reverse bit indicates whether the elements in x’s subtree were inserted before or after the elements in x’s parent plus those in the descendants of the right siblings of x. When a join is performed, the corresponding reverse bit is properly set. To perform an insert operation, a new single node is added as the rightmost tree in the priority queue. This may give rise to several joins once there are three trees with the same rank; the number of such joins is amortized constant, resulting in a constant amortized cost per insertion. After performing the joins, the preﬁx-minimum pointer of the surviving root is updated. For the worst-case solution, the underlying number system guarantees at most two joins per insert . To perform a delete-min operation, the tree T of the minimum root is identiﬁed via the preﬁx-minimum pointer of the rightmost root, the tree T is reconstructed as a (2, 3) binomial tree after detaching its root. This may be followed by a split and a join if T has rank one less that its original rank. Finally, the preﬁx-minimum pointers are updated. For the amortized solution, several splits of T may follow the delete-min operation. Starting with T , we repeatedly split the rightmost tree resulting from previous splits until such tree and its right neighbor (the right neighbor of T before the delete-min) have consecutive ranks; this splitting is unnecessary for the worst-case solution. It is not hard to conclude that the cost of delete-min is O(r), where r is the rank of the deleted node. In the worst-case solution, the rank of the deleted node x is O(lg (wx + 2)). This follows from the fact that there are O(wx ) elements in the trees to the right

218

A. Elmasry, A. Farzan, and J. Iacono

of T , and hence the number of such trees is O(lg (wx + 2)). For the amortized solution, an extra lemma (see [5]) proves the same bound in the amortized sense.

4

Supporting delete, find-min and decrease-key

The existing distribution-sensitive priority queues [2,5,7,8,9] do not support delete within the working-set bound. In this section, we modify the priority queue outlined in Section 3 to support delete within the working-set bound. Including delete in the repertoire of operations is not hard but should be done carefully. The major challenge is to maintain the chronological order of the elements. We start by traversing upwards via the parent pointers from the node x to-bedeleted until the root of the tree of x is reached. We use two stacks; a right stack and a left stack. Starting at this root, the current subtree is repeatedly split into two or three trees, one or two of them are pushed to one of the stacks (depending on the reverse bits) while continuing to split the tree that contains x, until we end up with a tree whose root is x. At this stage, we delete x analogously to the delete-min operation; the node x is detached and the subtrees resulting from removing x are incrementally joined from right to left, while possibly performing one split before each join (similar to the delete-min operation). We now have to work our way up to the root of the tree and merge all subtrees which we have introduced by splits on the way down from the root. The one or two trees that have the same rank are repeatedly popped from the stacks and joined with the current tree, while possibly performing one split before each join (as required for performing a join operation). Once the two stacks are empty, a split and a join may be performed if the resulting tree has rank one less that its original rank (again, similar to the delete-min operation). The total order is correctly maintained by noting that the only operations employed are the split and join, which are guaranteed to set the reverse bits correctly. Since the height of a (2, 3) binomial tree is one plus its rank, the time bound for delete is O(r), where r is the rank of the tree that contains the deleted node. This establishes the same time bound as that for delete-min in both the amortized and worst-case solutions. Using the preﬁx-minimum pointers, the find-min operation is easily performed in constant time. However, this operation is not considered as an access to the minimum element. As otherwise, a following delete operation would have to be supported in constant time by the working-set property, which is impossible. The version of find-min that is considered as an access to the minimum element can not be supported in time asymptotically less than that for the delete-min operation. It is straightforward to implement such an operation in asymptotically optimal time by executing a delete-min followed by a re-insertion. Also, the decrease-key operation that is considered as an access cannot be performed in asymptotically less time than a delete operation. As otherwise, a delete operation can be performed by executing a decrease-key operation with decrease value of zero, which essentially brings the element to the front of the working set, followed by a delete operation which now runs in constant time as

A Unifying Property for Distribution-Sensitive Priority Queues

219

the element has just been accessed. A decrease-key operation can be made to run in O (lg (wx + 2)) time by simply executing a delete followed by a re-insertion. Finally, the time optimality of delete-min and delete operations directly follows from the logarithmic lower bound of these operations for (non distributionsensitive) priority queues in the comparison model. Theorem 3. The priority queue presented in this section performs insert in constant time, and delete, delete-min, find-min and decrease-key of an element x in asymptotically optimal time of O (lg (wx + 2)), where wx is the number of elements accessed after the last access of x and are still present in the priority queue at the time of the current operation.

5

Incorporating the Queueish Property

The queueish property for priority queues states that the time to perform delete or delete-min on an element x is O (lg (n − wx + 2)), where n is the number of elements currently present in the priority queue, and wx is the number of elements accessed after the last access of x and are still present in the priority queue. In other words, the queueish property states that the time to perform delete or delete-min on an element x is O (lg (qx + 2)), where qx = n − wx is the number of elements last accessed prior to x and are still present. Queaps [9] are queueish priority queues that support insert in amortized constant time and support delete-min of an element x in amortized O (lg(qx + 2)) time. We extend our priority queue, in addition to supporting the working-set bound, to also support the operations within the queueish bound. Accordingly, the priority queue simultaneously satisﬁes both the working-set and the queueish properties. Instead of having the ranks of the trees of the queue non-decreasing from right to left, we split the queue in two sides, a right queue and a left queue, forming a two-sided priority queue. The ranks of the trees of the right queue are monotonically non-decreasing from right to left (as in the previous section), and those of the left queue are monotonically non-decreasing from left to right. We also impose the constraint that the diﬀerence in rank between the largest tree on each side is at most one. Figure 4 depicts the new priority queue. The preﬁx-minimum pointers in the left and right queues are kept independently. In the right queue, the root of each tree maintains a pointer to the root with the minimum value among those in the right queue to the left of it. Conversely, in the left queue, the root of each tree maintains a pointer to the root with the minimum value among those in the left queue to the right of it. To ﬁnd the overall minimum value, both the left and right queues are probed. Insertions are performed exactly as before in the right queue. The deletemin operation is performed in the left or right queue depending on where the minimum lies. Deletions are also performed as mentioned in the previous section. However, we must maintain the invariant that the diﬀerence in rank between the largest tree in the left and right sides is at most one. Since the total chronological order is maintained among our trees, this invariant guarantees that the rank of the tree of an element x is O (lg(min {wx , qx } + 2)). As a result of an

Left queue

rank 0

rank 1

rank 2

rank i

rank (i-1)

rank 2

rank 1

A. Elmasry, A. Farzan, and J. Iacono

rank 0

220

Right queue

Fig. 4. A priority queue satisfying the queueish property: the priority queue comprises two queues one of which has tree ranks increasing from right to left (right queue) and one increasing from left to right (left queue). The ranks of the largest trees on the two sides must diﬀer by at most one. The preﬁx-min pointers are separate for each side.

insertion or a deletion, the diﬀerence in such ranks may become two. Once the largest rank on one side is two more than that on the other side, the trees with such largest rank are split each in two or three trees, and the appropriate tree among the resulting ones is moved to the other side, increasing the largest rank on the second side by one. As a result of those splits, the number of trees of the same rank on the ﬁrst side may now exceed the limit, and hence one or two joins would be needed to satisfy the constraints. Once a tree is moved from one side to the other, the preﬁx-minimum pointers of the priority queues on both sides need to be updated. Because such action happens only after a lot of operations (a fraction of the current number of elements), updating the preﬁx-minimum pointers only accounts for an extra constant in the amortized cost per operation. If we want to guarantee the costs in the worst case, updating those preﬁx-minimum pointers is to be done incrementally with the upcoming operations. A deletion of a node x in a tree of rank r would still cost O(r) time, but now r = O(lg (min {wx , qx } + 2)) in the amortized sense (for the amortized solution), or in the worst-case sense (for the worst-case solution). Theorem 4. The priority queue presented in this section performs insert in constant time, and delete, delete-min, find-min and decrease-key of an element x in asymptotically optimal time of O (lg(min {wx , qx } + 2)), where wx and qx are the number of elements accessed after, respectively before, the last access to x and are still present in the priority queue at the time of the current operation.

6

Supporting Multiple Time Fingers

We deﬁne time ﬁngers t1 , t2 , . . . , tc as time instances within the sequence of operations, which are freely set by the implementer. We deﬁne the workingset of an element x with respect to time ﬁnger ti , wx (ti ), as the number of elements that have been last accessed in the window of time between the last

A Unifying Property for Distribution-Sensitive Priority Queues

221

access of x and ti and are still present in the priority queue. We say that a priority queue satisﬁes the multiple-time-ﬁnger property if the time to access x c

is O(lg(min {wx (ti )} + 2)). It is not hard to see that the working-set property is i=1

equivalent to having a single time ﬁnger t1 = +∞, and the queueish property is equivalent to having a single time ﬁnger t1 = 0. The priority queue presented in Section 5, which supports both the working-set and the queueish properties, has two time ﬁngers t1 = 0, t2 = +∞. In this section, we present a priority queue that satisﬁes the property for a constant number of time ﬁngers. The structure consists of multiple two-sided priority queues, as those designed in Section 5. We start with a single two-sided priority queue P Q0 , and at each point when a new time ﬁnger is introduced we ﬁnalize the priority queue and start a new one. Therefore, corresponding to c time-ﬁngers t1 = 0, . . . , tc = ∞, we have c − 1 two-sided priority queues P Q1 , . . . , P Qc−1 . Insertions are performed in the last (at the time when the insertion is performed) priority queue, and, following Theorem 4, takes constant time each. For delete operations, we are given a reference to an element x to delete. We determine to which priority queue P Qj the element belongs and delete it. This requires O(lg(min {wx (tj ), wx (tj+1 )}+2)) time, as indicated by Theorem 4. Since x belongs to P Qj , for any i < j, wx (tj ) ≤ wx (ti ), and for any i > j + 1, wx (tj+1 ) ≤ c

wx (ti ). It follows that lg(min {wx (tj ), wx (tj+1 )} + 2) = lg(min {wx (ti )} + 2). For i=1

the delete-min operation, it suﬃces to note that ﬁnding the minimum element per queue takes constant time. Therefore, we can determine in constant time the priority queue containing the minimum, and perform the operation there. The running-time argument is the same as that for the delete operation. Theorem 5. Given a constant number of time fingers t1 , t2 , . . . , tc , the priority queue presented in this section performs insert in constant time, and delete, c

delete-min, find-min, and decrease-key of an element x in O(lg(min {wx (ti )}+2)) i=1

time, where wx (ti ) is the number of elements that have been last accessed in the window of time between the last access of x and time ti and are still present in the priority queue at the time of the current operation.

7

Conclusion

We gave a hierarchy of distribution-sensitive properties in Figure 1. We proved that the working-set and the uniﬁed bounds are asymptotically equivalent. Our focus was on distribution-sensitive priority queues. Provably, priority queues cannot satisfy the sequential-access property, and in accordance neither the dynamic-ﬁnger nor the uniﬁed conjecture. We therefore considered other distribution-sensitive properties, namely: the working-set and the queueish properties. We presented a priority queue that satisﬁes both properties. Our priority queue builds on the priority queue of [5], which supports insert in constant time and delete-min in the working-set time bound. We showed that the same structure can also support delete operations within the working-set bound. We then

222

A. Elmasry, A. Farzan, and J. Iacono

modiﬁed the structure to satisfy the queueish property as well. It is worthy to note that the priority queue designed supports the stronger deﬁnition of the working-set and the queueish properties in which the elements deleted are not accounted for in the time bounds. Our result about the asymptotic equivalence of the working-set bound and the uniﬁed bound then implies that our priority queue also satisﬁes the uniﬁed, static-optimality and static-ﬁnger bounds. We deﬁned the notion of time ﬁngers, which encapsulates the working-set and the queueish properties. The priority queue described thus far has two time ﬁngers. We extended our priority queue to possibly support any constant number of time ﬁngers. The bounds mentioned are amortized. However, we showed that the time bounds for the working-set and queueish properties can also be made to work in the worst case. More generally, the multiple time-ﬁnger bounds can be made to work in the worst case. However, the time bounds for other properties: uniﬁed bound, static optimality, and static ﬁnger, naturally remain amortized.

References 1. Bdoiu, M., Cole, R., Demaine, E.D., Iacono, J.: A Uniﬁed Access Bound on Comparison-based Dynamic Dictionaries. Theoretical Computer Science 382(2), 86–96 (2007) 2. Brodal, G.S., Fagerberg, R.: Funnel Heap - a Cache Oblivious Priority Queue. In: Bose, P., Morin, P. (eds.) ISAAC 2002. LNCS, vol. 2518, pp. 219–228. Springer, Heidelberg (2002) 3. Cole, R.: On the Dynamic Finger Conjecture for Splay Trees. Part II: Finger Searching. SIAM Journal on Computing 30, 44–85 (2000) 4. Elmasry, A.: On the Sequential Access Theorem and Dequeue Conjecture for Splay Trees. Theoretical Computer Science 314(3), 459–466 (2004) 5. Elmasry, A.: A Priority Queue with the Working-set Property. International Journal of Foundation of Computer Science 17(6), 1455–1466 (2006) 6. Fredman, M.L., Sedgewick, R., Sleator, D.D., Tarjan, R.E.: The Pairing Heap: a New Form of Self-adjusting Heap. Algorithmica 1(1), 111–129 (1986) 7. Lacono, J.: Improved Upper Bounds for Pairing Heaps. In: Halld´ orsson, M.M. (ed.) SWAT 2000. LNCS, vol. 1851, pp. 32–45. Springer, Heidelberg (2000) 8. Iacono, J.: Distribution-sensitive Data Structures. Ph.D. thesis, Rutgers, The state University of New Jersey, New Brunswick, New Jersey (2001) 9. Iacono, J., Langerman, S.: Queaps. Algorithmica 42(1), 49–56 (2005) 10. Sleator, D.D., Tarjan, R.E.: Self-adjusting Binary Search Trees. Journal of the ACM 32(3), 652–686 (1985) 11. Tarjan, R.E.: Sequential Access in Splay Trees Takes Linear Time. Combinatorica 5(4), 367–378 (1985)

Enumerating Tatami Mat Arrangements of Square Grids Alejandro Erickson1 and Mark Schurch2 1

Department of Computer Science, University of Victoria, V8W 3P6, Canada 2 Mathematics and Statistics, University of Victoria, V8W 3R4, Canada {ate,mschurch}@uvic.ca

Abstract. We prove that the number of monomer-dimer tilings of an n × n square grid, with m < n monomers in which no four tiles meet at any point is m2m + (m + 1)2m+1 , when m and n have the same parity. In addition, we present a new proof of the result that there are n2n−1 such tilings with n monomers, which divides the tilings into n classes of size 2n−1 . The sum of these over all m ≤ n has the closed form 2n−1 (3n−4)+2 and, curiously, this is equal to the sum of the squares of all parts in all compositions of n.

1

Introduction

Tatami mats are a traditional Japanese ﬂoor covering, whose outside is made of soft woven rush straw, and whose core is stuﬀed with rice straw. They have been in use by Japanese aristocracy since the 12th century, but modern versions of them are now available to the average consumer to be used as ﬂoor mats, in lieu of carpeting, or as essential furnishing in a tatami room. The mats are integral to Japanese culture, and are often used to describe the square footage of a room. A standard full mat measures 6 × 3 , and a half mat is 3 × 3 . An arrangement of the mats in which no four meet at any point is often preferred because it is said to be auspicious. We call such arrangements monomerdimer tatami tilings. The monomer-dimer tiling in Fig. 1 violates the tatami condition, and the one in Fig. 2 does not.

Fig. 1. The tatami condition is that no four tiles may meet at a point. Such violations are circled.

Tilings with polyominoes are well studied, and they appear in physical models, the theory of regular languages, and of course, combinatorics (see [2, 12, 4, 8, 5]). C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 223–235, 2011. c Springer-Verlag Berlin Heidelberg 2011

224

A. Erickson and M. Schurch

Fig. 2. A tatami tiling of the 10 × 31 grid with 10 monomers, 64 vertical dimers and 86 horizontal dimers. Compare this with Fig. 6.

Considerable credit is owed to these and other authors for the popularity of monomer-dimer tilings, particularly of their enumeration. This begs the question, given a room’s size, how many diﬀerent auspicious arrangements of mats are there? The dimer-only version of the problem appears in the fourth volume of The Art of Computer Programming ([7]), a series named by American Scientist as one of the 100 most inﬂuential over a century of science ([9]). Motivated by the exercise posed by Prof. Knuth, our co-authors from [3] published the ordinary generating functions for ﬁxed height, dimer-only tatami tilings in [11], and their solution appears in [7]. In Fall 2009 our research group discovered the structure which is published in [3], and described in the next section. Problems such as the enumeration of tatami tilings with r rows, c columns, and m monomers, have since become within reach. This paper completes such an enumeration for square grids. In the same year, Prof. Ruskey shared a tatami ﬂavoured New Year’s greeting with Prof. Knuth, among others. He ﬁlled the letters of “Happy New Year” with tatami tilings that illustrate the structure we had discovered (see Fig. 3), and closed by proposing the problem: ... perhaps you will have fun proving that the number of such tilings of an n × n square that maximize the number of monomers is n2n−1 .

Fig. 3. Part of Prof. Ruskey’s new year’s greeting for 2010

Before the new decade came about, Ruskey received a reply from Knuth which read:

Enumerating Tatami Mat Arrangements of Square Grids

225

Dear Frank, I resisted the challenge in your New Year’s card (about 2n−1 n) for more than four weeks, but ﬁnally realized that I couldn’t live any longer without trying to ﬁnd out what was going on with those tatami tilings. I budgeted half a day to explore the problem; and ﬁnally ﬁgured out enough of the structure to declare victory after two days; but my derivation is not at all simple. Certainly I have no way to group the solutions into, say, n classes of size 2n−1 (although I do have lots of classes of solutions of size 2n−2 ). Our solution in [3] does not divide the tilings into such classes either, so we remedy the lack of symmetry by presenting a new proof which does. This time we count the tilings directly, rather than recursively. Alhazov et al. followed up on the aforementioned dimer-only research with a treatment of odd-area tatami tilings which include a single monomer. They closed [1] with this remark: However, the variety of tilings with arbitrary number of monominoes is quite “wild” in sense that such tilings cannot be easily decomposed, see Figure 11; therefore, most results presented here do not generalize to arbitrary number of monominoes, the techniques used here are not applicable, and it is expected that any characterization or enumeration of them would be much more complicated. The structure we found, however, reveals the opposite; the tilings with an arbitrary number of monomers are easily decomposed. The decomposition has a satisfying symmetry, it is ammenable to inductive arguments, and it shows that the complexity of a tatami tiling is linear in the dimensions of the grid (compare Fig. 2 with Fig. 6). We use it extensively to prove our main result. Let T (n, m) be the number of n × n tatami tilings with exactly m monomers. Theorem 1. If n and m have the same parity, and m < n, then T (n, m) = m2m + (m + 1)2m+1 . This conﬁrms Conjecture 3 in [3] for d = 0 (as was promised there), and completes the enumeration of tatami tilings of square grids, since T (n, m) = 0 when m > n. Nice round numbers such as these tend to be easily identiﬁed in output generated by exhaustively listing all tilings on a given size of grid. Both our research group and Knuth saw the sequence long before it was proven. Knuth wrote to Ruskey: I did happen to notice that even more is true — although I won’t have time to prove it. I just have overwhelming empirical evidence for the following theorem, at least up to 12 × 12 (and I’ll soon have much more data because the computer programs are nowhere near any breaking points): The number of monomer-dimer tatami tilings of an n×n square, in which there are m monomers, where m < n and m + n is even, is

226

A. Erickson and M. Schurch

exactly 2m (3m + 2). For example, the generating function when n = 11 is 10z + 88z 3 + 544z 5 + 2944z 7 + 14848z 9 + 11264z 11, and when n = 12 it is 2 + 32z 2 + 224z 4 + 1280z 6 + 6656z 8 + 32768z 10 + 24576z 12. Evaluating Knuth’s generating functions at z = 1 and simplifying reveals that there are 2n−1 (3n − 4) + 2 tatami tilings of the n × n grid. As a curious afterthought, we note that this is equal to the sum of the squares of all parts in all compositions of n. 1.1

Structure

Tatami tilings of rectangular grids have an underlying structure, called the Tdiagram, which is an arrangement of four possible types of features, shown in Figures 4-5, up to rotation and reﬂection (see [3] for a complete explanation). Each feature consists of a source, shown in colour, which forces the placement of up to four rays. Rays propagate to the boundary of the grid and do not intersect each other. A valid placement in the grid of a non-zero number of features determines a tiling uniquely. Otherwise, the trivial T-diagram corresponds to the four possible running bond patterns (brick laying pattern).

(a) A loner feature.

(b) A vee feature.

Fig. 4. These two types of features must have their coloured tiles on a boundary, as shown, up to rotation and reflection

Monomers occur on the boundary of the grid, and inside vortices, but nowhere else. The T-diagram is also a partition of the tiles into blocks of horizontal and vertical running bond. Wherever horizontal bond meets a vertical boundary of the grid, dimers alternate with monomers, forming a section of jagged boundary, and similarly when vertical bond meets horizontal boundary. The tiling in Fig. 6 uses all four types of features, displays this partition into horizontal and vertical running bond, and indicates all instances of jagged boundary. Its T-diagram is shown on its own in Fig. 7. Throughout this paper we consider tilings on the n × n integer grid, with the origin at the bottom left of the tiling. Let the coordinate of a grid square be the point at its bottom left corner as well. A diagonal is a rotation of the following: a monomer at (x0 , 0), and (vertical) dimers covering the pairs of grid squares (x0 + 1 + k, k) and (x0 + 1 + k, k + 1), for each non-negative k such that x0 + 1 + k ≤ n − 1. A diagonal can be flipped

Enumerating Tatami Mat Arrangements of Square Grids

(a) A vertical bidimer feature.

227

(b) A counterclockwise vortex feature.

Fig. 5. These two types of features may appear anywhere in a tiling provided that the coloured tiles are within the boundaries of the grid

Fig. 6. A tiling showing all four types of sources. Coloured in magenta, from left to right they are, a clockwise vortex, a vertical bidimer, a loner, a vee, and another loner. Jagged boundaries are indicated by brackets.

in place, so that the monomer is mapped to (n − 1, n − x0 − 1), and the dimers change orientation. These equivalent operations preserve the tatami condition. Diagonals are used and illustrated frequently in the next section.

2

Square Grids

Let T (n, m) be the number of n × n tatami tilings with m monomers. Theorem 1. If n and m have the same parity, and m < n, then T (n, m) = m2m + (m + 1)2m+1 . Proof. We show that any n × n tiling with m monomers and m < n has exactly one bidimer or vortex and we show that m is a function of the shortest distance from this source to the boundary. Such a feature determines all tiles in the tiling except a number of diagonals that can be ﬂipped independently. Proving the result becomes a matter of counting the number of allowable positions for the bidimer or vortex. For example, the 20 × 20 tiling in Fig. 8 has a vertical bidimer which forces the placement of the green and blue tiles, while the remaining

228

A. Erickson and M. Schurch

Fig. 7. A T-diagram

diagonals are coloured in alternating grey and magenta. There are eight such diagonals, so there are 28 tilings of the 20 × 20 grid, with a vertical bidimer in the position shown. Each of these 28 tilings has exactly 10 monomers. Let the centers of bidimers and vortices be the crossing point of an X-drawn through them symmetrically, where the origin is the grid point at the bottom left of the grid as in Figures 8-10. Suppose the center of a feature is at the point (xf , yf ), then without loss of generality, we may re-orient the tiling, by rotating and reﬂecting, so that yf ≤ xf ≤ n/2, to count the monomers and diagonals as follows. The number of diagonals for each type of bidimer or vortex centered at (xf , yf ), can be abstracted from the ﬁgures, by counting certain grid squares on boundaries. Namely, the grid squares indicated by the brackets ﬁlled with grey in Figures 8-10, which are not covered by green or blue dimers. Omitting some details which can be gleaned from Figures 8-10, we tabulate these numbers, abbreviating top, bottom, left, right, and corner with the letters t,b,l,r, and c, respectively. feature center positions grid squares diagonals c-monomers y f = xf bl and tr 0 0 0 yf < xf bl and tr 2(xf − yf ) − 1 xf − yf − 1 1 yf = xf = n/2 tl and br 0 0 0 yf + xf < n tl and br 2(n − xf − yf ) − 1 n − xf − yf − 1 1 The number of monomers is equal to the number of diagonals plus cornermonomers, plus, possibly, a vortex. When yf = xf = n/2, this number is either 0 or 1, and if yf = xf < n/2, it is n − xf − yf = n − 2yf , or n − 2yf + 1. When yf < xf , the number of monomers is also n − 2yf or n − 2yf + 1. In both the cases, yf = xf and yf < xf , the number of monomers is n − 2yf if the feature is a bidimer, and n − 2yf + 1 if it is a vortex. Therefore, the number of monomers is decided by the distance from the center of this feature to the nearest boundary of the grid. The number of positions for features whose tilings have m monomers are tabulated below the following explanation. We count the number of positions for bidimers for a ﬁxed yf , whose tilings have n − 2yf monomers as in Fig. 9 and Fig. 8. Abandoning the range restriction on xf , there are four such positions when xf = yf , up to rotation, and otherwise

Enumerating Tatami Mat Arrangements of Square Grids

tl

229

tr x−y

n−x−y

x

n−x

y

y

(0, 0) bl x−y

y

y

n−x−y

br

Fig. 8. Vertical bidimer

we count the four rotations of the case where yf < xf < n − yf . Thus there are 4(n − yf − 1 − yf ) positions for xf , and 4(n − 2yf − 1) = 4(m − 1), where m is the number of monomers. The same argument works for the vortex in Fig. 10, at distance yf from the nearest boundary, in spite of the fact that xf and yf are not integers. Here the number of monomers is n − 2yf + 1. Once again, the number of positions for the feature is four when xf = yf , and otherwise it is 4(n − 2yf − 1), which is equal to 4(m − 2) when expressed in terms of m. We tabulate what we have derived above. The words horizontal, vertical, counterclockwise and clockwise are abbreviated as h, v, cc and c, respectively. Position Feature Positions Diagonals xf = yf h and v bidimers 4 m−1 xf = yf cc and c vortices 4 m−2 xf < yf h and v bidimers 4(m − 1) m − 2 xf < yf cc and c vortices 4(m − 2) m − 3 Each term in the following sum comes from a row of the table, in the same respective order, and similarly, the three factors in each sum term come from the last three columns of the table. T (n, m) =2 · 4 · 2m−1 + 2 · 4 · 2m−2 + 2 · 4(m − 1) · 2m−2 + 2 · 4(m − 2) · 2m−3 =2 · 2m+1 + 2 · 2m + (m − 1)2m+1 + (m − 2)2m =m2m + (m + 1)2m+1 . That is, there are m2m tilings with vortices and (m + 1)2m+1 without.

230

A. Erickson and M. Schurch

tl

tr x−y

n−x−y

x

n−x

y

y

(0, 0) bl x − y

y

y

n−x−y

br

Fig. 9. Horizontal bidimer

This completes the enumeration of n × n tatami tilings with m monomers. Let this not be the end of the square tatami tiling story. We are compelled by other mathematicians, including Knuth, to organize the n × n tatami tilings with n monomers into n classes of size 2n−1 . We present a proof which directly counts diagonal ﬂips. The proof in [3] uses induction on the dimensions of the grid to show that n2n−1 = 4S(n), where S(n) = 2n−2 + 4S(n − 2), where S(1) =

1 and S(2) = 1. 4

The recurrence arises from relating the collisions of diagonals in an (n−2)×(n−2) tiling with those of an n × n tiling. Theorem 2 (Erickson, Ruskey, Schurch, Woodcock, [3]). T (n, n) = n2n−1 Proof (n classes of size 2n−1 ). We use the setup in [3]. Every tatami tiling of the n × n grid with n monomers can be obtained by performing a set of ﬂips (of diagonals) on a running bond, in which no monomer is moved more than once, and the corner monomers remain ﬁxed. As an immediate consequence, every tiling has exactly two corner monomers which are in adjacent corners, and as such, it has four distinct rotational symmetries. Let S be the n × n tilings with n monomers whose upper corners have monomers. It is suﬃcient to divide the n2n−3 tilings of S, into n classes of size 2n−3 , and then use the rotational symmetries of these to obtain the n classes of size 2n−1 of all the tilings. In this context, a ﬂipped diagonal or monomer refers to one which was ﬂipped from its initial position in the running bond, in the set of ﬂips referred to above.

Enumerating Tatami Mat Arrangements of Square Grids

tl

231

tr x − y

n − x − y

x

n − x

y

y

(0, 0) bl x − y

y

y

n − x − y

br

Fig. 10. Counter clockwise vortex. Note that xf and yf are not integers.

Each monomer is either ﬂipped on its longest or shortest diagonal, or not ﬂipped at all (see Fig. 11). Two monomers ﬂipped on their longest diagonals cannot have been ﬂipped on diagonals of the same length, because any two longest diagonals either interfere with each other, or they have diﬀerent parities. A tiling in S has either, (a) a monomer ﬂipped on (one of) its longest diagonal which is the unique diagonal of maximum length, or (b) no monomer that is ﬂipped on its longest diagonal. Suppose n is odd. The tilings in S are obtained from a vertical running bond with monomers in the top corners, as illustrated for n = 17 in Fig. 11. Here, the lengths of a monomer’s diagonals, deﬁned by the number of tiles they contain, diﬀer except when the monomer is in the central column of the grid. Flip a monomer μ on (one of) its longest diagonal, δ, as in Fig. 12(a). There are n − 3 monomers that may still be ﬂipped. We claim that if these are ﬂipped only along diagonals strictly shorter than δ, then each monomer has exactly one ﬂip available to it, and the ﬂips can be made independently, so that the number of combinations is 2n−3 . This is obviously the case in Fig. 12(a), where the available ﬂips are shown by the diagonal lines. We set up the general argument. Label each monomer with its x coordinate in the running bond, recalling that a grid square’s coordinate is its bottom left corner. The diagonal to its left has size x + 1, and the one to the right has size n−x. Diagonals interfere with each other on the left boundary if and only if they map monomers from top and bottom boundaries, whose labels α and β sum to more than n. Diagonals interfere on the right if and only if they map monomers

232

A. Erickson and M. Schurch

Fig. 11. Each monomer is initially in two diagonals

from top and bottom boundaries which do not interfere on the left. This labeling serves to prove that our statement about Fig. 12(a) holds in general. There are n − 2 choices for μ, and when μ is on the central column there are two choices of diagonals to ﬂip it on. This gives n − 1 classes of size 2n−3 . The case where no monomer is ﬂipped on its longest diagonal gives the nth class of size 2n−3 , because neither the middle column monomer nor the two corner monomers are ﬂipped (see Fig. 12(b)). This concludes the odd case.

(a) One monomer is flipped on (b) No monomer is flipped on its (one of) its longest diagonal. longest diagonal. Fig. 12. Odd n

Let n be even. The tilings in S are obtained from a horizontal running bond, and, contrary to the odd case, all monomers initially have two diagonals whose lengths diﬀer. Flip a monomer μ on its longest diagonal. Again, there are n − 3 monomers remaining, and each one has one available diagonal which is strictly shorter than

Enumerating Tatami Mat Arrangements of Square Grids

233

that of μ, and they can each be ﬂipped on these independently. This can be seen to hold in Fig. 13(a), and a labeling similar to the one described for odd n shows that it holds in general. The case where no monomer is ﬂipped on its longest diagonal introduces an asymmetry for even n, resulting from the fact that every monomer has two diagonals that diﬀer in length. The class of size 2n−2 is easily divided into two classes, however, since we are merely dealing with combinations of an n − 2 set.

(a) One monomer is flipped on its (b) Every monomer is flipped on its longest diagonal. shortest diagonal. Fig. 13. Even n

It comes as a surprise at ﬁrst, but the total number of n × n tilings is equal to the sum of the squares of all parts in all compositions of n. We prove this by showing they satisfy the following expression. Corollary 1. The number of n × n tatami tilings is 2n−1 (3n − 4) + 2. Proof. From [3], we have that T (n, m) = 0 when m > n. Let T (n) =

m≥0

so that n/2

T (n) = n2n−1 +

(n − 2i)2n−2i + (n − 2i + 1)2n−2i+1 , i=1

and notice that the sum simpliﬁes to T (n) = n2n−1 +

n−1 i=1

i2i .

T (n, m),

234

A. Erickson and M. Schurch

Now we use the fact that 2k + 2k+1 + · · · + 2n−1 = 2n − 1 − 2k + 1 = 2n − 2k to rearrange the sum. T (n) =n2n−1 +

n−1

i2i

i=1

=n2n−1 + (n − 1)2n −

n−1

2i

i=1

=2n−1 (3n − 4) + 2 We omit the details of this next, and ﬁnal curiosity. A reference to the sequence in question can be found in sequence A027992 of the The On-Line Encyclopedia of Integer Sequences ([6]). Corollary 2. The number of n × n tatami tilings is equal to the sum of the squares of all parts in all compositions of n.

3

Conclusions and Further Research

The number of red squares in the Hasse diagram in [10] is the sum of the squares of all parts in all compositions of n, and it would be aesthetically pleasing to see a natural bijection from the tatami tilings of the n × n grid to these red squares (see Fig. 14).

Fig. 14. Is there a mapping from n × n tatami tilings to red squares?

Perhaps of broader interest is the enumeration of T (n, m, v, h), the number of n × n tilings with m monomers and v and h vertical and horizontal dimers, respectively. Some progress has been made on this by Knuth, as well as the authors of [3] (Section 4.1, Conjecture 4).

Enumerating Tatami Mat Arrangements of Square Grids

235

Acknowledgements. The authors are grateful to Prof. Frank Ruskey for his continued participation in tatami research and insightful comments on this paper, as well as Prof. Don Knuth for his valuable communications about tatami tilings. We also thank the anonymous referees for their feedback and pointing out important references on classical tilings.

References [1] Alhazov, A., Morita, K., Iwamoto, C.: A note on tatami tilings. In: Proceedings of the 2009 LA Winter Symposium Mathematical Foundation of Algorithms and Computer Science, vol. 1691, pp. 1–7 (2010) [2] Benedetto, K.P., Loehr, N.A.: Tiling problems, automata, and tiling graphs. Theoretical Computer Science 407(1-3), 400–411 (2008) [3] Erickson, A., Ruskey, F., Schurch, M., Woodcock, J.: Monomer-dimer tatami tilings of rectangular regions. The Electronic Journal of Combinatorics 18(1), 24 (2011) [4] Gale, D., Golomb, S.W., Haas, R.: Mathematical entertainments. The Mathematical Intelligencer 18(2), 38–47 (1996) [5] Hock, J.L., McQuistan, R.B.: A note on the occupational degeneracy for dimers on a saturated two-dimensional lattice space. Discrete Applied Mathematics 8(1), 101–104 (1984) [6] Jovovic, V.: Comment on a027992 (2005), http://oeis.org/A027992 [7] Knuth, D.E.: The Art of Computer Programming, vol 4A: Combinatorial Algorithms, Part 1, 1st edn. Addison-Wesley Professional (2011) [8] Merlini, D., Sprugnoli, R., Cecilia Verri, M.: Strip tiling and regular grammars. Theoretical Computer Science 242(1-2), 109–124 (2000) [9] Morrison, P., Morrison, P.: 100 or so books that shaped a century of science. American Scientist 87(6), 1 (1999) [10] Piesk, T.: Binary and compositions 5 (2010), http://commons.wikimedia.org/wiki/File:Binary_and_compositions_5.svg [11] Ruskey, F., Woodcock, J.: Counting fixed-height tatami tilings. The Electronic Journal of Combinatorics 16, 20 (2009) [12] Stanley, R.P.: On dimer coverings of rectangles of fixed width. Discrete Applied Mathematics 12(1), 81–87 (1985)

Quasi-Cyclic Codes over F13 T. Aaron Gulliver Department of Electrical and Computer Engineering, University of Victoria Victoria, BC Canada, V8W 3P6 agullive@ece.uvic.ca

Abstract. Let dq (n, k) be the maximum possible minimum Hamming distance of a linear [n, k] code over Fq . Tables of best known linear codes exist for all fields up to q = 9. In this paper, linear codes over F13 are constructed for k up to 6. The codes constructed are from the class of quasi-cyclic codes. In addition, the minimum distance of the extended quadratic residue code of length 44 is determined.

1

Introduction

Let Fq denote the Galois ﬁeld of q elements, and let V (n, q) denote the vector space of all ordered n-tuples over Fq . A linear [n, k] code C of length n and dimension k over Fq is a k-dimensional subspace of V (n, q). The elements of C are called codewords. The (Hamming) weight of a codeword is the number of non-zero coordinates. The minimum weight of C is the smallest weight among all non-zero codewords of C. The minimum weight of a linear code equals the minimum distance between codewords. An [n, k, d] code is an [n, k] code with minimum weight d. Let Ai be the number of codewords of weight i in C. Then the numbers A0 , A1 , . . . , An are called the weight distribution of C. A central problem in coding theory is that of optimising one of the parameters n, k and d for given values of the other two. One version is to ﬁnd dq (n, k), the largest value of d for which there exists an [n, k, d] code over Fq . Another is to ﬁnd nq (k, d), the smallest value of n for which there exists an [n, k, d] code over Fq . A code which achieves either of these values is called optimal. Tables of best known linear codes exist for all ﬁelds up to q = 9 [6]. In this paper, linear codes over F13 are constructed for k up to 6. The Griesmer bound is a well-known lower bound on nq (k, d) nq (k, d) ≥ gq (k, d) =

k−1 j=0

d , qj

(1)

where x denotes the smallest integer ≥ x. For k ≤ 2, the Griesmer bound is met for all q and d. The Singleton bound [13] is a lower bound on nq (k, d) and is given by nq (k, d) ≥ d + k − 1 (2) C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 236–246, 2011. c Springer-Verlag Berlin Heidelberg 2011

Quasi-Cyclic Codes over F13

237

Codes that meet this bound are called maximum distance separable (MDS). MDS codes exist for all values of n ≤ q + 1. Thus for q = 13, MDS codes exist for all lengths 14 or less. For larger lengths and dimensions, far less is known about codes over F13 . MDS self-dual codes (k = n/2), of lengths 2, 4, 6, 8, 10 and 14 are given in [2], as well as self-dual [12, 6, 6], [16, 8, 8], [20, 10, 10], [22, 11, 10] and [24, 12, 10] codes. de Boer earlier discovered a self-dual [18, 9, 9] code, and [23, 3, 20] and [23, 17, 6] codes [7]. The [18, 9, 9], [24, 12, 10] and [30, 15, 12] extended quadratic residue (QR) codes are given in [14]. Using Magma [3], it was determined that the next extended QR code over F13 has parameters [44, 22, 16]. In this paper, codes with dimensions k = 3 − 6 are constructed. These codes establish lower bounds on the minimum distance. Many of these meet the Singleton and/or Griesmer bounds, and so are optimal. A punctured code of C is a code obtained by deleting a coordinate from every codeword of C. A shortened code of C is a code obtained by taking only those codewords of C having a zero in a given coordinate position and then deleting that coordinate. The following bounds can be established based on these constructions 1) dq (n + 1, k) ≤ dq (n, k) + 1, and 2) dq (n + 1, k + 1) ≤ dq (n, k). Using the codes given in this paper, they provide many additional lower bounds. The next section presents the class of quasi-cyclic codes, and the construction results are given in Section 3.

2

Quasi-Cyclic Codes

A code C is said to be quasi-cyclic (QC) if a cyclic shift1 of any codeword by p positions is also a codeword in C [8]. A cyclic code is a QC code with p = 1. The length of a QC code considered here is n = mp. With a suitable permutation of coordinates, many QC codes can be characterized in terms of (m × m) circulant matrices. In this case, a QC code can be transformed into an equivalent code with generator matrix G = [R0 R1 R2 ... Rp−1 ] , where Ri , i = 0, 1, . . . , p − 1, is a circulant matrix of the form ⎡ ⎤ r0,i r1,i r2,i · · · rm−1,i ⎢ rm−1,i r0,i r1,i · · · rm−2,i ⎥ ⎥ ⎢ ⎢ ⎥ Ri = ⎢ rm−2,i rm−1,i r0,i · · · rm−3,i ⎥ . ⎢ .. .. .. .. ⎥ ⎣ . . . . ⎦ r1,i 1

r2,i r3,i · · ·

(3)

(4)

r0,i

A cyclic shift of an m-tuple (x0 , x1 , . . . , xm−1 ) is the m-tuple (xm−1 , x0 , . . . , xm−2 ).

238

T.A. Gulliver

The algebra of m × m circulant matrices over Fq is isomorphic to the algebra of polynomials in the ring Fq [x]/(xm − 1) if Ri is mapped onto the polynomial ri (x) = r0,i + r1,i x + r2,i x2 + · · · + rm−1,i xm−1 , formed from the entries in the ﬁrst row of Ri [13]. The ri (x) associated with a QC code are called the defining polynomials [8]. The set {r0 (x), r1 (x), . . . , rp−1 (x)} deﬁnes an [mp, m] QC code with k = m. The construction of QC codes requires a representative set of deﬁning polynomials. These are the equivalence class representatives of a partition of the set of polynomials of degree less than m. Two polynomials, rj (x) and ri (x) are said to be equivalent if they belong to the same class, which here means rj (x) = γxl ri (x) mod (xm − 1), for some integer l > 0 and scalar γ ∈ Fq \{0}. The number of representative deﬁning polynomials, N (m), for F13 is given below m N (m) 2 8 3 63 4 604 5 6189 6 67116 The QC codes presented here were constructed using a stochastic optimization algorithm, tabu search, similar to that in [4] and [11]. This algorithm will be described in the next section. By restricting the search to the class of QC codes, and using a stochastic heuristic, codes with high minimum distance can be found with a reasonable amount of computational eﬀort.

3

The Construction Algorithm

Imposing a structure on the codes being considered results in a search space that is smaller than for the original problem. The more restrictions on the structure, the smaller the search problem. This results in a tradeoﬀ, since good codes may be missed if too much structure is imposed on the code. However, it is often the case that good codes have signiﬁcant structure, and this partially explains why the approach presented here works so well. It is not necessary to check the weight of every codeword in a QC code in order to determine d. Only a subset, N < M , of the codewords need be considered since the Hamming weight of i(x)bs (x) mod (xm − 1) is equal to the weight of i(x)γxl bs (x) mod (xm − 1) for all l ≥ 0 and γ ∈ GF(q) \ {0}. Note that this argument also applies to the set of deﬁning polynomials. Thus, for example, with q = 13 and m = 3, from the above table N = 63.

Quasi-Cyclic Codes over F13

239

To simplify the process of searching for good codes, the weights of the subset of codewords can be stored in an array, and a matrix, D, can be formed from the arrays for the deﬁning polynomials to be considered b1 (x) b2 (x) · · · i1 (x) w11 w12 · · · i2 (x) w21 w22 · · · .. .. .. D = . . . it (x) wt1 wt2 · · · .. .. .. . . .

bs (x) · · · by (x) w1s · · · w1y w2s · · · w2y .. .. . . wts · · · wty .. .. . .

iz (x) wz1 wz2 · · · wzs · · · wzy , where it (x) is the tth information polynomial, bs (x) is the sth deﬁning polynomial, and wts is the Hamming weight of it (x)bs (x) mod (xm − 1). Since it (x) and bs (x) correspond to the same polynomials, D is a square (y = z = N ), symmetric (by letting it (x) = bt (x) for all 1 ≤ t ≤ N ) matrix. For example, if q = 13 and m = 2, the matrix is 1 x + 1 x + 2 x + 3 x + 4 x + 5 x + 6 x + 12 1 1 2 2 2 2 2 2 2 x+1 2 2 2 2 2 2 2 0 x+2 2 2 2 2 2 2 1 2 D = x+3 2 2 2 2 1 2 2 2 x+4 2 2 2 1 2 2 2 2 x+5 2 2 2 2 2 1 2 2 x+6 2 2 1 2 2 2 2 2 2 2 2 2 2 2 x + 12 2 0 The complete weight distribution for a QC code composed of any set of bs (x) can be constructed from D. The search for a good code consists of ﬁnding p columns of D with a large minimum row sum, since the weight of a minimum distance codeword must be contained in these sums. Having decided on the values of m and p (and thus also n = mp), the entries of the integer matrix D can be calculated and the problem formulated as a combinatorial optimization problem. The goal is to ﬁnd max min wj,s , (5) S

1≤j≤N

s∈S

where S ⊆ {1, 2, . . . , N } and |S| = p. In general, one can take a multiset S with p elements, but it was found in past studies that for the new codes obtained, no deﬁning polynomial occurs more than once, so S is here required to be a set.

240

T.A. Gulliver

The optimization method used in this work is tabu search [5]. This method can produce good near-optimal (optimal in some cases) solutions to diﬃcult optimization problems with a reasonable amount of computational eﬀort [12]. Tabu search is a local search algorithm, which means that starting from an initial solution, a series of solutions is obtained so that every new solution only diﬀers slightly from the previous one. A potential new solution is called a neighbor of the old solution, and all neighbors of a given solution constitute the neighborhood of that solution. To evaluate the quality of solutions, a cost function is needed. Tabu search always proceeds to a best possible solution in the neighborhood of the current solution. In a simple version, if there are several equally good neighbors with the best cost, a random choice is made (note that it is possible that the best neighbor has a worse cost than the current solution has). To ensure that the search does not loop on a subset of moves or solutions, attributes of recent solutions are stored in a so-called tabu list; new moves or solutions with these attributes are then not allowed for L moves. Tabu search is applied here to the problem of ﬁnding QC codes, deﬁned as a minimization problem, in the following way. First, the problem is not formulated as generally as in (5), as the desired minimum distance, d, of the code is ﬁxed. A solution is any set S ⊆ {1, 2, . . . , N } of p columns of D, the neighborhood of a solution is the set of solutions obtained by replacing one column with a column that is not in the code, and the cost function is of the form C=

N j=1

max 0, d −

wj,s

s∈S

A solution with cost 0 now corresponds to a code with minimum distance at least d. If such a solution is found, the search ends. Otherwise, the search is continued (and possibly restarted occasionally), until a given time or iteration limit is reached. The tabu list is simply the indexes of the new columns. Thus, if a column is replaced by another, the new column must not be replaced during the next L moves. The values of L used were small, in the range p/10 ≤ L ≤ p/5. If a code was not found within 1000–2000 iterations, the search was restarted from a new random initial solution. As many as 1000 restarts were performed for given values of m and p. The total number of iterations to ﬁnd a code varied between about one hundred and a few million. The best QC codes found are given in Tables 1 to 4. The deﬁning polynomials are listed with the lowest degree coeﬃcient on the left, i.e., 7321 corresponds to the polynomial x3 + 2x2 + 3x + 7, with leading zeroes left out for brevity. The digits 10, 11 and 12 are denoted by (10), (11) and (12), respectively.

Quasi-Cyclic Codes over F13

241

As an example, consider the [18,3] code in Table 1 with m = 3 and p = 6 deﬁning polynomials. These polynomials give the following generator matrix ⎡ ⎤ 016 175 125 117 135 143 G = ⎣ 601 517 512 711 513 314 ⎦ 160 751 251 171 351 431 with weight distribution i Ai 0 1 15 456 16 468 17 720 18 552 This code is optimal since it meets the Griesmer bound (1), and so establishes that d13 (18, 3) = 15. For m = 5 and p = 4, the best code found has generator matrix ⎡ ⎤ 00018 14(10)(12)4 01(12)8(11) 12(11)3(12) ⎢ 80001 414(10)(12) (11)01(12)8 (12)12(11)3 ⎥ ⎢ ⎥ ⎥ G=⎢ ⎢ 18000 (12)414(10) 8(11)01(12) 3(12)12(11) ⎥ ⎣ 01800 (10)(12)414 (12)8(11)01 (11)3(12)12 ⎦ 00180 4(10)(12)41 1(12)8(11)0 2(11)3(12)1 with weight distribution i

Ai

0 1 15 9300 16 11640 17 51960 18 98520 19 125220 20 74652 This code is also optimal since it meets the Griesmer bound (1), and so establishes that d13 (20, 5) = 15. In addition, the codes for m = 3 and 4 with p = 5 meet the Griesmer bound. Note that all codes with n ≤ 14 given in the tables are MDS.

242

T.A. Gulliver

Table 1. Best QC codes over F13 with p = 3 code [6,3] [9,3] [12,3] [15,3] [18,3] [21,3] [24,3] [27,3] [30,3] [33,3] [36,3] [39,3] [42,3] [45,3] [48,3]

d 4 7 10 12 15 18 20 23 26 29 32 34 37 40 43

[51,3] 45 [54,3] 48 [57,3] 51 [60,3] 54 [63,3] 56 [66,3] 59 [69,3] 62 [72,3] 65

ri (x) 1, 12(12) 1, 15(11), 117 1, 135, 112, 153 11, 153, 12, 143, 11(10) 16, 175, 125, 117, 135, 143 115, 11(10), 146, 132, 16, 1, 176 1, 174, 1(11), 112, 19(12), 138, 114, 12(12) 112, 117, 12, 162, 17, 12(12), 13, 114, 19 124, 176, 11(12), 156, 13, 129, 13(11), 14, 17, 132 12, 1(10), 13(11), 18, 15, 12(12), 15(11), 132, 156, 126, 116 129, 11(10), 11, 11(11), 19, 146, 12(12), 14(11), 11(12), 145, 13, 18 1(11), 138, 12, 11, 14(11), 11(11), 16, 125, 112, 114, 113, 156, 15 15, 12, 119, 158, 126, 156, 138, 11(12), 11, 176, 117, 1(11), 112, 13(10) 18, 1(11), 163, 11, 134, 135, 126, 156, 174, 19(12), 17, 132, 125, 13, 162 116, 1(10), 1(11), 114, 14(11), 142, 1(10)6, 12(12), 19(12), 163, 11(12), 12 174, 146, 11, 1(12) 113, 16, 11, 17, 142, 146, 18, 118, 132, 194, 1(12), 156, 15, 117, 176, 116, 115 17, 11, 13(12), 132, 118, 19, 153, 185, 13(10), 14(11), 146, 162, 142, 11(11), 135 175, 15, 11(10) 1(11), 11(10), 175, 123, 12(12), 115, 156, 1, 163, 124, 13, 18, 11(12), 11(11), 146 112, 19, 17(12), 132 162, 11(12), 13, 118, 113, 115, 13(12), 117, 19, 18, 112, 12, 185, 138, 153, 123, 17 156, 126, 132 116, 143, 119, 185, 146, 15(11), 11, 134, 19(12), 117, 156, 115, 19, 135, 12(11), 15 158, 125, 154, 113, 18 118, 1, 11(11), 13(12), 135, 154, 17, 11, 13(11), 163, 12(10), 129, 112, 115, 15 12(11), 19(12), 119, 132, 19, 18, 123 18, 142, 19, 11(11), 194, 17, 14(11), 13(11), 118, 132, 11, 123, 125, 112, 113, 12(10) 156, 17(12), 16, 117, 129, 116, 1(11) 1(12), 134, 1(11), 17(12), 119, 1, 11, 15(11), 163, 13(10), 124, 114, 142, 13, 128 14(11), 154, 126, 11(12), 11(11), 156, 19, 117, 176

Quasi-Cyclic Codes over F13

Table 2. Best QC codes over F13 with p = 4 code [8,4] [12,4] [16,4] [20,4] [24,4] [28,4] [32,4] [36,4] [40,4] [44,4]

d 5 9 12 16 19 23 26 30 33 37

[48,4] 40 [52,4] 44 [56,4] 48 [60,4] 51 [64,4] 55 [68,4] 58 [72,4] 62 [76,4] 66 [80,4] 69 [84,4] 73 [88,4] 76 [92,4] 80 [96,4] 84

ri (x) 1135, 1326 104, 1197, 135 17, 1(10)3, 14(11)8, 161(11) 116, 1(11), 1186, 142, 134(10) 1326, 11, 1745, 111(11), 186, 1165 14, 13, 1159, 163(11), 1252, 112(12), 1294 103, 1(10)3, 1182, 114, 1143, 1(10)(10), 1132, 1(11)(10) 1155, 113, 139, 1117, 13(10)(11), 153(11), 125, 136, 122 12, 1315, 1, 115(10), 141, 117(10), 1825, 112(12), 1(12)4, 1184 14, 1118, 112(10), 11(11)(12), 113(10), 102, 1214, 12(10)4, 1(11) 13(10), 13(12)2 102, 1115, 12, 1166, 12(10)4, 133, 18(11), 145(11), 12(10)5, 1197 1825, 112(12) 11, 1, 1125, 1546, 12(11)6, 1(12)5, 11(10)4, 1293, 1135, 1197, 17(10) 1458, 168 103, 19, 1(11)6, 1112, 145(11), 17(10), 141, 13(10)6, 1376, 1385 119(10), 11(10)9, 11(12)8, 1(10)7 11, 135, 153, 1598, 169, 13(11)(12), 123, 1112, 12(12), 1416, 128(12) 1346, 1219, 118(10), 181 135, 14(10)5, 151, 11(11)(10), 1418, 166, 13(10)5, 13(11)2, 1564, 16(10) 14(11)(12), 1193, 1153, 14, 1116, 111(10) 1, 112, 14(10)2, 1592, 1265, 17(10), 151(11), 167(12), 193, 145(12) 1416, 117, 1115, 189, 1464, 14(12), 135 13, 1623, 1243, 1462, 1475, 12, 172, 1128, 161(11), 164, 1535, 12(12) 1625, 1148, 1284, 134, 18(12), 1328 171, 1284, 1376, 12(11)3, 113(12), 12(10), 1, 11(10)3, 161(12), 1154, 143 1289, 12(10)(11), 119(11), 1(11)(12), 129(12), 187, 1278, 1318 105, 11(10)(11), 1825, 1314, 1(12)(12), 102, 14(10)(11), 113, 11(12), 1423 127(12), 124(10), 1148, 1243, 1215, 12(11)6, 1329, 127, 1(11), 1382 196, 1376, 158, 167, 18(10)3, 1343, 129, 14(12), 1, 1498, 1187, 133 143(10), 1237, 1(11)5, 1598, 1217, 1172, 125, 12(11)2, 1238 11, 1245, 1, 1585, 113(12), 112(12), 1329, 1(12)(10), 1876, 197, 199, 1138 121(11), 1(11)6, 17(11), 1354, 15(11)6, 1134, 17(10), 1684, 1319, 14(10) 102, 1169, 149, 16(12), 1, 146, 1(12)(12), 1384, 1172, 1425, 1114, 1(10)1 115, 1217, 192, 12(11)3, 147(12), 1193, 1456, 1454, 1756, 127(10), 11(12)6 113, 1415, 1, 1254, 1(12)(12), 137(11), 13(11)3, 119(11), 187, 13, 11(11)9 1194, 1623, 13(12)2, 1264, 11(10), 1516, 11(11)5, 145(11), 128(11), 1148 106, 121, 129(10)

243

244

T.A. Gulliver

Table 3. Best QC codes over F13 with p = 5

code [10,5] [15,5] [20,5] [25,5] [30,5] [35,5] [40,5] [45,5] [50,5]

d 6 10 15 19 23 27 31 36 40

[55,5] 45 [60,5] 49 [65,5] 54 [70,5] 58 [75,5] 62 [80,5] 67 [85,5] 71 [90,5] 76

[95,5] 80 [100,5] 84

[105,5] 89

[110,5] 93

[115,5] 98

[120,5] 102

ri (x) 13(10), 10(10)(10) 154, 14(10)56, 11(12)9(10) 18, 14(10)(12)4, 1(12)8(11), 12(11)3(12) 10(12), 1(12)(11)(12), 14168, 11893, 17(10)(12)3 1561(11), 11659, 1163(12), 1(10)6(11), 126(10)(12), 1842 10(10), 112(12)6, 16842, 11458, 11(10)(12), 1212(12), 11(10)92 1, 13(12)1, 12434, 1157, 158(12)3, 133(10), 11(12)3(11), 111 11(10), 19, 11453, 1156(12), 12(12)5, 11247, 16746, 1222, 1635(11) 121(10)2, 14, 12619, 1(12)47, 12(12)2(12), 1454, 11586, 12835, 13792 13(10)(12) 138(12)8, 11, 1(10)3(10)6, 159, 172(11), 12348, 1673(11), 10(12)(12), 15684 128(11)8, 1776 13, 1589, 11284, 1333, 11(11), 153, 1456, 12(12)52, 13(12)6(11), 12(11)89 1(11)1(12), 11724 16(12), 1(10)94, 128(10)(11), 10(11)9, 1(11)11, 13(11)6, 11(12)49, 13138 1152(11), 1351(10), 11139, 1124(10), 14(11) 103, 14, 17(12)34, 12(11)(10)(12), 124(10)(11), 112, 1713, 11(11)89, 14182 106(12), 11374, 11553, 1(10)17, 145(11)3 1137, 11, 103, 1161(12), 1(10)9, 1987, 1(12)32, 1783, 11766, 142(11)3, 11618 12(12)43, 141(12)2, 127(11)5, 1152(12) 152, 102, 14(11)3(11), 15(10), 11(12)7(10), 1385, 11(11)38, 11229, 11295 15385, 1334, 18(11)6, 1115(12), 12154, 1841, 11(11)8 1944, 13, 1268(11), 1(11)92, 12(12)72, 119, 1131(10), 1841, 15(11)5 129(10)6, 1497(12), 11(12)82, 15325, 11584, 14742, 14(10)(11)3, 1397(10) 122, 1675(11), 1262(12), 12825, 113(11)5, 15(12)(11), 1(11)8, 1(10)4 12(10)3(10), 1394(12), 119(12)9, 1172(12), 12723, 1552, 121, 12(12)8(11) 14(11)(10)(11), 19(12) 14(10), 12978, 14, 11474, 11(11)7(11), 14(11)2(11), 1285, 127, 12132, 14646 1955, 12(11)63, 134(10)2, 14934, 11(12)96, 1(12), 1627(12), 14163, 119(12)8 135, 11(11)96, 15(10), 13494, 1241(11), 127(10)(12), 13(10)23, 11(10)2(11) 137(11), 13156, 13(10)28, 13(10)6(10), 1(10)95, 128(12)3, 12496, 1134(11) 159(11)8, 11917, 19(10)(10), 13(11)2(11) 108, 11445, 14(11)2, 12328, 14(11)82, 11833, 135(11)4, 18(10)9(12), 11269 114(12)5, 13172, 173(10), 144(12), 11(10)3, 142(12)4, 16975, 117(12)7 113(11)8, 11(12)(11)3, 12(10)3(12), 11875 106, 1121(11), 14(10)(11), 111, 161(12)6, 12694, 193, 14172, 11564, 1117(12) 13(10)4, 1(11)3(10), 115(10)8, 12349, 1131(12), 14374, 161(11)2, 1721 11(12)7(11), 1437, 11935, 11719 116, 137(10)5, 113, 15(11)(10)6, 13(11)(12)(10), 11(11)95, 119(12)(10) 15694, 15156, 126(12)9, 1(10)98, 119(12)5, 1275(10), 1588, 11917, 1229 12(10)(12)4, 1118(10), 11(11)(12), 114(11)(10), 118(12)5, 1427(10), 1515(11) 118(11), 169, 1127, 1, 124(12)3, 10(11), 11, 1338, 19(12)1(12), 13258 1863, 128(10)4, 1274, 1161(10), 13438, 116(10)(12), 18(12)(11) 131(10)(11), 11814, 11363, 117(10)6, 12(10)28, 11(12)93, 13862

Quasi-Cyclic Codes over F13

Table 4. Best QC codes over F13 with p = 6 code [12,6] [18,6] [24,6] [30,6] [36,6] [42,6]

d 7 11 16 21 26 32

[48,6] 37 [54,6] 42 [60,6] 47 [66,6] 52 [72,6] 57 [78,6] 63 [84,6] 68 [90,6] 73 [96,6] 78

[102,6] 83

[108,6] 88

[114,6] 94

[120,6] 99

[126,6] 105

[132,6] 110

[138,6] 115

[144,6] 120

ri (x) 12212, 11(10)93 12, 10(12)5(11), 128(10)3 185, 1827(12)4, 12835, 114947 13, 11183(10), 1133(12)4, 14(10)2(11)(12), 13537 1002, 118217, 115184, 126596, 12179, 1112 11(10), 12(12)235, 111893, 1121(12)(12), 138745, 119(12)24 13(12)6(11)(10) 114, 107, 1(11)267, 1131(12), 128(11)(10)(11), 1346(11)5 11(11)6(11)4, 1(12)511 105(11)7, 118633, 19, 111299, 1698(10)3, 1269(11)8, 121976, 1451(11)4 11(12)9(10)(11) 1(11)(12), 104(10), 12(12)4(10)4, 1469(10), 119(10)6, 1(10)25(11) 11(11)38(11), 14(10)46, 15564, 12361 13, 11, 1214, 10633, 1124(10)7, 141(11)8(10), 14187(11), 1455(11) 11(12)7(11)(12), 135843, 15577 1, 11(11)5, 12(10)(10)(11), 11(11)543, 147(12)92, 1299, 128958 111(12)(11)2, 15768, 11(12)61(10), 19247, 12773 12(12)1, 19, 153(10)3(11), 13784(10), 19(10)3, 10326, 12(12)(10)85 125268, 11(11)65, 13564, 187(11)9, 1192(10)7, 1(10)269 119, 149, 18332, 13(10)17(12), 14623, 131768, 105(10)3, 11837(10) 11123(11), 121435, 1241(10)8, 151(10)7, 11385, 11(10)535 106, 11, 11(11)68(11), 11398(11), 14(11)4(10), 143(11)2, 119(11)29 125286, 10169, 17556, 13469(11), 129474, 1535, 108(10)(10), 13(11)2(10)5 132345, 14535(12), 14(10)(12)82, 11(10)395, 1029, 112453, 115(10)68 19452, 1231(12), 132(11)(12), 11286, 1(12)(12)(12)(12), 116684, 13(11)476 147(12)(12), 1591 102, 1432, 116735, 1263, 12(10)8, 1, 11123(12), 11585(12), 14689(11) 19432, 17(10)96, 124592, 117758, 1347(11), 1419(12)4, 12(11)7(12)(11) 14(12)(12)6 1, 107, 149(11)1(12), 14(10)8(10)2, 121796, 11(12)173, 10249, 14142(12) 13(12)8(10)(11), 116, 116895, 126714, 11323(11), 1114(10)6, 1(11)684, 1901 19(12)84, 13673 104(11)7, 118(11)(10)8, 11(10)418, 1688(12), 15, 1(10)8(10)8, 125894 112452, 1282(12)(10), 1(10)4(11)(10), 1178(10)2, 121752, 16(12)59, 14618 135(12)15, 19(11)(10)2, 117(10)15, 113564, 16235(11) 125, 119(11)56, 1432(12)6, 1, 16726, 101(12), 1382(11)(10), 19133, 107(11) 112(11)(11), 1427(10)6, 116459, 121(11)6, 1187(12)(10), 131645, 1(10)46 146(10)(12)5, 112(10)(12)2, 1421(11)(10), 14(10)(11)9 16, 11, 117(12)6, 125(12), 11668(12), 14(11)(10)92, 11(11)(12)18 13(11)8(11)5, 10759, 114578, 111934, 11493(12), 1(10)91, 123575, 132193 114188, 13(12)5(12)4, 119427, 1154(10)3, 14147(12), 12(11)3(12)4 13, 17(10)72, 11, 19(12), 14295, 121(12)63, 119615, 11572(10), 116784 14(11)1(10)2, 1(12)(10)(12)(11), 129234, 111114, 11598(11), 14935(11) 132398, 1(12)918, 1417(11)2, 141(11)53, 10927, 115(11)5(12), 1(10)(12)14 112146, 12, 1(10)83, 119125, 17, 116(10)35, 1397, 11(11)683, 11(11)843 145(11)68, 13026, 1(10)4(11)8, 10743, 1846(11), 1251(12)9, 11635 112(11)(12)5, 129373, 164(12)2, 15(12)56, 14(11)818, 1328(11)4, 11032 101, 1574(11), 121642, 19(11)28, 127(12)6(10), 139(10)62, 1(12)969 16(11)2(11), 14(10)5(12), 125438, 1419(10)6, 119324, 12(12)45(11), 16(12) 13(12)3(12)2, 142(10)84, 1326(11)4, 15(11)(12)38, 1419, 129585, 13(11)434 114897, 114(10)64, 12(11)6(10)

245

246

T.A. Gulliver

References 1. Berlekamp, E.R.: Algebraic Coding Theory. McGraw-Hill, New York (1968) 2. Betsumiya, K., Georgiou, S., Gulliver, T.A., Harada, M., Koukouvinos, C.: On self-dual codes over some prime fields. Disc. Math. 262, 37–58 (2003) 3. Bosma, W., Cannon, J.: Handbook of Magma Functions, Department of Mathematics, University of Sydney, http://magma.maths.usyd.edu.au/magma/ 4. Daskalov, R.N., Gulliver, T.A.: New good quasi-cyclic ternary and quaternary linear codes. IEEE Trans. Inform. Theory 43, 1647–1650 (1997) 5. Glover, F.: Tabu search—Part I. ORSA J. Comput. 1, 190–206 (1989) 6. Grassl, M.: Bounds on the minimum distance of linear codes and quantum codes, http://www.codetables.de 7. de Boer, M.A.: Almost MDS codes. Design, Codes Crypt. 9, 143–155 (1996) 8. Greenough, P.P., Hill, R.: Optimal ternary quasi-cyclic codes. Designs, Codes and Crypt. 2, 81–91 (1992) 9. Gulliver, T.A., Bhargava, V.K.: Some best rate 1/p and rate (p-1)/p systematic quasi-cyclic codes over GF(3) and GF(4). IEEE Trans. Inform. Theory 38, 1369– 1374 (1992) 10. Gulliver, T.A.: New optimal ternary linear codes. IEEE Trans. Inform. Theory 41, 1182–1185 (1995) 11. Gulliver, T.A., Bhargava, V.K.: New good rate (m-1)/pm ternary and quaternary quasi-cyclic codes. Designs, Codes and Crypt. 7, 223–233 (1996) ¨ 12. Honkala, I.S., Osterg˚ ard, P.R.J.: Applications in code design. In: Aarts, E.H.L., Lenstra, J.K. (eds.) Local Search in Combinatorial Optimization. Wiley, New York (2003) 13. MacWilliams, F.J., Sloane, N.J.A.: The Theory of Error-Correcting Codes. NorthHolland, New York (1977) 14. Newhart, D.W.: On minimum weight codewords in QR codes. J. Combin. Theory Ser. A 48, 104–119 (1988)

Acyclic Colorings of Graph Subdivisions Debajyoti Mondal1 , Rahnuma Islam Nishat2, , Sue Whitesides2,∗ , and Md. Saidur Rahman3 1

Department of Computer Science, University of Manitoba Department of Computer Science, University of Victoria 3 Department of Computer Science and Engineering, Bangladesh University of Engineering and Technology (BUET) debajyoti mondal cse@yahoo.com, {rnishat,sue}@uvic.ca, saidurrahman@cse.buet.ac.bd 2

Abstract. An acyclic coloring of a graph G is a coloring of the vertices of G, where no two adjacent vertices of G receive the same color and no cycle of G is bichromatic. An acyclic k-coloring of G is an acyclic coloring of G using at most k colors. In this paper we prove that any triangulated plane graph G with n vertices has a subdivision that is acyclically 4-colorable, where the number of division vertices is at most 2n − 6. We show that it is NP-complete to decide whether a graph with degree at most 7 is acyclically 4-colorable or not. Furthermore, we give some suﬃcient conditions on the number of division vertices for acyclic 3-coloring of subdivisions of partial k-trees and cubic graphs. Keywords: Acyclic coloring, Subdivision, Triangulated plane graph.

1

Introduction

A coloring of a graph G is an assignment of colors to the vertices of G such that no two adjacent vertices receive the same color. A coloring of G is an acyclic coloring if G has no bichromatic cycle in that coloring. The acyclic chromatic number of G is the minimum number of colors required in any acyclic coloring of G. See Figure 1 for an example. The large number of applications of acyclic coloring has motivated much research [4,7]. For example, acyclic coloring of planar graphs has been used to obtain upper bounds on the volume of 3-dimensional straight-line grid drawings of planar graphs [6]. Consequently, acyclic coloring of planar graph subdivisions can give upper bounds on the volume of 3-dimensional polyline grid drawings, where the number of division vertices gives an upper bound on the number of bends suﬃcient to achieve that volume. As another example, solving large scale optimization problems often makes use of sparse forms of Hessian matrices; acyclic coloring provides a technique to compute these sparse forms [7]. Acyclic coloring was ﬁrst studied by Gr¨ unbaum in 1973 [8]. He proved an upper bound of nine for the acyclic chromatic number of any planar graph G,

Work is supported in part by the Natural Sciences and Engineering Research Council of Canada (NSERC) and University of Victoria.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 247–260, 2011. c Springer-Verlag Berlin Heidelberg 2011

248

D. Mondal et al.

with n ≥ 6 vertices. He also conjectured that ﬁve colors are suﬃcient for acyclic coloring of any planar graph. His upper bound was improved many times [1,9,10] and at last Borodin [3] proved that ﬁve is both an upper bound and a lower bound. Testing acyclic 3-colorability is NP-complete for planar bipartite graphs with maximum degree 4, and testing acyclic 4-colorability is NP-complete for planar bipartite graphs with the maximum degree 8 [13]. c5 c4

c1

c3 c1

(a)

c2

(b)

Fig. 1. (a) A graph G and (b) an acyclic coloring of G using ﬁve colors c1 –c5

Subdividing an edge (u, v) of a graph G is the operation of deleting the edge (u, v) and adding a path u(= w0 ), w1 , w2 , . . . , wk , v(= wk+1 ) through new vertices w1 , w2 , . . . , wk , k ≥ 1, of degree two. A graph G is said to be a subdivision of a graph G if G is obtained from G by subdividing some of the edges of G. A vertex v of G is called an original vertex if v is a vertex of G; otherwise, v is called a division vertex. Wood [15] observed that every graph has a subdivision with two division vertices per edge that is acyclically 3-colorable. Recently Angelini and Frati [2] proved that every plane graph has a subdivision with one division vertex per edge that is acyclically 3-colorable. Main Results : We study acyclic colorings of subdivisions of graphs and prove the following claims. (1) Every cubic graph with n vertices has a subdivision that is acyclically 3colorable, where the number of division vertices is 3n/4. Every triconnected plane cubic graph has a subdivision that is acyclically 3-colorable, where the number of division vertices is at most n/2. Every Hamiltonian cubic graph has a subdivision that is acyclically 3-colorable, where the number of division vertices is at most n/2 + 1. See Section 2. (2) Every partial k-tree, k ≤ 8, has a subdivision with at most one division vertex per edge that is acyclically 3-colorable. See Section 2. (3) Every triangulated plane graph G with n vertices has a subdivision with at most one division vertex per edge that is acyclically 4-colorable, where the total number of division vertices is at most 2n − 6. See Section 3. (4) It is NP-complete to decide whether a graph with degree at most 7 is acyclically 4-colorable or not. See Section 4.

Acyclic Colorings of Graph Subdivisions

2

249

Preliminaries

In this section we present some deﬁnitions and preliminary results that are used throughout the paper. See also [12] for graph theoretic terms. Let G = (V, E) be a connected graph with vertex set V and edge set E. The degree d(v) of a vertex v ∈ V is the number of neighbors of v in G. A subgraph of a graph G = (V, E) is a graph G = (V , E ) such that V ⊆ V and E ⊆ E. If G contains exactly the edges of G that join vertices in V , then G is called the subgraph induced by V . If V = V then G is a spanning subgraph of G. A spanning tree is a spanning subgraph of G that is a tree. The connectivity κ(G) of a graph G is the minimum number of vertices whose removal results in a disconnected graph or a single-vertex graph. G is said to be k-connected if κ(G) ≥ k. Let P = u0 , u1 , u2 , . . . , ul+1 , l ≥ 1, be a path of G such that d(u0 ) ≥ 3, d(u1 ) = d(u2 ) = . . . = d(ul ) = 2, and d(ul+1 ) ≥ 3. Then we call the subpath P = u1 , u2 , . . . , ul of P a chain of G. A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. An ear of a graph G is a maximal path whose internal vertices have degree two in G. An ear decomposition of G is a decomposition P1 , . . . , Pk such that P1 is a cycle and Pi , 2 ≤ i ≤ k, is an ear of P1 ∪ . . . ∪ Pi . Throughout the paper, division vertices are colored gray in all the ﬁgures. We now have the following two facts. Fact 1. Let G be a graph with two distinct vertices u and v and let G be a graph obtained by adding a chain w1 , . . . , wk between the vertices u and v of G. Let G be acyclically 3-colorable such that the colors of u and v are diﬀerent. Then G is acyclically 3-colorable. Proof. In an acyclic coloring of G that colors vertices u and v diﬀerently, let the colors of vertices u and v be c1 and c2 , respectively. For each wi , i = 1, 2, . . . , k, we assign color c3 when i is odd and color c1 when i is even as in Figure 2(a). Clearly, no two adjacent vertices of G have the same color. Therefore, the coloring of G is a valid 3-coloring. Suppose for a contradiction that the coloring of G is not acyclic. Then G must contain a bichromatic cycle C. The cycle C either contains the chain u, w1 , w2 , . . . , wk , v or is a cycle in G. C cannot contain the chain since the three vertices u, v and w1 are assigned three diﬀerent colors c1 , c2 and c3 , respectively. Thus we can assume that C is a cycle in G. Since G does not contain any bichromatic cycle, C cannot be a bichromatic cycle, a contradiction. Fact 2. Let G be a biconnected graph with n vertices and let P1 ∪ . . . ∪ Pk be an ear decomposition of G where each ear Pi , 2 ≤ i ≤ k, contains at least one internal vertex. Then G has a subdivision G , with at most k−1 division vertices, that is acyclically 3-colorable.

250

D. Mondal et al.

Proof. We prove the claim by induction on k. The case k = 1 is trivial since P1 is a cycle, which is acyclically 3-colorable. Therefore we assume that k > 1 and that the claim is true for the graphs P1 ∪ . . . ∪ Pi , 1 ≤ i ≤ k − 1. By induction, G − Pk has a subdivision G that is acyclically 3-colorable and that has at most k − 2 division vertices. Let the end vertices of Pk in G be u and v. If u and v have diﬀerent colors in G then we can prove in a similar way as in the proof of Fact 1 that G has a subdivision G that is acyclically 3-colorable and that has the same number of division vertices as G , which is at most k − 2. Otherwise, u and v have the same color in G . Let the color of u and v be c1 and let the two other colors in G be c2 and c3 . If Pk contains more than one internal vertex then we assign the colors c2 and c3 to the vertices alternately. If Pk contains only one internal vertex v then we subdivide an edge of Pk once. We color v with c2 and the division vertex with c3 as shown in Figure 2(b). In both cases we can prove in a similar way as in the proof of Fact 1 that G has no bichromatic cycle. Moreover, the number of division vertices in G is at most (k−2)+1 = k−1.

w2

w

c1

c3

G u

v c2 G

(a)

c1

c3

wn

w3

c1

c3 w1

u

c1

c3

c2 v

G

c1 c2

G

c2 c3

c3 c2

v

c2

c3

c1

c2

c3

c1

(b)

Fig. 2. Illustration for the proof of (a) Fact 1 and (b) Fact 2

Let G = (V, E) be a 3-connected plane graph and let (v1 , v2 ) be an edge on the outer face of G. Let π = (V1 , V2 , ..., Vl ) be an ordered partition of V . Then we denote by Gk , 1 ≤ k ≤ l, the subgraph of G induced by V1 ∪V2 ∪...∪Vk and by Ck the outer cycle of Gk . We call the vertices of the outer face the outer vertices. An outer chain of Gk is a chain on Ck . We call π a canonical decomposition of G with an edge (v1 , v2 ) on the outer face if the following conditions are satisﬁed [12]. (a) V1 is the set of all vertices on the inner face that contains the edge (v1 , v2 ). Vl is a singleton set containing an outer vertex v, v ∈ {v1 , v2 }. (b) For each index k, 2 ≤ k ≤ l − 1, all vertices in Vk are outer vertices of Gk and the following conditions hold: (1) if |Vk | = 1, then the vertex in Vk has two or more neighbors in Gk−1 and has at least one neighbor in G − Gk ; and (2) If |Vk | > 1, then Vk is an outer chain of Gk . Figure 3 illustrates a canonical decomposition of a 3-connected plane graph. A cubic graph G is a graph such that every vertex of G has degree exactly three. Every cubic graph has an acyclic 4-coloring [14]. We can get an acyclic

Acyclic Colorings of Graph Subdivisions

V

8

4

8

V

2

5

6

7

251

V

3

5

6

7

4 3

3 2

1 (a)

4

V1

2

1 (b)

Fig. 3. (a) A 3-connected plane graph G and (b) a canonical decomposition of G

3-coloring of a subdivision G of G with 3n/4 division vertices from an acyclic 4-coloring of G as follows. Let c4 be the color of the vertices that belong to the smallest color class and let the other colors be c1 , c2 and c3 . We ﬁrst assign to each vertex v with color c4 a diﬀerent color c ∈ {c1 , c2 , c3 }. If all three neighbors of v have diﬀerent colors, we assign any one of the three colors c1 , c2 , c3 to v. Otherwise, we assign v the color that is not assigned to any of its neighbors. We then subdivide each of the three edges incident to v with a vertex u such that u is assigned a color c1 , c2 or c3 , which is not assigned to the end vertices of the edge. It is now straightforward to observe that the resulting subdivision G of G is acyclically colored with 3 colors. Since the number of vertices with color c4 is at most n/4, the number of division vertices in G is at most 3n/4. In the following two lemmas we show two subclasses of cubic graphs for which we can obtain acyclic 3-colorings using smaller number of division vertices. Lemma 1. Let G be a triconnected plane cubic graph with n vertices. Then G has a subdivision G with at most one division vertex per edge that is acyclically 3-colorable and has at most n/2 division vertices. Proof. Let π = {V1 , V2 , . . . , Vk } be a canonical decomposition of G. G1 is a cycle, which can be colored acyclically with three colors c1 , c2 and c3 . Since every vertex of G has degree three, each Vi , 1 < i < k, has exactly two neighbors in Gi−1 . Therefore, Vi corresponds to an ear of Gi and V1 ∪ . . . ∪ Vk−1 corresponds to an ear decomposition of Gk−1 . By Fact 2, Gk−1 has a subdivision Gk−1 that is acyclically 3-colorable with at most k − 2 division vertices. We now add the singleton set Vk to Gk−1 . First, suppose that all the three neighbors of Vk have the same color c1 . Then Vk is assigned color c2 and any two edges incident to Vk are subdivided with division vertices of color c3 as in Figure 4(a). In all other cases, at most one edge incident to Vk is subdivided. Thus any cycle that passes through the vertex Vk uses three diﬀerent colors. Since Gk−1 has at most k − 2 division vertices and the last partition needs at most two division vertices, the total number of division vertices in the subdivision G of G is equal to the

252

D. Mondal et al.

number of partitions in π. Note that the addition of Vk creates two inner faces and the addition of each Vi , 1 < i < k, creates one inner face. Let the number of inner faces of G be F . Then the number of partitions is F − 1 = n/2 by Euler’s formula. Therefore, G has at most n/2 division vertices. Lemma 2. Any Hamiltonian cubic graph G, not necessarily planar, with n vertices has a subdivision G that is acyclically 3-colorable and has n/2 + 1 division vertices. Proof. Let C be a Hamiltonian cycle in G. Since the number of vertices in G is even by the degree-sum formula, we can color the vertices on C with colors c1 and c2 . We next subdivide an edge on C and each of the other edges in G that are not on C to get G . We assign color c3 to all the division vertices. See Figure 4(b).

c2

c3 c1

c1

c3 c2

c2 c1

(a)

c1 c3 c2

c3

c3 c2

c1 c2

c2 c3

Vk

c3

c2 c3

c1

c1

c3

c3 c2

c1

c3

c2

c1 c2

c3 c1

(b)

Fig. 4. Illustration for the proof of (a) Lemma 1 and (b) Lemma 2

Each cycle C in G corresponds to a unique cycle C in G that contains only the original vertices of C . If C in G corresponds to the Hamiltonian cycle C in G, then C is not bichromatic. Since every vertex in G has degree at most 3, no cycle can be formed with only edges that are not on C in G. Let C be a cycle in G that corresponds to a cycle C in G where C = C. Then C must contain at least one edge e on C and one edge e not on C. According to the coloring of G , the end vertices of e in G must have diﬀerent colors c1 , c2 and the division vertex on the edge e has the remaining color c3 . Therefore G does not contain any bichromatic cycle. The total number of edges in G is 3n/2. We have subdivided all the edges of G other than (n − 1) edges on C. As a result, the total number of division vertices in G is 3n/2 − (n − 1) = n/2 + 1. A graph G with n vertices is a k-tree if G satisﬁes the following (a)-(b). (a) If n = k, then G is the complete graph with k vertices. (b) If n > k, then G can be constructed from a k-tree G with n − 1 vertices by adding a new vertex to exactly k vertices of G , where the induced graph of these k-vertices is a complete graph.

Acyclic Colorings of Graph Subdivisions

253

Let G be a k-tree with vertex set V . Then by deﬁnition, there is an ordered partition π = (V1 , V2 , ..., Vm ) of V that satisﬁes the following: (a) V1 contains k vertices inducing a complete graph. (b) Let Gk , 1 ≤ k ≤ m, be the subgraph of G induced by V1 ∪ V2 ∪ ... ∪ Vk . Then Gk , k > 1, is a k-tree obtained by adding Vk to Gk−1 , where Vk is a singleton set and its neighbors in Gk−1 form a k-clique. A partial k-tree is a subgraph of a k-tree. It is straightforward to observe that k-trees are acyclically (k + 1)-colorable. Lemma 3. For k ≤ 8, every partial k-tree G with n vertices has a subdivision G with at most one division vertex per edge that is acyclically 3-colorable. Proof. For n ≤ 3, G is itself acyclically 3-colorable. We thus assume that n > 3 and that all partial k-trees with less than n vertices have a subdivision with at most one division vertex per edge that is acyclically 3-colorable. Let G be a partial k-tree obtained from a k-tree K. Let π = (V1 , V2 , ..., Vm ) be an ordered partition of the vertex set of K and let π = (V1 , V2 , ..., Vm ) be an ordered partition of the vertex set of G, where V1 ⊆ V1 and V2 , ..., Vm is a subsequence of V2 , ..., Vm . Now we add Vm to Gm −1 to obtain G. By induction Gm −1 has a subdivision Gm −1 that is acyclically 3-colorable, where the number of division vertices per edge of Gm −1 is at most one. Let Vm = v. By deﬁnition of k-tree, v is connected to at most k original vertices of Gm −1 . However, the neighbors of v may not induce a complete graph since G is a partial k-tree. Let G be the graph obtained by adding v to Gm −1 . Then G is a subdivision of G. To get G from G , we consider the following three cases. Case 1 : The neighbors of v in G have the same color c1 . Assign color c2 to v and subdivide each edge (v, u), where u is a neighbor of v. Finally, assign color c3 to all these new division vertices. See Figure 5(a). Thus any cycle that passes through v uses three diﬀerent colors. Case 2 : The neighbors of v in G have color c1 and c2 . Then assign color c3 to v. For each neighbor u of v, if u has color c1 , subdivide the edge (v, u) and assign color c2 to the division vertex. Similarly, for each neighbor u of v, if u has color c2 , subdivide the edge (v, u) and assign color c1 to the division vertex as in Figure 5(b). So any cycle that passes through v, uses three diﬀerent colors. Case 3 : The neighbors of v have all three colors c1 , c2 and c3 . Since k ≤ 8 there is at least one color assigned to less than or equal to two neighbors of v. Let the color be c3 . Assign color c3 to v. If only one neighbor u1 of v has color c3 , subdivide edge (v, u1 ) and assign color c1 to the division vertex. If two neighbors u1 , u2 of v have color c3 , subdivide each of the edges (v, u1 ) and (v, u2 ) once. Then assign color c1 to the division vertex of edge (u, v1 ) and color c2 to the division vertex of edge (u, v2 ). For each neighbor u ∈ {u1 , u2 } of v, if u has color c1 , then subdivide the edge (v, u) and assign color c2 to the division vertex. Similarly, for each neighbor u of v, if u has color c2 , then subdivide the edge (v, u) and assign color c1 to the division vertex. See Figure 5(c). Note that any cycle that passes through v but does not contain both u1 or u2 , must have three

254

D. Mondal et al.

diﬀerent colors. Any cycle that passes through v, u1 and u2 has color c3 on v and colors c1 , c2 on the two division vertices on the edges (v, u1 ), (v, u2 ). In all the three cases above, any cycle that passes through vertex v is not a bichromatic cycle. All the other cycles are cycles of Gm −1 , thus are not bichromatic. Thus the computed coloring in each of Cases 1–3 is an acyclic 3-coloring of a subdivision G of G. By construction, the number of division vertices on each edge of G is at most one. c2

c3

v

c c3 c3 c3 3 c3 c3 c3

c3 c2

c c1 c1 c c c c1 c1 1 1 1 1

(a)

v

c3

v

c2 c2 c c2 c1 c1 c2 1 c c1 c1 c c c2 c1 c1 2

c2 c2 c 2 c1 c1 c2 c1 c1 c c1 c1 c c c2 c2 c3 3 1

(b)

(c)

2

1

Fig. 5. Illustration for the proof of Lemma 3

2

An independent set S of G is a set of vertices in G, where no two vertices in S are adjacent in G. The following lemma is of independent interest. Lemma 4. Let S be an independent set of a graph G. If G − S is acyclic then G is acyclically 3-colorable. Proof. If G − S is acyclic then G − S is a tree or a forest and hence, it is 2– colorable. Color the vertices of G − S with colors c1 and c2 . Add the vertices of S to G − S and assign the vertices color c3 . Since S is an independent set, a cycle in G contains at least one edge (u1 , u2 ) from G − S and at least one vertex u3 from S. Since, by the coloring method given above, u1 , u2 and u3 have diﬀerent colors, there is no bichromatic cycle in G.

3

Acyclic Coloring of Plane Graphs

In this section we prove our results for acyclic 3 and 4-colorability of plane graph subdivisions. We ﬁrst introduce “canonical ordering” of triangulated plane graphs. Let G be a triangulated plane graph on n ≥ 3 vertices. We denote by C0 (G) the outer cycle of G. Let the three vertices on C0 (G) be v1 , v2 and vn in counterclockwise order. Let π = (v1 , v2 , . . . , vn ) be an ordering of all vertices in G. For each integer k, 3 ≤ k ≤ n, we denote by Gk the plane subgraph of G induced by the k vertices v1 , v2 , . . . , vk . We call π a canonical ordering of G with respect to the outer edge (v1 , v2 ) if it satisﬁes the following conditions [12]:

Acyclic Colorings of Graph Subdivisions

255

(a) Gk is 2-connected and internally triangulated for each k, 3 ≤ k ≤ n. (b) If k + 1 ≤ n, then the vertex vk+1 is located on the outer face of Gk , and all neighbors of vk+1 in Gk appear on C0 (Gk ) consecutively. Observe that the vertex partition obtained by a canonical decomposition of a triangulated plane graph G determines a vertex ordering, which corresponds to a canonical ordering of G. Let E ∗ be the set of edges that do not belong to any C0 (Gk ), 3 ≤ k ≤ n. We call these edges the internal edges of G because they never appear on the outer face of any Gk . We call all the other edges of G, the external edges. Let V ∗ = V − {v1 , v2 } and let G∗ = (V ∗ , E ∗ ). Now we prove that G∗ is a tree. Lemma 5. For any triangulated plane graph G with a canonical ordering π = (v1 , v2 , . . . , vn ), the subgraph G∗ = (V ∗ , E ∗ ) is a tree. Proof. We prove that G∗ is a tree by ﬁrst showing that G∗ is connected and then showing that |E ∗ | = |V ∗ | − 1. To show that G∗ is connected, we show that each internal node vk , 3 ≤ k ≤ n, has a path to vn in G∗ . For a contradiction, let k be the maximum index such that vk , k < n, does not have such a path to vn . Since vk ∈ C0 (Gk ) but vk ∈ / C0 (G), there exists an integer l, k < l ≤ n, such that vk ∈ C0 (Gl−1 ) but vk ∈ / C0 (Gl ). Hence by property (b) of π, (vk , vl ) must be an internal edge in G. Since l > k, by assumption there must be a path from vl to vn in G∗ . Therefore vk has a path to vn in G∗ which is a contradiction. Each vk , 3 ≤ k ≤ n, is connected to Gk−1 by exactly two external edges. Since (v1 , v2 ) is also an external edge, the number of external edges in G is 2(n − 2) + 1 = 2n − 3. By Euler’s formula, G has 3n − 6 edges in total. Therefore, |E ∗ | = 3n − 6 − (2n − 3) = n − 3 = |V ∗ | − 1. Therefore, G∗ is a tree. We use Lemma 5 to prove the following theorem on acyclic 3-colorability of subdivisions of triangulated plane graphs. This theorem is originally proved by Angelini and Frati [2]. However, our proof is simpler and relates acyclic coloring of graph subdivisions with canonical ordering, which is an important tool for developing graph algorithms. Theorem 1. Any triangulated plane graph G has a subdivision G with one division vertex per edge that is acyclically 3-colorable. Proof. Let G = (V, E) be a triangulated plane graph and let π = (v1 , v2 , ..., vn ) be a canonical ordering of G. Let E be the set of external edges and let E ∗ = E − E be the set of internal edges of G. Let Gs = (V, E ). We now compute a subdivision Gs of Gs and color Gs acyclically with three colors as follows. We assign colors c1 , c2 and c3 to the vertices v1 , v2 and v3 , respectively. For 3 ≤ k ≤ n, as we traverse C0 (Gk ) in clockwise order starting at v1 and ending at v2 , let lvk be the ﬁrst neighbor of vk encountered and let rvk be the other neighbor of vk on C0 (Gk ). Then assign vk a color other than the colors of lvk and rvk .

256

D. Mondal et al.

We now subdivide each edge in E with one division vertex to get Gs . Finally, we assign each division vertex a color other than the colors of its two neighbors. It is easy to see that every edge in Gs along with its division vertex uses three diﬀerent colors. Therefore, the resulting coloring of Gs is an acyclic 3-coloring. We now add the edges of E ∗ to Gs and subdivide each of these edges with one division vertex to obtain G . We assign each new division vertex a color other than the colors of its two neighbors. By Lemma 5, E ∗ is the edge set of a tree. Therefore, any cycle in G must contain an edge from E . Consequently, the cycle must use three diﬀerent colors. Figure 6(a) shows an example of G , where the edges of E are shown by solid lines and the edges of E ∗ are shown by dashed lines. We now extend the technique used in the proof of Theorem 1 to obtain the following theorem on acyclic 4-colorability of triangulated plane graphs. Theorem 2. Any triangulated plane graph G has a subdivision G with at most one division vertex per edge that is acyclically 4-colorable, where the number of division vertices in G is at most 2n − 6. Proof. We deﬁne π and Gs as in the proof of Theorem 1. We ﬁrst compute a subdivision Gs of Gs and color Gs acyclically with three colors as follows. We assign colors c1 , c2 and c3 to the vertices v1 , v2 and v3 , respectively. For 3 ≤ k ≤ n, as we traverse C0 (Gk ) in clockwise order starting at v1 , let lvk be the ﬁrst neighbor of vk encountered and let rvk be the other neighbor of vk on C0 (Gk ). Then for each vertex vk we consider the following two cases. Case 1: The colors of lvk and rvk are the same. In this case we assign vk a color other than the color of lvk and rvk . Then we subdivide edge (vk , rvk ) with one division vertex and assign the division vertex a color other than the colors of its two neighbors. Case 2: The colors of lvk and rvk are diﬀerent. In this case we assign vk a color other than the color of lvk and rvk and do not subdivide any edge. At each addition of vk , Cases 1 and 2 ensure that any cycle passing through vk has three diﬀerent colors. Hence, the resulting subdivision is the required Gs and the computed coloring of Gs is an acyclic 3-coloring. We now add the edges of E ∗ to Gs and subdivide each of these edges with one division vertex to obtain G . We assign each new division vertex the fourth color. Any cycle that does not contain any internal edge is contained in Gs and hence, uses three diﬀerent colors. On the other hand, any cycle that contains an internal edge must use the fourth color and two other colors from the original vertices on the cycle. Therefore, the computed coloring of G is an acyclic 4coloring. Figure 6(b) shows an example of G . We have not subdivided any edges between the vertices v1 , v2 and v3 . Moreover, for each vk , we subdivided exactly one external edge. Therefore the number of division vertices is at most (3n − 6) − (n − 3) − 3 = 2n − 6. Observe that canonical ordering and Schnyder’s realizer of a triangulated plane graph are equivalent notions [11]. Using the fact that G∗ = (V ∗ , E ∗ ) is a tree of Schnyder’s realizer [5], one can obtain alternate proofs for Theorems 1 and 2.

Acyclic Colorings of Graph Subdivisions c3 c2

c2

v6

c2

c3

c2 c2 c3

v1

c1

c1

v4

c2

c2

v5

c3 c1

c3

vn =v8

c2

v7

c3

v3

c1

c2

c1

v6

c1

c3

c3

c2

v4

c2

c3 c1

c3

(a)

vn=v8

v7

c1

c2

257

c3

v2

c2

v1

v c1 5 c3

v3

v2

c2

c1

(b)

Fig. 6. Illustration for the proof of (a) Theorem 1 and (b) Theorem 2

4

NP-Completeness

In this section we prove that it is NP-complete to decide whether a graph with maximum degree 7 has an acyclic 4-coloring or not. We denote the problem by Acyclic 4-Color Max-deg 7. The equivalent decision problem is given below. Instance: A graph G with maximum degree 7. Question: Can the vertices of G be acyclically colored with 4 colors? Theorem 3. Acyclic 4-Color Max-deg 7 is NP-complete. Proof. The problem is in NP. If a valid 4-coloring of the vertices of G is given, we can check in polynomial time whether that is an acyclic coloring or not. We consider each pair of colors and the subgraph induced by the vertices of those two colors. We check whether that subgraph contains a cycle. If none of the 42 subgraphs contains any cycles, the 4-coloring is an acyclic coloring. We will prove the NP-hardness by reducing the problem of deciding acyclic 3colorability of plane graphs with maximum degree 4 to our problem. The problem of acyclic 3-colorability, which was proved to be NP-complete by Angelini and Frati [2], is given below. Instance: A plane graph H with maximum degree 4. Question: Can the vertices of H be acyclically colored with 3 colors? Let H be an instance of the problem of deciding acyclic 3-colorability of plane graphs with maximum degree 4, as in Figure 7. Let p be the number of vertices in H. Then we construct a plane 3-tree G4p of 4p vertices as in Figure 7 as follows. We ﬁrst take a triangle with vertices v1 , v2 and v3 . Next we take a vertex v4 in the inner face of the triangle and connect v4 to v1 , v2 and v3 to get G4 . In any valid coloring of G4 , v1 , v2 , v3 and v4 must be assigned four diﬀerent colors and hence the coloring is acyclic. Let the colors assigned to v1 , v2 , v3 and v4 be c1 , c2 , c3 and c4 , respectively. Now we place a new vertex v5 inside the face

258

D. Mondal et al.

bounded by the triangle v2 , v3 , v4 and connect v5 with the three vertices on the face to get G5 . It is obvious that G5 is 4–colorable and v5 must be assigned the same color as v1 in a 4-coloring of G5 . In this recursive way, we construct the graph G4p with 4p vertices, where each inner vertex of G4p has degree exactly six. In any valid 4-coloring of G4p , each of the four colors is assigned to exactly p vertices. We now prove that any valid 4-coloring of a plane 3-tree Gn with n vertices is an acyclic coloring. The proof is by induction on n. When n ≤ 4, any 4coloring of G3 is an acyclic coloring. We thus assume that n > 4 and that any valid 4-coloring of a plane 3-tree with less than n vertices is an acyclic coloring. By deﬁnition of plane 3-tree, Gn has a vertex v of degree three. We remove v from Gn to get another plane 3-tree Gn−1 with n − 1 vertices. By the induction hypothesis, any 4-coloring of Gn−1 is an acyclic coloring. We now add v to Gn−1 to get Gn . By construction of plane 3-trees, v must be placed in a face of Gn−1 and must be connected to the three vertices on the face. Let the colors assigned to three neighbors of v be c1 , c2 and c3 . Then v is assigned color c4 . Now, any cycle that goes through v must also go through at least two of the neighbors of v. Hence any cycle containing v contains vertices of at least three colors. Therefore, Gn has no bichromatic cycle.

v3 c

G

3

G4p

c1

v5

c2

c2

c1 c3 c2

c3

c2

v1 c v 4 1

c1

H

c3

c3 c1

c1

c3 c2

c2

c3

v2

Fig. 7. Illustration for the proof of Theorem 3

Let S be the set of the vertices of G4p that are assigned color c4 in a 4-coloring when the outer vertices use the colors c1 , c2 , c3 . We connect each vertex of H to exactly one vertex of S as illustrated in Figure 7, so that the edges connecting vertices of H and G4p form a matching. Let the resulting graph be G. It is easy to see that the degree of each vertex of G is at most seven. We argue that G has an acyclic 4-coloring if and only if H has an acyclic 3-coloring. First we assume that G admits an acyclic 4-coloring. Let the colors assigned to the vertices of G be c1 , c2 , c3 and c4 . Let the colors assigned to the outer vertices of G4p be c1 , c2 and c3 . Then each vertex in S has color c4 and hence no

Acyclic Colorings of Graph Subdivisions

259

vertex in H receives color c4 . Therefore, the vertices of H are acyclically colored with three colors c1 , c2 and c3 . We now assume that H has an acyclic 3-coloring where the colors assigned to the vertices of H are c1 , c2 and c3 . We assign the three colors to the three outer vertices v1 , v2 and v3 of G4p . Clearly the common neighbor v4 of the three outer vertices must be assigned a fourth color c4 . In the same way, all the vertices of S get the color c4 . Suppose for a contradiction that G contains a bichromatic cycle C. C cannot be a cycle of H. Since any 4-coloring of G4p is acyclic, C cannot be a cycle of G4p . Therefore, C must contain vertices from both G4p and H. Since the edges connecting G4p and H form a matching, no two vertices of G4p have the same neighbor in H. Therefore, C must contain at least one edge e of H. The end vertices of e have two of the three colors c1 , c2 , c3 . Since C must contain a vertex in G4p with color c4 , C contains vertices of at least three colors and hence cannot be a bichromatic cycle. Therefore, the 4-coloring of G described above is acyclic.

5

Open Problems

Acyclic colorings of plane graph subdivisions with fewer division vertices will be an interesting direction to explore. We ask the following question: What the minimum positive constant c such that every triangulated planar graph with n vertices has an acyclic k-coloring, k ∈ {3, 4}, with at most cn division vertices? Every cubic graph is acyclically 4-colorable [14]. On the other hand, we have proved that testing acyclic 4-colorability is NP-complete for graphs with the maximum degree 7. The problem of obtaining acyclic 4-colorings for graphs with maximum degree greater than three and less than seven remains open, as does using our results to improve volume bounds on 3-dimensional polyline grid drawings.

References 1. Albertson, M.O., Berman, D.M.: Every planar graph has an acyclic 7-coloring. Israel Journal of Mathematics 28(1-2), 169–174 (1977) 2. Angelini, P., Frati, F.: Acyclically 3-colorable planar graphs. In: Rahman, M. S., Fujita, S. (eds.) WALCOM 2010. LNCS, vol. 5942, pp. 113–124. Springer, Heidelberg (2010) 3. Borodin, O.V.: On acyclic colorings of planar graphs. Discrete Mathematics 306(1011), 953–972 (2006) 4. Coleman, T.F., Cai, J.: The cyclic coloring problem and estimation of sparse hessian matrices. SIAM Journal on Algebraic and Discrete Methods 7(2), 221–235 (1986) 5. Dhandapani, R.: Greedy drawings of triangulations. Discrete & Computational Geometry 43(2), 375–392 (2010) 6. Dujmovi´c, V., Morin, P., Wood, D.R.: Layout of graphs with bounded tree-width. SIAM Journal of Computing 34, 553–579 (2005)

260

D. Mondal et al.

7. Gebremedhin, A.H., Tarafdar, A., Pothen, A., Walther, A.: Eﬃcient computation of sparse hessians using coloring and automatic diﬀerentiation. INFORMS Journal on Computing 21, 209–223 (2009) 8. Gr¨ unbaum, B.: Acyclic colorings of planar graphs. Israel Journal of Mathematics 14(4), 390–408 (1973) 9. Kostochka, A.V.: Acyclic 6-coloring of planar graphs. Diskretn. Anal. 28, 40–56 (1976) 10. Mitchem, J.: Every planar graph has an acyclic 8-coloring. Duke Mathematical Journal 41(1), 177–181 (1974) 11. Miura, K., Azuma, M., Nishizeki, T.: Canonical decomposition, realizer, Schnyder labeling and orderly spanning trees of plane graphs. International Journal of Foundations of Computer Science 16(1), 117–141 (2005) 12. Nishizeki, T., Rahman, M.S.: Planar Graph Drawing. World Scientiﬁc (2004) 13. Ochem, P.: Negative results on acyclic improper colorings. In: European Conference on Combinatorics (EuroComb 2005), pp. 357–362 (2005) 14. Skulrattanakulchai, S.: Acyclic colorings of subcubic graphs. Information Processing Letters 92(4), 161–167 (2004) 15. Wood, D.R.: Acyclic, star and oriented colourings of graph subdivisions. Discrete Mathematics & Theoretical Computer Science 7(1), 37–50 (2005)

Kinetic Euclidean Minimum Spanning Tree in the Plane Zahed Rahmati and Alireza Zarei Department of Mathematical Sciences, Sharif University of Technology, Tehran, Iran {rahmati@alum.,zarei@}sharif.edu

Abstract. This paper presents the ﬁrst kinetic data structure (KDS) for maintenance of the Euclidean minimum spanning tree (EMST) on a set of n moving points in 2-dimensional space. We build a KDS of size O(n) in O(n log n) preprocessing time by which their EMST is maintained eﬃciently during the motion. In terms of the KDS performance parameters, our KDS is responsive, local, and compact. Keywords: computational geometry; Euclidean minimum spanning tree; kinetic data structures.

1

Introduction

Problem statement. For a weighted graph G(V, E), a minimum spanning tree of G is a connected sub-graph G (V, E ) of G where the sum of the weights of its edges is the minimum possible. For a set P = {p1 , p2 , . . . , pn } of n points, there is a complete weighted graph with P as its nodes. The weight of each edge of this graph is the Euclidean distance between its two endpoints. A minimum spanning tree of this graph is known as the Euclidean minimum spanning tree (EMST) of the underlying points. The EMST has many applications in solving geometric and graph problems and has been studied extensively. Some of which are described below. In this paper, we consider the kinetic version of the EMST problem in the plane. This problem was ﬁrst posed by Basch et al. [4] and has been open since 1997. In this setting, the points are moving independently in the plane and the goal is to maintain the combinatorial structure of their EMST during the motion. We assume that the position of a point pi at time t, denoted by pi (t) = (xi (t), yi (t)), is deﬁned by two algebraic functions (for x and y coordinates) of constant maximum degree (in terms of time). Moreover, we assume that the points move without collision, i.e. ∀i=j ∀t∈R pi (t) = pj (t). This assumption is required by the kinetic Delaunay triangulation algorithm on which our solution is built. Related work. Whereas EMST is a special version of the minimum spanning tree problem, we can use any of the classic minimum spanning tree algorithms to solve the EMST problem. Therefore, the EMST can be obtained in O(E+n log n) C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 261–274, 2011. c Springer-Verlag Berlin Heidelberg 2011

262

Z. Rahmati and A. Zarei

time using the Prim’s algorithm [14] or in time O(E log E) using the Kruskal’s algorithm [12] where E = O(n2 ) is the number of the edges in the complete graph over the n points. Based on the geometric properties of the EMST, this problem can be solved in optimal O(n log n) time in the plane [7]. A good method for computing the EMST in the plane obtained just after the Delaunay triangulation (DT) problem was solved in O(n log n) time [6,11]. The edges of the EMST of points P are a subset of the edges of their DT and the number of the edges of the DT is O(n) which result a O(n log n) time algorithm for the EMST problem using the Prim or Kruskal algorithms. Afterward, the dynamic and kinetic versions of this problem were investigated where respectively, point insertion/deletion and point movement are allowed. Eppstein [8] proposed an algorithm that maintains the EMST of a set of points in the plane allowing point insertion and deletion (the dynamic ver1 sion). This algorithm requires O(n 2 log2 n) amortized time per update (point insertion/deletion). The ﬁrst algorithm for the kinetic situation was proposed by Fu and Lee [9]. Their algorithm requires O(kn4 log n) preprocessing time and O(m) space where k is the maximum degree of the algebraic functions deﬁning the points motion and m is the maximum number of the changes of the EMST from time t = 0 to t = ∞. Then, the EMST of the points at any given time can be constructed in query time O(n). For the restricted version of the kinetic EMST problem, in which the distances between each pair of points are deﬁned by linear functions of time, Agarwal et al. [1] proposed an algorithm that runs 3 1 in time O(n 2 log 2 n) per combinatorial change of the EMST. They propose this algorithm for maintaining the minimum spanning tree of a general graph where the edge weights are linear functions of time and supports edge insertion and deletion as well. The kinetic data structure framework. The kinetic data structure (KDS) framework was initially introduced by Basch et al. [3]. In this framework, a set of certiﬁcates is deﬁned to maintain a special attribute of a set of moving objects. Validity of these certiﬁcates implies the correctness of the goal attribute. Whenever a certiﬁcate fails, it means that the computed value of the attribute must be updated and the new set of certiﬁcates must be built. Therefore, it is enough to compute the failure time of these certiﬁcates, called events, and put them in an event queue. The most important part of this framework is a set of criteria that determines the performance of a KDS. The performance of a KDS is measured according to the following four criteria [2,3]: • Responsiveness: The response time of a KDS is the processing time of an event spent by the repair mechanism. If the response time is a polylogarithmic function of the number of the moving objects, the KDS is responsive. • Compactness: The size of a KDS is deﬁned by the space used by its data structures and certiﬁcates. A KDS is called compact if its size is within a polylogarithmic factor of linear in the total number of the moving objects. • Locality: The locality of a KDS is deﬁned by the maximum number of events associated with one particular object, at any ﬁxed time. A KDS is

Kinetic Euclidean Minimum Spanning Tree

263

called local if this number is always a polylogarithmic function of the total number of the moving objects. • Eﬃciency: The eﬃciency of a KDS deals with the number of events processed during the motion. Not every event (certiﬁcate failure) of a KDS necessarily implies a change in the attribute being maintained. Processing an event may produce only internal changes to the data structures while the desired attribute is still valid. These events are called internal events. An event that produces a change in the target attribute is called an external event. The eﬃciency of a KDS is deﬁned as the ratio between the total number of the internal events and the total number of the external events (enumerated from time t = 0 to t = ∞). A KDS is called eﬃcient if this ratio is polylogarithmic in the number of the moving objects. Our Results. To the best of our knowledge there is no algorithm for solving the exact EMST problem in general kinetic settings satisfying the KDS performance metrics. This was our motivation in considering this problem. It is known that the edges of the EMST of a set of points are a subset of the edges of their Delaunay triangulation (DT). Using this fact, we use the KDS proposed by Guibas et al. [10] for tracking changes of the DT. As soon as a DT change happens the necessary updates are applied on the EMST. Moreover, if the ordering of the edge-lengths of two edges of the DT is changed, it may produce a change in the EMST. One can maintain the edges of the DT in a sorted list and whenever the ordering of two edges in this list is changed, apply the required changes to the EMST. Our contribution in this paper is to do this while satisfying some of the performance criteria of the KDS framework. Besides one instance of the KDS proposed by Guibas et al. [10] for maintaining the DT, we build a set of data structures of total size O(n) in O(n log n) preprocessing time by which a certiﬁcate failure (event) is handled in O(log2 n) time. According to the KDS performance metrics, our KDS is responsive, local in expectation and compact.

2

Certificates and Events

As mentioned in the introduction, our approach is based on the fact that the edges of the EMST of a set of points is a subset of the edges of their Delaunay triangulation. On the other hand, the minimum spanning tree of a graph depends on the orderings of its edge weights. Therefore, we need to track two types of changes to correctly update and maintain the EMST of a set of moving points: 1. Changes in the order of each pair of consecutive edges in the sorted list (according to the edge’s length) of the Delaunay triangulation edges of the points. 2. Changes in the Delaunay triangulation of the points which causes an edge removal from or an edge insertion into the potential edges of the EMST.

264

Z. Rahmati and A. Zarei

Let E(DT) and E(EMST) be respectively the set of edges of the Delaunay triangulation and the edges of the EMST of a set of moving points P in the plane and let path(pi , pj ) be the simple path between pi and pj in the EM ST . The ﬁrst change type corresponds to a pair of edges e and e in E(DT) such that (for small enough value of ) • at time t − the Euclidean length of e is smaller than that of e , and • at time t + the Euclidean length of e is greater than that of e . Then, e may be replaced by e in E(EMST) at time t. Such a change is called an order event with parameters e, e and t. It is simple to prove the following lemma about the order-events: Lemma 1. An order-event of parameters e, e and t changes the EM ST if and only if at time t − we have e ∈ E(EMST), e ∈ / E(EMST) and e ∈ path(pi , pj ) where pi and pj are the end points of e . We call such order-events eﬀective order-events. The second change type means that there is a pair of edges e and e such that (for small enough value of ) • at time t − we have e ∈ E(DT) and e ∈ / E(DT), • at time t the four endpoints of e and e lie on a circle, and • at time t + we have e ∈ / E(DT) and e ∈ E(DT). Then, e may appear in E(EMST) at some time t > t. Such a change is called a DT-event with parameters e, e and t. If we add the points of a suﬃciently large bounding box of the points to the set of input points, the convex hull of the points is always this box and DT-events do not aﬀect it. Having this bounding box, we prove that a DT-event does not directly aﬀect the EMST. Lemma 2. For any DT-event of parameters e, e and t there is an arbitrarily small value of such that neither e nor e exist in E(EMST) at times t − and t + . Proof. We prove this lemma by showing that exactly at time t and before removing e from the Delaunay triangulation e ∈ / E(EMST) and exactly at time t and after adding e to the Delaunay triangulation e ∈ / E(EMST). Any DT-event has a conﬁguration shown in Figure 1 where four points lie on a circle. In this ﬁgure e = p2 p4 and e = p1 p3 . Assume that p1 is the point on the opposite side of e relative to the center of this circle (if e is a diameter of this circle then there is no distinction between the points p1 and p3 in this proof). Then, |p1 p2 | < |e| and |p1 p4 | < |e|. We prove by contradiction that e ∈ / E(EMST) at time t − . If e ∈ E(EMST), at most one of the edges p1 p2 and p1 p4 can be a member of E(EMST). Without loss of generality, assume that p1 p2 ∈ / E(EMST). Then, either e ∈ path(p1 , p2 ) which we can obtain a smaller EMST by using p1 p2 instead of e, or e ∈ / path(p1 , p2 ) which means that p1 p4 ∈ / E(EMST) and e ∈ path(p1 , p4 ) and therefore, we can obtain a smaller EMST by using p1 p4 instead of e. In both cases we have the contradiction that e ∈ / E(EMST) at time t − . By the same argument we can prove that e does not exist in the EMST at time t + .

Kinetic Euclidean Minimum Spanning Tree

265

According to Lemmas 1 and 2, the actual set of certiﬁcates that may aﬀect our goal attribute (the EMST) is the set of O(n) certiﬁcates that deﬁnes the order of the weights of E(DT); see Theorem 1 Theorem 1. The EM ST of a set of moving points is changed if and only if an eﬀective order-event happens. Using this theorem, we can maintain the sorted list of the edges of the Delaunay triangulation and whenever the ordering of a pair of consecutive edges is changed we must check to see whether it deﬁnes an eﬀective order-event. If so, the required changes are applied to the EMST. Doing this naively, each event can be processed in O(n) time which is not responsive in terms of the KDS metrics. In the next sections, we describe how these p certiﬁcates are handled to maintain a responp sive, local, and compact EMST during the e e motion. p However, we need to track and process DTp events to have the correct value of E(DT) that is necessary to have the correct set of the order-event certiﬁcates. We employ the method proposed by Guibas et al. [10] to de- Fig. 1. The EMST of a set of tect the DT-events. In this method, after pre- points does not contain the degenprocessing requiring O(n log n) time and O(n) erate edges of the Delaunay trianspace, the Voronoi diagram of a set of moving gulation points can be maintained by processing the required events. Any event is processed in O(log n) time and the total number of processed events from t = 0 to t = ∞ is O(n2 λs (n)) where λs (n) is the maximum length of a DavenportSchinzel sequence of length n and order s. Thereby, s = 4q where q is the maximum degree of the polynomial curves deﬁning the points motion. 1

4

2

3

3

Building the Kinetic Data Structure

Besides the data structures and algorithms proposed by Guibas et al. [10] which triggering the DT-events, our KDS contains three parts: • The DT Edges and Certiﬁcates: We store the Euclidean lengths of E(DT) in a balanced binary search tree, T (DT), and for each pair of consecutive nodes of this tree we compute the closest time at which the order of these nodes is changed. These times are put in a priority queue Q(DT). The root of Q(DT) contains the closest time at which the order of the lengths of two edges of E(DT) is changed. Moreover, we make links between the Delaunay triangulation edges and their length entries in T (DT) and Q(DT) for removal purposes. • The EMST Planar Structure: Assume that SD is the subdivision produced from the overlay of the convex hull of the points (which is the added bounding box) and their EMST. This part of our KDS is a variation of the

266

Z. Rahmati and A. Zarei

DCEL data structure [5] that maintains the status of SD and has three structures for vertices, edges and faces which are respectively denoted by V, E and F . For each point pi ∈ P , there is an entry V(pi ) that points to the root of a search tree in which the edges of SD that are adjacent to pi are sorted according to their radial order around pi . For each edge ei in SD there is an entry in E that points to the two directed half-edges of ei in its both sides. The direction of these half-edges are such that their adjacent faces lie to their left. Moreover, each half-edge have a pointer to its occurrence in F to be deﬁned as follows. For each face fi of SD there is an entry F (fi ) that points to the root of a search tree in which the half-edges of the boundary of fi are sorted according to their order on this boundary. To be precise, each F (fi ) is a balanced binary search tree that supports merge and split operations eﬃciently as well as search, insert and delete in O(log n) time [15]. we denote these trees by MS-BBST. Moreover, we assign the maximum ordering values to the bounding half-edges of a face fi that are not member of the EMST (these half-edges belongs to the convex hull). This convention makes our next discussions easier. Figure 2 sketches a typical conﬁguration of these structures. p1

p3 p2

F (f1 ) − p−→ p 5 6

− → p− 3 p4

f1 p4 p6

p5

→ p−− 2 p3 − − → p1 p2

− → p− 5 p7 → −−→ −−→ p−− 4 p5 p6 p5 p7 p1

→ −−→ p− E(p1 p2 ) = (− 1 p2 , p2 p1 ) p7

V(p5 ) p5 p 6 p4 p5

p5 p7

Fig. 2. A typical conﬁguration of the V, E and F structures

• The Relation between E(DT) and E(EMST): The last part of our KDS exhibits relations between edges of the current EMST and its future potential edges which are those edges of DT that are not members of the current EMST. In other words, during the motion some edges of E(DT) − E(EMST) may be inserted into the EMST. We describe next, how these updates are handled by our KDS. For each edge pi pj ∈ E(DT) − E(EMST) there is a simple path path(pi , pj ) in the EMST that connects pi and pj . Assume that ps pt has the maximum Euclidean length among edges of path(pi , pj ). Then, |pi pj | > |ps pt | and if |pi pj | gets to decrease while the points are moving it will be added to the EMST just after the moment that its length reaches |ps pt | (we assume that ps pt has still the maximum Euclidean length among edges of path(pi , pj )). For such situations we say that pi pj is a potential candidate for ps pt . In other words, it is possible to have an eﬀective order-event of parameters ps pt , pi pj and t for any potential candidate edge pi pj of ps pt .

Kinetic Euclidean Minimum Spanning Tree

267

In this part of our KDS, we store the set of all potential candidates of each edge ps pt ∈ E(EMST) and ps pt itself in a MS-BBST. In the MS-BBST of an edge ps pt denoted by PK(ps pt ), the ordering of the nodes are according to their distance from the edge ps pt to be deﬁned later. Now, we describe how these data structures are initially constructed and analyze their complexities. Lemma 3. For a set of n points, their T (DT) and Q(DT) can be constructed in O(n log n) time and the size of these structures is O(n). Proof. We can compute the Delaunay triangulation in O(n log n) time. We know that |E(DT)| = O(n). Then, the lengths of these edges are computed in O(n) time and they are inserted in a balanced binary search tree T (DT) in O(n log n) time. Finally, for each consecutive pair of nodes in T (DT) we compute the time at which this ordering changes and put this event time into a priority queue Q(DT). The size of this queue is also O(n) and can be constructed in O(n log n) time. Lemma 4. For a set of n points, the V, E and F data structures can be constructed in O(n log n) time and their total size is O(n). Proof. After computing the Delaunay triangulation, the EMST and the convex hull of the points, the overlay SD can be constructed in O(n) time and the subdivision can be obtained as a standard DCEL data structure [5]. Having this DCEL, the V, E and F data structures is constructed in a linear trace on this DCEL in O(n log n) time. The size of the subdivision SD is O(n) which implies that the total size of these three data structures is also O(n). Before analyzing the PK structures we need to know more about them. Assume that ps pt ∈ E(EMST). Removing this edge from the EMST will break this graph into two connected components C1 (P1 , E1 ) and C2 (P2 , E2 ). Only those edges pi pj of E(DT) that pi ∈ P1 and pj ∈ P2 can be used to reconnect C1 and C2 and obtain a spanning tree (not necessarily minimum). Let denote this set of edges by cut(ps pt ). Figure 3a shows such cuts for edges p4 p5 and p5 p6 . It is simple to argue that each edge of PK(ps pt ) exists in cut(ps pt ), but the reverse is not necessarily true. For all edges ps pt ∈ path(pi , pj ), pi pj exists in cut(ps pt ) but pi pj belongs only to PK(ps pt ) where ps pt has the maximum length among the edges of the path path(pi , pj ). Using the following steps we can ﬁnd the edges of PK(ps pt ) for all edges ps pt ∈ E(EMST): 1. For each face fk of the SD subdivision we build a dual directed tree D(fk ) as follows. Each triangle of DT that is inside the face fk corresponds to a node in D(fk ) and two nodes of D(fk ) are connected by an edge if their corresponding triangles have an edge in common. The face fk has exactly one boundary edge which is not in E(EMST) and is an edge of the convex hull

268

Z. Rahmati and A. Zarei

root p1

p3 p2

p2

b

p4

p4

a

p6

p5

p1

p3 e f

c

p6

p5

root g

h root p7

(a)

p7

(b)

Fig. 3. (a) cut(p4 p5 ) = {p4 p7 , p4 p5 , p3 p5 , p2 p5 , p2 p6 , p1 p6 , p1 p7 } and cut(p5 p6 ) = {p5 p6 , p2 p6 , p1 p6 , p7 p6 }. (b) Dual trees of the faces of a Delaunay triangulation.

of the points. We add one extra node to D(fk ) as its root that is connected to the node corresponding to the triangle that is adjacent to this convex hull edge (see Figure 3b). The direction of the edges of D(fk ) is set to be from parent to child. → −−→ 2. We assign a left label l(− p− i pj ) and a right label r(pi pj ) to each directed edge − − → pi pj ∈ D(fk ) as follows (In the following items max(a, b) denotes the edge of maximum length among edges a and b): 2.1. If pj is a leaf node, both edges of its dual triangle lie on the EMST. Let pm pl and pm pr be these edges which pl lies on the left of the directed −−p−− → −−→ chain p i j pm and pr lies on the right of this chain. We set l(pi pj ) and − − → r(pi pj ) to be pm pl and pm pr , respectively. 2.2. If pj has only one child pk , one of the edges of its dual triangle lies on the −−p−−→ EMST. Let e be this edge. If e lies on the left (right) of the chain p i j pk , − − → − − → − − → − − → − − → we set l(pi pj ) and r(pi pj ) to be max(l(pj pk ), e) and r(pj pk ) (l(pj pk ) and → max(r(− p− j pk ), e)), respectively. 2.3. Otherwise, pj has two children. Assume that pl is the left child (according → −−→ −−→ to the direction of − p− i pj ) and pr is the right one. If r(pj pl ) = l(pj pr ), we set − − → − − → − − → − − → − − → → l(pi pj ) and r(pi pj ) to be max(l(pj pl ), l(pj pr )) and max(r(pj pl ), r(− p− j pr )), − − → − − → respectively. Otherwise, assume that e = r(pj pl ) = l(pj pr ) and pm and ps are the dual nodes of the triangles adjacent to e and e lies to the left −−−−−→ −−−−−→ of a chain − p− m pm pm and lies to the right of a chain ps ps ps of D(fk ) (If − − − − → − − − → − − − − → l(pm pm ) = r(ps ps ), we use this value (l(pm pm )) as the new value of e and ﬁnd the nodes pm and ps corresponding to this value of e as deﬁned −−− −→ before. This is done until we obtain diﬀerent values for l(p m pm ) and − − → − − → − − → −−− −→ − − − → r(ps ps ).). Then, we set l(pi pj ) and r(pi pj ) to be max(l(pj pl ), l(p m pm )) − − → − − − → and max(r(pj pr ), r(ps ps )), respectively. If pm (ps ) is a leaf node in D(fk ), its dual triangle must have another edge in the EMST which −−− −→ −−−→ −−→ −−→ is used instead of l(p m pm ) (r(ps ps )) to obtain l(pi pj ) (r(pi pj )). For example, assuming that in Figure 3b we have |p5 p7 | < |p4 p5 | < |p5 p6 | and |p2 p3 | < |p3 p4 | < |p1 p2 |. Then,

Kinetic Euclidean Minimum Spanning Tree

269

→ − → − → − → − l(ba) = p4 p5 , r(ba) = p3 p4 ; l( cb) = p4 p5 , r( cb) = p3 p4 ; − → − → → → ec) = p3 p4 ; l(f e) = p5 p6 , r(f e) = p1 p2 ; l(− ec) = p5 p6 , r(− − → − → − → − → l(f h) = p5 p7 , r(f h) = p5 p6 ; l(gf ) = p4 p5 , r(gf ) = p1 p2 ; 3. An edge e ∈ E(DT) − E(EMST) is added to PK(e ) where e = → −−→ −−→ max(l(− p− i pj ), r(pi pj )) and pi pj is the dual edge of e in a D(fk ) tree. The distance of this entry in PK(e ) is set to be the height of the subtree of D(fk ) with root pj . There are two faces adjacent to e in its left and right sides. Therefore, we may have two edges in PK(e ) with the same distance one for each side of e . In order to obtain a well-deﬁned ordering and distinct values of distances, we set the sign of distances of all edges of PK(e ) that come from one side of e to be positive and the other ones to be negative. 4. For each edge e ∈ E(EMST), it will be added to PK(e ) with zero as its distance value. We used three simple observations inside the above steps which we ignore their proves. 1. D(fk ) is a tree. 2. Each internal node of D(fk ) has at most two children. 3. Each face fk has exactly one boundary edge that is an edge of the convex hull of the points. Lemma 5. The above procedure correctly computes the edges of PK(e) for all edges e ∈ E(EMST). Proof. According to our deﬁnition, an edge pi pj ∈ E(DT)− E(EMST) is added to PK(ps pt ) if and only if ps pt exists in path(pi , pj ) and has the maximum length among edges of path(pi , pj ). Assume that after running the above procedure pi pj has been added to PK (ps pt ). This implies that pi pj ∈ cut(ps pt ) and therefore, ps pt is a member of path(pi , pj ). On the other hand, for each edge ps pt ∈ path(pi , pj ) there is a path in D(fk ) along which the ps pt label can reach to either the left or the right label of the edge a where fk is the face containing edge pi pj and a is the dual edge of pi pj in D(fk ). The only exception to this claim is due to the 2.3. step −−→ −−→ of the building procedure in witch the labels l(p j pr ) and r(pj pl ) are omitted if they are equal. It is simple to prove that such labels do not belong to path(pi , pj ). − → For example, the label p5 p6 can not reach to the edge gf in Figure 3b even if it has the maximum length among all edges of the EM ST and it is apparent / path(p7 , p1 ). Therefore, if ps pt is the left or right label of the edge that p5 p6 ∈ a with the maximum length, |ps pt | must have the maximum among all edges of path(pi , pj ) which proves the only if part. To prove the if part, assume that ps pt exists in path(pi , pj ) and has the maximum length among edges of path(pi , pj ) where pi pj ∈ E(DT) − E(EMST). Trivially, pi pj ∈ cut(ps , pt ) and lies inside the face fk where ps pt lies on its boundary. On the other hand, any edge ps pt ∈ E(EMST) that can be the label of the dual edge a of pi pj in D(fk ) lies on the path path(pi , pj ). These implies

270

Z. Rahmati and A. Zarei

that the label of the edge a must be equal to ps pt which means that pi pj must be added to PK(ps pt ). Lemma 6. For a set of n points, the PK structures of all edges of the EMST can be constructed in O(n log n) time and their total size is O(n). Proof. By the same argument the DCEL structure of the DT, EMST and SD of the points can be constructed in O(n log n) time. Having this DCEL, the ﬁrst step can be done in O(n) time. The second step can be done in O(n) time as well. Finally, the last steps insert O(n) items into their corresponding MS-BBST in total O(n log n) time. The number of PK structures is O(n) but their total size is still O(n). Summarizing the above discussions, we have the following theorem about the complexity of our KDS. Theorem 2. The proposed KDS can be constructed in O(n log n) time and requires O(n) space.

4

Event Handling

In this section we describe how the events are processed to correctly maintain the EMST as well as updating our KDS during the motion. 4.1

Processing DT-Events

According to Lemma 2, when a DT-event with parameters pi pj , pk pl and t happens it does not have a direct eﬀect on the EMST and, therefore, it is enough to update our KDS with respect to this event. First, we update the PK data structures. These data structures are aﬀected because the edge pi pj must be removed from the DT and pk pl must be inserted instead. pi pj belongs to PK(e) for some e ∈ E(EMST) and because we have a pointer from pi pj to its position in PK(e) it can be removed in O(log n) time. Now, we should ﬁnd the edge e such that the new edge pk pl must be inserted in PK(e ). We determine the edge e by checking the status of the four edges pi pk , pi pl , pj pk and pj pl . Assume that pi pk ∈ PK(e1 ), pi pl ∈ PK(e2 ), pj pk ∈ PK(e3 ) and pj pl ∈ PK(e4 ). It is simple to prove that it is impossible to have four distinct values for e1 , e2 , e3 and e4 . So assume that two of these four edges are the same. Without loss of generality, assume that e1 is equal to one of the other edges. We continue with two cases where either e1 = e2 or e1 = e4 . The other case (e1 = e3 ) is the same as the case of e1 = e2 . For the ﬁrst case where e1 = e2 , the edge pk pl must be added to the PK data structure of one the edges e3 or e4 that has greater Euclidean length. Assuming that |e3 | > |e4 |, pk pl is added to PK(e3 ) and its position (ordering) is just before (resp. after) the position of the edge pj pk if e3 lies before (resp. after) pj pk in the ordering of P K(e3 ).

Kinetic Euclidean Minimum Spanning Tree

271

In the other case where e1 = e4 the edge pk pl is added to PK(e1 ) between positions of the edges pi pk and pj pl in PK(e1 ). Doing the above updates, we obtain the correct values of PK for the time t + just after the event. The second part of our KDS, the V, E and F data structures only depend on the subdivision SD. This subdivision is the overlay of the EMST and the convex hull of the points. DT-events does not change the EMST. Hence, a DTevent changes these data structures if it aﬀects the convex hull of the points. According to our bounding box assumption which deﬁnes the convex hull, the DT-events do not aﬀect the V, E and F data structures. Finally, on processing a DT-event of parameters pi pj , pk pl and t, the T (DT) and Q(DT) data structures are updated as follows. The edge pi pj is removed from T (DT) and its associated certiﬁcates (at most two certiﬁcates for its previous and next edges in T (DT) ) are removed from Q(DT). Then, the new DT edge, pk pl is inserted into T (DT) and the new certiﬁcates (at most two) associated to this edge are determined and inserted into Q(DT). 4.2

Processing Order Events

For an order event of parameters pi pj , pk pl and t we should apply the necessary changes to the EMST as well as to our KDS. These changes are applied as follows. We ﬁrst update the order of the edges pi pj and pk pl in T (DT) by swapping their positions in T (DT). Then, the previous certiﬁcates of these edges that are no longer valid are removed from Q(DT) and the new certiﬁcates, according to the new adjacent edges of pi pj and pk pl in T (DT) are computed and inserted into Q(DT). An order event changes the V, E and F data structures if it results a change in the EMST. Otherwise, these data structures are not aﬀected due to an order event. In order to identify the eﬀect of the assumed order event we distinguish between four diﬀerent cases: a) b) c) d)

pi pj pi p j pi p j pi p j

∈ / E(EMST) ∈ E(EMST) ∈ / E(EMST) ∈ E(EMST)

and and and and

pk pl pk pl pk pl pk pl

∈ / E(EMST). ∈ E(EMST). ∈ E(EMST). ∈ / E(EMST).

In cases (a) and (c) none of the PK, V, E and F data structure is changed. Therefore, the EMST is not changed in these cases. In case (b) the order event does not change the EMST of the points and therefore, it does not change the V, E and F data structures. However, it should be checked to see whether there is an edge e in both PK(pi pj ) and cut(pk pl ). If there are such edges, they must be removed from PK(pi pj ) and added to PK(pk pl ). Trivially, if pi pj and pk pl do not lie on the boundary of a single face of SD, there is no edge e in both PK(pi pj ) and cut(pk pl ).

272

Z. Rahmati and A. Zarei

Therefore, we ﬁrst check this condition using the E and F data structures: Each edge has two half-edges in E and each half-edge points to its corresponding half-edge in F (fs ) for some face fs of SD. If we obtain the same face for a halfedge of pi pj and a half-edge of pk pl , a subset Δ of edges of PK(pi pj ) must be removed and these edges must be inserted into PK(pk pl ). The subset Δ has the following properties: – The subset Δ is a connected part of the sorted list of edges in P K(pi pj ) i.e. if e1 ∈ Δ has the minimum distance and e2 ∈ Δ has the maximum distance among edges of Δ, there is no edge e ∈ P K(pi pj ) − Δ that its distance is between the distances of e1 and e2 . – For each ps pt ∈ Δ, pl pk ∈ f where f is the face of SD that contains the edge ps pt . Moreover, f is adjacent to only one of the half-edges of pk pl . Using the above properties, we can ﬁnd the two extreme edges of Δ by navigating along two paths from the root of P K(pi pj ) to two leaves. At any node of these paths we check the second property using the F (f ) data structure to determine the direction of the next step downward. After ﬁnding Δ, it will be removed from P K(pi pj ) and inserted into its appropriate position in P K(pk pl ). Assume that this appropriate position is between the edges ps pt and ps pt of P K(pk pl ). We have the following property about these edges: – For each edge pm pn ∈ Δ, pathf (ps , pt ) ⊂ path(pm , pn ) and pathf (pm , pn ) ⊂ path(ps , pt ) where pathf (pi , pj ) is the path between pi and pj on the boundary of f that uses only the half-edges of the edges of the EMST. Using this property, we can ﬁnd the position of Δ in P K(pk pl ) by navigating a path from the root of P K(pk pl ) to a leaf. It is notable that in some cases there is no edge ps pt or ps pt in P K(pk pl ) and Δ must be added to the start or the end of P K(pk pl ). In case (d) if pk pl ∈ / PK(pi pj ), none of p the PK, V, E and F data structures and the f f EMST is changed. Otherwise, by adding pk pl p to the EMST and removing pi pj we obtain an p p f EMST of smaller weight. Therefore, in such conditions the EMST and some parts of our KDS must be updated. To do this pk pl is added to the EMST and pi pj is removed from Fig. 4. Cutting fmid from fs and it. Whereas pi pj no longer exists in the EMST adding it to ft and pk pl is a new edge of the EMST, PK(pi pj ) is no longer required and we must build the P K(pk pl ) data structure. It is interesting to note that just after the event P K(pk pl ) is equal to P K(pi pj ) just before the event and we can use the existing P K(pi pj ) as the value of the required PK(pk pl ). Moreover, pi pj is removed from E, V(pi ) and V(pj ). Finally, F (fs ) and F (ft ) are updated accordingly where fs and ft are the two faces adjacent to pi pj . As shown in Figure 4, a set of half-edges of the boundary of fs is removed from F (fs ) and this set l

s

mid

j

k

t

i

Kinetic Euclidean Minimum Spanning Tree

273

−−→ is inserted into F (ft ). Precisely, the half-edge p i pj is removed from F (ft ), the sequence of half-edges from pi to pk are removed from F (fs ) and are inserted → into F (ft ) just after the point pi , the half-edge − p− k pl is inserted into F (ft ) just after the point pk , the sequence of half-edges from pl to pj are removed from −−→ F (fs ) and are inserted into F (ft ) just after the point pl , the half-edge p j pi is − − → removed from F (fs ), and the half-edge pl pk is inserted into F (fs ) just after the point pl . Except for the case (b) of processing an order-event, other processes required for a DT-event and order-event includes a constant number of logarithmic operations (search, insert, delete, merge, split) on data structures of linear size. The excepted part of the processing of an order event can be done in O(log2 n) time using the P K and F MS-BBST data structures. Therefore, Theorem 3. Each DT-event and order event can be handled in O(log n) and O(log2 n) time.

5

Performance Analysis

In this section, we analyze the performance of the proposed KDS according to the KDS performance criteria. Theorem 4. The proposed KDS for a set of n moving points has the following properties: • • • •

It processes O(n4 ) events. Each event can be handled in O(log2 n) time. Each point participates in O(1) (in average) number of certiﬁcates. It uses O(n) space and requires O(n log n) preprocessing time.

Therefore, the proposed KDS is responsive, compact and local (in average). Proof. Assume that x and y coordinates of moving points are deﬁned by algebraic functions of maximum degree s. There are O(n2 ) items (lengths of edges) that can appear in T (DT). Although at any ﬁxed time only O(n) items exist in T (DT), to obtain an upper bound we assume that all these items exist in T (DT). The total number of swaps in this sorted list is O(n4 ) which dominates the number of the DT-events (the number of the Delaunay triangulation events is O(n2 λs (n))). This O(n4 ) bound is a consequence of our assumption about the motion of the points: x and y coordinates of the points change according to some algebraic functions of constant maximum degree which means that s is constant. However, we do not know how much this upper bound is tight. The second property is concluded from Theorem 3. the Delaunay triangulation is a planar graph which means that the average number of edges of its points is constant. This concludes the third property. The last property is concluded from Theorem 2. Eﬃciency is somehow the main KDS performance evaluation metric. As discussed in Section 1, this metric depends on the upper bound of the number of

274

Z. Rahmati and A. Zarei

the internal events and the lower bound of the number of the external events. We proved an upper bound of O(n4 ) for the number of internal events in Theorem 4. But, the number of external events is smaller [13] which means that this KDS is not eﬃcient.

6

Conclusion

In this paper, we considered the kinetic version of the planar Euclidean minimum spanning tree. We proposed a KDS that can be used to track the combinatorial changes of the EMST of a set of moving points. Our KDS is the ﬁrst responsive, local in average and compact solution for this problem. Proving the tight bounds of the number of the changes of the EMST is the immediate open direction in continuing this research. Extending to higher dimensions as well as to dynamic environments in which the points are added or removed are the other future directions.

References 1. Agarwal, P.K., Eppstein, D., Guibas, L.J., Henzinger, M.R.: Parametric and kinetic minimum spanning. In: 39th IEEE Sympos Found Comput Sci, pp. 596–605 (1998) 2. Basch, J.: Kinetic data structures. PhD Thesis, Stanford University (1999) 3. Basch, J., Guibas, L.J., Hershberger, J.: Data structures for mobile data. Journal of Algorithms 31, 1–28 (1999) 4. Basch, J., Guibas, L.J., Zhang, L.: Proximity problems on moving points. In: 13th Annual Symposium on Computational Geometry, pp. 344–351 (1997) 5. de Berg, M., Cheong, O., van Kreveld, M., Overmars, M.: Computational Geometry: Algorithms and Applications, 3rd edn. Springer, Santa Clara (2008) 6. Boissonnat, J.-D., Teillaud, M.: On the randomized construction of the Delaunay. Theoretical Computer Science 112, 339–354 (1993) 7. Chang, R.C., Lee, R.C.T.: An O(nlogn) minimal spanning tree algorithm for n points in the plane. BIT 26, 7–16 (1986) 8. Eppstein, D.: Dynamic Euclidean minimum spanning trees and extrema of binary functions. Discrete and Computational Geometry 13, 111–122 (1995) 9. Fu, J.-J., Lee, R.C.T.: Minimum Spanning Trees of Moving Points in the Plane. IEEE Transactions on Computers 40, 113–118 (1991) 10. Guibas, L.J., Mitchell, J.S.B., Roos, T.: Voronoi Diagrams of Moving Points in the Plane. In: Proceedings of the 17th International Workshop, pp. 113–125 (1991) 11. Guibas, L.J., Knuth, D.E., Sharir, M.: Randomized incremental construction of Delaunay and Voronoi diagrams. Algorithmica 7, 381–413 (1992) 12. Kruskal, J.B.: On the Shortest Spanning Subtree of a Graph and the Traveling Salesman Problem. Proceedings of the American Mathematical Society 7, 48–50 (1956) 13. Katoh, N., Tokuyama, T., Iwano, K.: On minimum and maximum spanning trees of linearly moving points. Discrete and Computational Geometry 13, 161–176 (1995) 14. Prim, R.C.: Shortest connection networks and some generalizations. Bell System Technical Journal 36, 1389–1401 (1957) 15. Tarjan, R.E.: Data structures and network algorithms. Society for Industrial and Applied Mathematics (1983)

Generating All Simple Convexly-Drawable Polar Symmetric 6-Venn Diagrams Khalegh Mamakani, Wendy Myrvold, and Frank Ruskey Dept. of Computer Science, University of Victoria, Canada

Abstract. An n-Venn diagram consists of n curves drawn in the plane in such a way that each of the 2n possible intersections of the interiors and exteriors of the curves forms a connected non-empty region. A Venn diagram is convexly-drawable if it can be drawn with all curves convex and it is simple if at most two curves intersect at any point. A Venn diagram is called polar symmetric if its stereographic projection about the infinite outer face is isomorphic to the projection about the innermost face. We outline an algorithm that shows there are exactly 375 simple convexly drawable polar-symmetric 6-Venn diagrams. Keywords: Venn diagram, polar-symmetry.

1

Introduction

Named after John Venn(1834 − 1923), who used diagrams of overlapping circles to represent propositions [10], Venn diagrams are commonly used in set theory to visualize the relationship between diﬀerent sets. When talking about Venn diagrams, the traditional three circles diagram with 3-fold symmetry often comes to mind (Figure 1(a)). Although it is not possible to use circles to draw Venn diagrams of more than 3 sets, more than 3 sets can be represented if the curves of the Venn diagram are other simple closed curves. Figure 1(b) shows a 5set Venn diagram composed of 5 congruent ellipses which was discovered by Gr¨ unbaum[5], and Figure 1(c) shows a 7-set Venn diagram with 7-fold rotational symmetry called Adelaide which was discovered independently by Gr¨ unbaum [7] and Edwards [3]. Intensive research has been done recently on generating and drawing Venn diagrams of more than three sets, particularly in regard to symmetric Venn diagrams, which are those where rotating the diagram by 360/n degrees results in the same diagram. Henderson considered rotationally symmetric Venn diagrams and he showed that they could exist only if the number of curves is prime [9]. Griggs, Killian, and Savage published a constructive method for producing symmetric Venn diagrams with a prime number of curves [8]. Venn diagrams exist for any number of curves and several constructions of them are known [12]. Another type of symmetry, introduced by Gr¨ unbaum [6], is called polarsymmetry which can be imagined by ﬁrst projecting the diagram onto the surface of a sphere with the regions corresponding to the full and empty sets at the north C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 275–286, 2011. c Springer-Verlag Berlin Heidelberg 2011

276

K. Mamakani, W. Myrvold, and F. Ruskey

and south poles, respectively. The Venn diagram is polar-symmetric if it is invariant under polar ﬂips, meaning that the north and south hemispheres are congruent. In other words, for a polar-symmetric Venn diagram on the plane turning the diagram inside-out (the innermost face becomes the outermost face) gives the same Venn diagram. Note that all three Venn diagrams of Figure 1 are polar-symmetric, as well as being rotationally symmetric. The only other attempt that we know of to exhaustively list some interesting class of 6-Venn diagrams is the work of Jeremy Carroll, who discovered that there are precisely 126 such Venn diagrams where all curves can be drawn as triangles [2]. He used a brute force search algorithm for all possible face sizes of a Venn diagram. However, the problem of generating polar-symmetric six-set Venn diagrams has not been studied before. In this paper we are restricting our attention to the special (and most studied) class of Venn diagrams that are both simple and drawable with convex curves. We introduce two representations of these diagrams. Inspired by Carroll’s work, an algorithm for generating all possible simple convexly-drawable polar-symmetric six-set Venn diagrams is developed — an algorithm which determines that there are exactly 375 simple convexly-drawable polar-symmetric 6-Venn diagrams. Although our results are oriented towards 6-Venn diagrams, they could in principle be applied to general n-Venn diagrams, but the computations will quickly become prohibitive. Nevertheless, we believe that the data structures and ideas introduced here (i.e., the representations) will be useful in further investigations, and in particular to resolving one of the main outstanding open problems in the area of Venn diagrams: is there a simple 11-Venn diagram? We intend to use the data structures proven useful here to attack a restricted, but natural, version of that problem: is there a simple convexly-drawable polar-symmetric 11-Venn diagram? The study of symmetric Venn diagrams in interesting not only because symmetry is core aspect of mathematical enquiry, but also because we are often led to diagrams of great inherent beauty. Furthermore, the geometric dual of a simple Venn diagram is a maximal planar spanning subgraph of the the hypercube, and so results about Venn diagrams often have equivalent statements as results about the hypercube. The remainder of paper is organized as follows. In Section 2 we introduce basic deﬁnitions. Representations of simple convexly-drawable Venn diagrams are explained in Section 3. The generating algorithm and results are explained in the last two sections.

2

Basic Definitions

A closed curve in the plane is simple if it doesn’t intersect itself. Each simple closed curve decomposes the plane into two connected regions, the interior and the exterior. An n-Venn diagram is a collection of n ﬁnitely intersecting simple closed curves C = {C0 , C1 , . . . , Cn−1 } in the plane, such that there are exactly 2n nonempty and connected regions of the form X0 ∩ X1 ∩ · · · ∩ Xn−1 , where

Generating All Simple Convexly-Drawable Polar Symmetric 6-Venn

277

{1}

{1,2}

{1,3} {1,2,3}

{2}

{2,3}

{3}

(a)

(b)

(c) Fig. 1. (a) A 3-Venn diagram whose curves are circles. (b) A 5-Venn diagram whose curves are ellipses. (c) A symmetric 7-Venn known as “Adelaide.”

Xi is either the unbounded open exterior or open bounded interior of curve Ci . Each connected region corresponds to a subset of the set {0, 1, . . . , n − 1}. Two Venn diagrams are isomorphic if one of them can be changed into the other or its mirror image by a one-to-one continuous transformation of the plane onto itself. A k-region in a diagram is a region that is in the interior of precisely k curves. In an n-Venn diagram, each k-region corresponds to a k-element subset of a set with n elements. So, there are nk k-regions. A Venn diagram is monotone if every k-region is adjacent to both some (k − 1)-region (if k > 0) and also to some (k + 1)-region (if k < n). A diagram is monotone if and only if it is drawable with each curve convex [1]. A simple Venn diagram is one in which exactly two curves cross each other at each intersection point. Figure 2 shows a simple monotone 6-Venn diagram. Consider a Venn diagram as being projected onto the surface of a unit sphere where the empty region of the diagram encloses the north pole of the sphere and the innermost region contains the south pole. A cylindrical projection of the

278

K. Mamakani, W. Myrvold, and F. Ruskey

Fig. 2. A simple monotone 6-Venn diagram

Venn diagram can be obtained by mapping the surface of sphere to a 2π by 2 rectangle on the plane, where the equator of the sphere maps to a horizontal line of length 2π and the north and south pole of the sphere are mapped to the top and bottom sides of the rectangle respectively. In this representation, the top of cylinder represents the empty region and bottom of cylinder represents the innermost region. A Venn diagram is said to be polar symmetric if it is invariant under polar ﬂips. In the cylindrical representation the polar ﬂip is equivalent to turning the cylinder upside-down. For a Venn diagram on the plane, a polar ﬂip is equivalent to turning the diagram inside-out, with the innermost face becoming the outermost. It is known that there are exactly 6 simple monotone 7-Venn diagrams with rotational and polar symmetry [4],[3]. Figure 3 shows the cylindrical representation of the polar symmetric 6-Venn diagram shown in Figure 2. Note that in the cylindrical representation of a monotone Venn diagram every curve is x-monotone because of the monotonicity of the diagram; i.e., every vertical line intersects each curve at a single point at most. A simple Venn diagram can be viewed as a planar graph where the intersection points of the Venn diagram are the vertices of the graph and the sections of the curves that connect the intersection points are the edges of the graph. For a

Fig. 3. Cylindrical representation of the 6-Venn diagram of Figure 2

Generating All Simple Convexly-Drawable Polar Symmetric 6-Venn

279

planar graph with f faces, v vertices and e edges, Euler’s formula states that f + v = e + 2. A graph of an n-Venn diagram has 2n faces. In a simple Venn diagram each vertex of this graph has degree 4; i.e. e = 2v, so a simple n-Venn diagram has 2n − 2 vertices.

3

Representing Venn Diagrams

In this section we introduce two representations for simple monotone Venn diagrams. First we discuss the binary matrix representation where each 1 in the matrix represents an intersection point of the corresponding Venn diagram. Having the matrix representation of a diagram, it is easy to check if it is a Venn diagram or not. In the second part we show how to represent simple monotone Venn diagrams using compositions. We use this representation to ﬁnd all candidate diagrams. Then we ﬁlter non-Venn diagrams using the matrix representation. 3.1

Matrix Representation

For a simple monotone n-Venn diagram, every 1-region is adjacent to the empty region. So the empty region surrounds a “ring” of n1 1-regions. An intersection point is said to be part of ring i if of the four incident regions, two are in ring i and the other two are in ring i − 1 and i + 1. Since each region is started by one intersection point and ended by another one, there are n1 intersection points in the ﬁrst ring. Similarly, every 2-region is adjacent to at least one 1-region. So, there are n2 2-regions that form a second ring surrounded by the ﬁrst ring and which contains n2 intersection points. In general, in a simple monotone n−Venn diagram, there are n − 1 rings of regions, where all regions in a ring are enclosed by the same number of curves and every region in ring i, 1 ≤ i ≤ n − 1, is adjacent to at least one region in ring i − 1 and also to at least one region in th ring i + 1. The number of intersection points nin the i ring is the same as the th number of regions in the i ring, which is i . The rings have diﬀerent colors in Figure 1(c). Thus a simple monotone n−Venn diagram can be represented by a n − 1 by m binary matrix, m ≤ 2n − 2, where each 1 in the matrix represents an intersection point in the Venn diagram. Row i of the matrix corresponds to ring i of the Venn diagram. A Venn matrix has the following properties : – There are ni 1’s in the ith row of the matrix, 1 ≤ i ≤ n − 1. – There are no two adjacent 1’s in any row or column of the matrix. – A valid matrix must represent exactly 2n − 2 distinct regions of the corresponding Venn diagram. The two other regions are the outermost and the innermost regions. Figure 4 shows the matrix representation of the Venn diagram of Figures 2 and 3. n−1 The rank of a region of a Venn diagram is deﬁned by i=0 2i xi where xi = 1 if curve i encloses the region and xi = 0 otherwise. Given a matrix representation P , we need to check that no two ranks are the same to check if it represents a valid Venn diagram.

280

K. Mamakani, W. Myrvold, and F. Ruskey

1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0

Fig. 4. Matrix representation of the 6-Venn diagram of Figures 2 and 3

For a given matrix P , suppose vector C = [c0 , c1 , · · · , cn−1 ] represents the curve labels of the corresponding diagram in cylindrical representation along some column where c0 is the label of the outermost(top) curve and cn−1 is the label of the innermost(bottom) curve. Then a region at ring i, 1 ≤ i ≤ n − 1, is i−1 ck enclosed by curves c0 , · · · , ci−1 and the rank of the region is k=0 2 . To get the curve labels for each region we need to update C based on the entries of matrix P at each column. For a given column j of the matrix, each entry of 1 represents an intersection point. So for each row i, if pij = 1 then we need to exchange ci and ci+1 to get the next curve labels. Starting from left to right with C = [0, 1, · · · , n − 1] as the initial curve labels, then we can compute the rank of each region. Matrix P represents a valid simple monotone Venn diagram if we get exactly 2n − 2 regions with distinct ranks and C = [0, 1, · · · , n − 1] at the end given that we start with C = [0, 1, · · · , n− 1]. We used the matrix representation in [4] to generate all monotone simple symmetric 7-Venn diagrams. 3.2

Compositions

In this part we introduce the other representation we use to generate Venn diagrams. In this representation, we use a sequence of non-negative integers to show the size of faces in each ring and and also to specify the position of intersection points of the next ring. Definition 1. Let a1 , a2 , · · · , ak be non-negative integers such that : k

ai = n

i=1

Then (a1 , a2 , · · · , ak ) is called a composition of n into k parts or a k−composition of n. n In a simple monotone n-Venn diagram there are i+1 intersection points at ring n i + 1 that are distributed among i intersection points at ring i. So if we pick a particular point at ring i as the reference point, thenwe can specify the exact n into ni parts. location of points at ring i + 1 using a composition of i+1

Generating All Simple Convexly-Drawable Polar Symmetric 6-Venn

281

Definition 2. Let C(n, k) be the set of all compositions of n into k parts. For a simple monotone n-Venn diagram V , starting from an arbitrary point of the first ring, we label the intersection points of V from 1 to 2n − 2 in clockwise direction. Let i denote the label of the starting point at ring i. The composition representation P of V is a set of n − 2 pairs of form i , ci , where n n n , ci ∈ C , 1 = 1, i = i−1 + i i−1 i+1 Figure 5 shows the composition representation of the 6-Venn diagram of Figure 2 and 3.

3

1

2 1 0

3 1

2

7

1

1

22

1

0

0

42

1

1

1

1 1

1 0

3 1

2 0 1

1

1

1 0

1 0

3 1

2 0 1

1

1

1 0

1 0

2 1

2 0 1

1 1

1

1 0

1 1

0

0 1

Fig. 5. Composition representation of the 6-Venn diagram of Figures 2 and 3

We now list several observations that will help us cut down on the size of the search space. Observation 1. For any simple monotone n-Venn diagram V , the largest part of ci in the composition representation is at most n − i − 1. Proof. A region at ring i is enclosed by i curves above its starting and ending points. Since the size of a region is at most n and no two edges belong to the same curve [11], at most n − i remaining curves can be used to shape the region. As shown in Figure 6, to put p intersection points between the two end points of the region on the next ring, we need p + 1 curves, p − 1 curves for the bottom side and two curves for the left and right sides. So, p ≤ n − i − 1. Observation 2. In the composition representation of any simple monotone Venn diagram with more than 3 curves, there are no two non-adjacent 1’s in c1 . Proof. Suppose, there is such a Venn diagram V, then the ﬁrst ring of the Venn diagram will be like Figure 7 , where regions A and D correspond to non-adjacent 1’s in the composition and A = D. Then A ∩ D = ∅ which contradicts the assumption that V is a Venn diagram. So in the ﬁrst ring composition there are at most two 1’s which must be adjacent. Observation 3. There are no two faces of size 3 adjacent to another face of size 3 in a simple monotone n−Venn diagram V.

282

K. Mamakani, W. Myrvold, and F. Ruskey

111111111111111111111111111 000000000000000000000000000 000000000000000000000000000 111111111111111111111111111 000000000000000000000000000 111111111111111111111111111 Enclosed by i curves 000000000000000000000000000 111111111111111111111111111 000000000000000000000000000 111111111111111111111111111 p intersection points

Fig. 6. Largest part of the composition at level i

A

F AF

B AB

C

D CD

E DE

Fig. 7. Non-Adjacent 1’s in the first ring composition

Proof. There are only two cases, shown in Figure 8, that two faces of size 3 could be adjacent to a single face of size 3. However, both cases result in a two part disconnected region(the shaded region) which contradicts the fact that V is a Venn diagram. Observation 4. There are no two consecutive 0’s in c2 for the composition representation of any simple monotone n-Venn diagram. Proof. By observation 3 Definition 3. Let r1 , r2 ∈ C(n, k) be two compositions of n into k parts. r1 and r2 are rotationally distinct if it is not possible to get r2 from any rotation of r1 or its reversal. Let Fn denote the set of all rotationally distinct compositions of n2 into n parts such that for any r ∈ Fn there are no two non-adjacent parts of 1 and all parts are less than or equal to n − 2. Theorem 5. If c1 is the composition corresponding to the first ring of a simple monotone n-Venn diagram, then c1 ∈ Fn . Proof. Given a simple monotone n-Venn diagram, suppose we get the composition representation P of V by picking a particular intersection point x in the ﬁrst ring as the reference point. Now let P be another representation of V using any other intersection point diﬀerent than x as the reference point. It is clear that c1 in P is a rotation of c1 in P . Also for any composition representation P of the mirror of V the ﬁrst composition c1 in P is a rotation of the reversal

Generating All Simple Convexly-Drawable Polar Symmetric 6-Venn

A

B AB

C BC

A

B

283

C

A

AC BC

AB

(a)

AC

BC

(b)

Fig. 8. Possible cases for two faces of size 3 being adjacent to a single face of size 3

of c1 . By the observations 1 and 2 the largest part of c1 is n − 2 and there are no two non-adjacent 1’s in c1 . Therefore, there is a composition c ∈ Fn which is rotationally identical to c1 .

4

Generating Algorithm

Given the upper/lower half of the cylindrical representation of a polar symmetric Venn diagram, one can generate the whole diagram by creating a copy of the given half, turning it upside down and rotating it until the two parts match together. So, to generate a polar symmetric monotone Venn diagram, we need only to generate the ﬁrst n−2

compositions. 2 Two halves of the diagram can match only if gluing them using the intersection points doesn’t create any faces of size 2. Given the last composition of the upper half, for each positive part aj there are aj −1 edges that bound the corresponding face from the bottom and there is a gap between two faces corresponding to two consecutive parts of the composition. So, we can map the composition to a bitstring where each 1 represents a bounding edge of a face and each 0 represents the gap between two faces. The length of bit-string is the same as the sum of all parts of the composition. In other words the composition (a1 , a2 , · · · , ak ) is mapped to the following bit-string. a1 −1 bits

a2 −1 bits

ak −1 bits

11 · · · 1 0 11 · · · 1 0 · · · 0 11 · · · 1 0

We can ﬁnd all matchings of the two halves by computing the bitwise “and” of the bit-string and its reverse for all left rotations of the reverse bit-string. Any result other than 0 means that there is at least one face of size 2 in the middle. Then for each matching we compute the matrix representation of the resulting diagram. The matrix can be obtained by sweeping the compositions from left to right and computing the position of each intersection point. Checking each resulting matrix for all compositions gives us all possible polar symmetric 6-Venn diagrams.

284

K. Mamakani, W. Myrvold, and F. Ruskey

Algorithm 1. GenPolarSymSixVenn

begin foreach composition (a1 , a2 , · · · , a6 ) ∈ F6 do foreach composition (b1 , b2 , · · · , b15 ) ∈ C(20, 15) do create the corresponding upper and lower halves for i ← 1 to 20 do glue the upper and lower halves if there are no parallel edges in the diagram then compute matrix X representing the diagram if isV enn(X) then Print(X) rotate lower half one point to the left end

5

Results

Using the exhaustive search we found 375 simple monotone polar symmetric 6-Venn diagrams. This result was independently checked by using a separate program that is based on a diﬀerent search method. That search method will be explained in the eventual expanded version of this paper. Table 1. Number of polar symmetric 6-Venn diagrams for F6 Composition Venn Diagrams 443211 25 434211 0 344211 38 442311 0 433311 12 343311 9 424311 0 432411 0 442221 15 433221 2 343221 30 424221 0 334221 6 244221 13 432321 7 342321 8 423321 6 333321 41 243321 22 324321 7

Composition Venn Diagrams 234321 5 422421 0 332421 9 242421 0 323421 3 432231 9 342231 15 423231 0 333231 9 324231 0 422331 12 332331 4 422241 0 432222 15 423222 22 333222 6 422322 1 332322 21 323232 3

Generating All Simple Convexly-Drawable Polar Symmetric 6-Venn

285

Table 1 shows the number of Venn diagrams for each particular composition of the ﬁrst level. Figure 9 shows one Venn diagram for each of those 29 compositions that have at least one Venn diagram. Renderings of each of the 375 diagrams may be found at the website: http://webhome.cs.uvic.ca/~ruskey/Publications/SixVenn/SixVenn.html.

Fig. 9. 29 simple monotone polar symmetric 6-Venn diagrams, representing all possible compositions for the outermost ring

286

K. Mamakani, W. Myrvold, and F. Ruskey

References 1. Bultena, B., Gr¨ unbaum, B., Ruskey, F.: Convex Drawings of Intersecting Families of Simple Closed Curves. In: 11th Canadian Conference on Computational Geometry, pp. 18–21 (1999) 2. Carroll, J.: Drawing Venn triangles. Technical Report HPL-2000-73, HP Labs (2000) 3. Edwards, A.W.F.: Seven-set Venn Diagrams with Rotational and Polar Symmetry. Combinatorics, Probability, and Computing 7, 149–152 (1998) 4. Cao, T., Mamakani, K., Ruskey, F.: Symmetric Monotone Venn Diagrams with Seven Curves. In: Boldi, P. (ed.) FUN 2010. LNCS, vol. 6099, pp. 331–342. Springer, Heidelberg (2010) 5. Gr¨ unbaum, B.: Venn Diagrams and Independent Families of Sets. Mathematics Magazine, 13–23 (January-February 1975) 6. Gr¨ unbaum, B.: Venn Diagrams I. Geombinatorics I(4), 5–12 (1992) 7. Gr¨ unbaum, B.: Venn Diagrams II. Geombinatorics II(2), 25–32 (1992) 8. Griggs, J., Killian, C.E., Savage, C.D.: Venn Diagrams and Symmetric Chain Decompositions in the Boolean Lattice. Electronic Journal of Combinatorics 11(1), #R2 (2004) 9. Henderson, D.W.: Venn diagrams for more than four classes. American Mathematical Monthly 70, 424–426 (1963) 10. Venn, J.: On the diagrammatic and mechanical representation of propositions and reasonsings. Philosophical Magazine and Journal of Science, Series 5 10(59) (1880) 11. Chilakamarri, K.B., Hamburger, P., Pippert, R.E.: Venn diagrams and planar graphs. Geometriae Dedicata 62, 73–91 (1996) 12. Ruskey, F., Weston, M.: A survey of Venn diagrams. The Electronic Journal of Combinatorics (1997); Dynamic survey, Article DS5 (online) (revised 2001, 2005)

The Rand and Block Distances of Pairs of Set Partitions Frank Ruskey1, and Jennifer Woodcock1 Dept. of Computer Science, University of Victoria, Canada

Abstract. The Rand distance of two set partitions is the number of pairs {x, y} such that there is a block in one partition containing both x and y, but x and y are in diﬀerent blocks in the other partition. Let R(n, k) denote the number of distinct (unordered) pairs of partitions of n that have Rand distance k. For ﬁxed k we prove that R(n, k) can be expressed as j ck,j nj Bn−j where ck,j is a non-negative integer and Bn is a Bell number. For ﬁxed k we prove that there is a constant Kn such that R(n, n2 − k) can be expressed as a polynomial of degree 2k in n for all n ≥ Kn . This polynomial is explicitly determined for 0 ≤ k ≤ 3. The block distance of two set partitions is the number of elements that are not in common blocks. We give formulae and asymptotics based on N(n), the number of pairs of partitions with no blocks in common. We develop an O(n) algorithm for computing the block distance.

1

Introduction and Motivation

In statistics, particularly as it is applied to cluster analysis, it is sometimes useful to have a measure of the diﬀerence between two set partitions [4]. The Rand distance is one such measure, and was introduced in Rand [8]. In this paper we will initiate a combinatorial study of the properties of the Rand distance, taken over all unordered pairs of partitions of an n-set. We will also introduce another measure, which we call the block distance, and determine some of its properties. For example, we will determine an exact expression for the number of pairs of partitions that have no blocks in common. Furthermore, we will show how to compute the block distance eﬃciently. The Rand distance of two set partitions is the number of unordered pairs {x, y} such that there is a block in one partition containing both x and y, but x and y are in diﬀerent blocks in the other partition. We use R(P, Q) to denote the Rand distance between two set partitions P and Q. For example, R({{1, 2}, {3}}, {{1}, {2, 3}}) = 2 (the pairs are {1, 2} and {2, 3}) and R({{1, 2, 3}}, {{1}, {2}, {3}}) = 3 (the pairs are {1, 2}, {1, 3}, and {2, 3}). In general, if P and Q are partitions of an n-set, then 0 ≤ R(P, Q) ≤ n2 . Let R(n, k) be the number of distinct (unordered) pairs of partitions of an n-set that have Rand distance k. See Table 2 in Section 3.1. This table was computed from exhaustive computer listings of all partitions of {1, 2, . . . , n} up

Research supported in part by NSERC.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 287–299, 2011. c Springer-Verlag Berlin Heidelberg 2011

288

F. Ruskey and J. Woodcock

to n = 11. The column sums are B2n . Note that the numbers for ﬁxed n are not unimodal in general. We deﬁne the block distance B(P, Q) between two partitions of n as the number of elements in the blocks that are not common to both P and Q. For example, B({{1, 2}, {3}}, {{1}, {2}, {3}}) = 2 since the only block that is common to both partitions is {3} and there are 2 elements in the remaining blocks. By B(n, k) we denote the number of pairs of partitions of n that have block distance k. See Table 1 in Section 2. The Rand distance can be cleverly computed using a linear number of arithmetic operations; see Filkov and Skiena [2] and we will show that the block distance is also eﬃciently computable. Organizationally, we will ﬁnish this section by giving some background on set partitions. In the succeeding two sections, we discuss ﬁrst the block distance and then the Rand distance. The focus is mainly on the elucidation of some enumerative results along with a clever O(n) algorithm for computing the block distance. 1.1

Background on Set Partitions

A partition of a set S is collection of disjoint subsets of S, say {S1 , S2 , · · · , Sk } whose union is S. Each Si is referred to as a block. The number of partitions of an n-set into k blocks is the Stirling number (of the second kind), which is denoted as nk . We use [n] to denote {1, 2, . . . , n}. In the computer, partitions are usually represented by restricted growth strings. We assume that the blocks of a partition X are numbered S1 , S2 , . . . , Sk according to the size of the smallest element in each block. That is, S1 contains 1, S2 contains the smallest element not in S1 , and so on. Then the restricted growth string r[1..n] of X is deﬁned by taking r[i] to be the distance of the block containing i. The Gray code algorithms for generating restricted growth strings developed in [9] and discussed in [5] were used to generate the numbers in Tables 1 and 2; as each string was generated the O(n) algorithms for computing the Rand distance and the block distance were applied. The n-th Bell number, Bn , is the number of partitions of an n-set, irretotal spective of block size. Thus Bn = k nk . The exponential generating function (egf) of the Bell numbers is well-known (e.g., Stanley [10], pg. 34)) to be B(z) =

Bn

n≥1

The number of pairs of partitions is are

z zn = ee −1 . n!

Bn 2

(1)

. For n = 1, 2, 3, . . . , 10 these numbers

0, 1, 10, 105, 1326, 20503, 384126, 8567730, 223587231, 6725042325. They give the row sums in Tables 1 and 2.

The Rand and Block Distances of Pairs of Set Partitions

289

We use several times a generalization of the fact that if f (z) = n≥0 fn z n /n! is the egf of a sequence fn , then zf (z) is the egf of the sequence nfn−1 . See Knuth, Graham, Patashnik [3], page 350. Furthermore, for k ≥ 0, z k f (z) =

n(n − 1) · · · (n − k + 1)fn−k

n≥k

n zn = k! fn−k . k n!

zn n! (2)

n≥0

Thus k! nk fn−k is the n-th coeﬃcient of z k f (z).

2

The Block Distance

Recall that the block distance B(P, Q) of two partitions of n is the number of elements in the blocks that are not common to both P and Q, and that B(n, k) is the number of pairs of partitions of n that have block distance k. See Table 1. Table 1. The values of B(n, k) for 1 ≤ k ≤ n ≤ 9 n\k 2 3 4 5 6 7 8 9 2 1 3 3 7 4 12 28 65 5 50 140 325 811 700 1950 4866 12762 6 225 7 1092 3675 11375 34062 89334 244588 8 5684 20384 68250 227080 714672 1956704 5574956 9 31572 119364 425880 1532790 5360040 17610336 50174604 148332645

Let N (n) = B(n, n); this is the number of unordered pairs of partitions that have no blocks in common. The numerical values of N (n), for 0 ≤ n ≤ 10, are 0, 0, 1, 7, 65, 811, 12762, 244588, 5574956, 148332645, 4538695461. Determining N (n) for i = 1, . . . , n is suﬃcient to determine B(n, k) since, by direct combinatorial considerations, n B(n, k) = N (k) Bn−k . (3) k We also note that n n Bn n B(n, k) = N (k) Bn−k . = 2 k k=0

k=0

(4)

290

F. Ruskey and J. Woodcock

Letting N (z) be the egf of the N (n) numbers, from (4) we obtain the equation Bn z n z P (z) := = N (z)ee −1 . 2 n! n≥0

And thus

z

N (z) = P (z)e1−e .

(5)

1−ez

The egf e is known; it is the egf of the “complementary Bell numbers” (OEIS A000587). The complementary Bell numbers, Cn , for n = 0, 1, 2, . . . , 14 are 1, −1, 0, 1, 1, −2, −9, −9, 50, 267, 413, −2180, −17731, −50533, 110176. It is known that Cn =

n k=0

n (−1) . k k

Thus, from (5) we get a “closed-form” formula for N (n), namely N (n) =

n n j=0

2.1

j

Cj

Bn−j 2

=

j n n Bn−j j=0

j

2

k=0

j (−1) . k k

Linear Time Algorithm to Compute the Block Distance

In this subsection we present a linear time algorithm to compute the block distance of two partitions. Closely related to the restricted growth string, we deﬁne the block string, b[1..n], of P as follows: b[i] is the smallest element in the block containing i. Every block string has the characterizing property that b[1] = 1, and for i > 1, b[i] ∈ {i, b[1], b[2], . . . , b[i − 1]}. It is relatively simple to convert a restricted growth string into the corresponding block string in O(n) time. The following code takes as input a restricted growth function r[1..n] and returns the corresponding block string b[1..n]. It uses a temporary array m[1..n] that maintains the invariant b[i] = m[r[i]]. for i ∈ {1, 2, . . . , n} do m[i] := 0; for i := 1, 2, . . . , n do if m[r[i]] = 0 then m[r[i]] := i; b[i] := m[r[i]]; Before describing the algorithm for computing the block distance, we encourage the reader to consider the following small example. Suppose P = {1}{2}{3, 4}{5, 7}{6},

Q = {1, 2}{3, 4, 6}{5, 7}.

The Rand and Block Distances of Pairs of Set Partitions

291

Then the restricted growth strings for P and Q are rP = 1, 2, 3, 3, 4, 5, 4,

rQ = 1, 1, 2, 2, 3, 2, 3

and the block strings are p = 1, 2, 3, 3, 5, 6, 5,

q = 1, 1, 3, 3, 5, 3, 5.

Comparing the elements, we ﬁnd that the blocks labelled 1, 2, 3, and 6 are not common to P and Q and that the block labelled 5 is common to P and Q. Since there are 5 elements in blocks 1, 2, 3, and 6, the block distance of P and Q is 5. The algorithm maintains a boolean array C[1..n] with the property that, upon termination, C[i] is true if i is in a block common to P and Q, and is false otherwise. The block distance is thus equal to the number of entries in this array that are false. The algorithm makes two passes over p, one pass over q, and one pass over C. Consider p[i] and q[i]; there are three mutually exclusive cases: (a) p[i] = q[i] and i is not in a common block, (b) p[i] = q[i] and i is in a common block, and (c) p[i] = q[i] and i is not in a common block. (Because we are using the block string and not the restricted growth string, it is not possible that p[i] = q[i] and i is in a common block.) In the ﬁrst pass we test only for case (a). In the second pass we (indirectly) distinguish cases (b) and (c). The key observation is this: If i is not in a common block and p[i] = q[i], then there is some value j = i such that j is in the same block as i in P but is in a diﬀerent block than i in Q, or vice-versa. In other words, p[i] = p[j] = q[j] or p[j] = q[j] = q[i]. Thus, in the ﬁrst pass C[p[j]] and C[q[j]] were set to false. So on the second pass, we test whether C[p[i]] is false to determine whether i is in a common block or not. On the ﬁnal pass, we ﬁnd the block distance by counting the number of false values in C. Below is the code in detail. for i ∈ {1, 2, . . . , n} do C[i] := true for i := 1, 2, . . . , n do if p[i] = q[i] then C[p[i]] := C[q[i]] := false; for i := 1, 2, . . . , n do if ¬C[p[i]] then C[i] := false; c := 0; for i ∈ {1, 2, . . . , n} do if ¬C[i] then c := c + 1; return(c);

3

Results on the Rand Distance

Now recall that R(P, Q) is the number of unordered pairs {x, y} such that there is a block in one partition containing both x and y, but x and y are in diﬀerent blocks in the other partition, and that R(n, k) is the number of distinct (unordered) pairs of partitions of an n-set that have Rand distance k. See Table 2. Let R(n) be the sum of the Rand distance over all unordered pairs of partitions.

292

F. Ruskey and J. Woodcock

Table 2. The values of R(n, k) for 2 ≤ n ≤ 11 and 1 ≤ k ≤ 55. This table is inverted in the sense that k increases down columns and n varies along the columns. k\n 2 3 4 5 6 7 8 9 10 11 1 1 3 12 50 225 1092 5684 31572 186300 1163085 2 6 30 150 780 4200 23772 141624 887220 5835060 3 1 32 280 1720 10885 69272 452508 3060360 21482340 4 24 300 3360 25200 183960 1341648 9883440 74471760 5 6 240 3426 42672 391356 3266172 26969040 222185304 6 1 220 4100 56889 696178 7234374 67288830 612903720 7 60 2400 60165 941088 12259368 141778440 1469224350 8 15 2700 57750 1182888 18992502 256463820 3164268690 9 10 1075 46585 1150520 23324140 399874640 5762811670 10 1 471 31374 1165416 28129626 547907454 9538994388 11 150 24528 815640 26605908 670419540 13513772745 12 35 14140 780570 26190612 742419510 18112131840 13 45 4725 413840 21568932 744780330 20675910420 14 15 1890 369180 17119818 701747010 23653643310 15 1 1302 178080 13040280 607809750 22677991578 16 252 115780 8948079 520591950 22923998460 17 210 43512 6244308 377521875 19287053775 18 140 20734 3679032 312082260 17554312490 19 105 6860 2431044 198307620 13495597225 20 21 7098 1250109 158606532 11143736604 21 1 3508 640908 87210930 8029798920 22 574 315828 63688410 6035010960 23 840 197568 33243120 4254456690 24 665 57288 25703205 2872892550 25 476 46116 11343906 1924619235 26 210 30366 6764940 1215058680 27 28 25732 3272500 789847190 28 1 7695 2003805 453548480 29 4104 1532340 306871290 30 2226 757080 177358500 31 3780 211410 112440900 32 2205 212625 53211510 33 1344 198345 35497935 34 378 138600 16793040 35 36 82512 13781493 36 1 21080 10664335 37 16200 6744100 38 15750 2483415 39 14910 1445565 40 13545 802164 41 7245 1320165 42 3270 860640 43 630 580965 44 45 215325 45 1 104313 46 62205 47 103950 48 70455 49 74250 50 45045 51 21945 52 7095 53 990 54 55 55 1

The Rand and Block Distances of Pairs of Set Partitions

293

Theorem 1 R(n) =

(n2 )

k R(n, k) =

k=0

n Bn−1 (Bn − Bn−1 ). 2

Proof Choose a pair {x, y}. The number of partitions in which this pair appears in the same block is Bn−1 . The number of partitions in which this pair appears in diﬀerent blocks is the diﬀerence Bn − Bn−1 . Thus in total, each pair contributes Bn−1 (Bn − Bn−1 ) to the sum. Since there are n2 ways to choose a pair, the proof is ﬁnished. The average value of the Rand distance is thus R(n) n(n − 1)Bn−1 (Bn − Bn−1 ) Bn = . Bn (Bn − 1) 2 Since the Bell numbers grow exponentially, R(n) Bn−1 , Bn ∼ n2 Bn 2 which experimentally appears to be Θ(n log n). 3.1

Determining R(n, k) for Small Values of k

We now consider R(n, k) for small values of k. Clearly R(n, 0) = 0. Theorem 2. For all n ≥ 1, R(n, 1) =

n Bn−2 . 2

Proof. The only way that the Rand distance can be 1 is if there is a block {x, y} in one partition and two blocks {x}, {y} in the other, and all other blocks in one partition are present in the other. There are n2 ways to choose the pair and Bn−2 ways to determine the other blocks. Corollary 1. The egf of the R(n, 1) numbers is

R(n, 1)

n≥1

Proof. Apply (2) with k = 2.

zn z2 z 2 ez −1 = B(z) = e . n! 2 2

The previous two results were warm-ups for the more technical results that follow.

294

F. Ruskey and J. Woodcock

Theorem 3. For fixed k, there are non-negative integer constants ck,j such that, for all n ≥ 1, 2k n R(n, k) = ck,j Bn−j . j √ j=(1+ 1+8k)/2

Proof. Any two partitions P and Q will have a largest subpartition X that is common to both P and Q. As a consequence, R(P, Q) = R(P \ X, Q \ X). In the sum above j represents n − |X|, given that R(P, Q) = k. Thus, ck,j is the number of pairs of j-element set partitions with no common blocks and that have Rand distance k. It remains to prove that the restrictions on the index of summation are correct. The lower bound in the summation followsfrom the fact that the maximum Rand distance between two partitions of n is n2 and thus k ≤ 2j . Solving the √ implied quadratic yields j ≥√(1 + 1 + 8k)/2, which gives us the lower bound. We hereafter use α = (1 + 1 + 8k)/2 for ease of reading. For the upper bound, consider two partitions P and Q of an j-set that have no block in common, and have Rand distance k. We claim that k ≥ j/2. Consider some arbitrary integer x ∈ {1, 2, . . . , j}. Since P and Q have no common blocks, there is some integer y that is in the same block as x in one partition, and in another block in the other partition. Thus we have j distinct ordered pairs (x, y), one for each diﬀerent value of x. At least j/2 of them have to be distinct as unordered pairs, and each such unordered pair contributes 1 to the Rand distance. Thus k ≥ j/2 as claimed. From this it follows that j ≤ 2k, which is the upper bound in the sum above. Theorem 4. For all n ≥ 1,

n n R(n, 2) = 6 Bn−3 + 6 Bn−4 . 3 4

Proof. Theorem 3 tells us that

n n R(n, 2) = c2,3 Bn−3 + c2,4 Bn−4 . 3 4

From the k = 2 row of Table 2 we then have the following two equations. 3 3 R(3, 2) = 6 = c2,3 B0 + c2,4 B−1 = c2,3 and 3 4 4 4 R(4, 2) = 30 = c2,3 B1 + c2,4 B0 = c2,3 4 + c2,4 . 3 4 This system of equations can be solved to obtain c2,3 = c2,4 = 6. Corollary 2. The egf of the R(n, 2) numbers is z zn z4 z4 R(n, 2) = z3 + B(z) = z 3 + ee −1 . n! 4 4 n≥1

The Rand and Block Distances of Pairs of Set Partitions

295

In a similar fashion we can solve systems of linear equations to obtain the following theorems and corollaries. Theorem 5. For all n ≥ 1, n n n n R(n, 3) = Bn−3 + 28 Bn−4 + 120 Bn−5 + 60 Bn−6 . 3 4 5 6 Corollary 3. The egf of the R(n, 3) numbers is n≥1

R(n, 3)

zn = n!

z3 7z 4 z6 + + z5 + 6 6 12

B(z) =

z3 7z 4 z6 + + z5 + 6 6 12

z

ee

−1

.

Theorem 6. For all n ≥ 1, the value of R(n, 4) is n n n n n 24 Bn−4 + 180 Bn−5 + 1560 Bn−6 + 2520 Bn−7 + 840 Bn−8 . 4 5 6 7 8 Corollary 4. The egf of the R(n, 4) numbers is z8 zn 3z 5 13z 6 z 7 R(n, 4) = z4 + + + + B(z). n! 2 6 2 48 n≥1

We summarize the known values of ck,j in Table 3. Although we don’t know the value of ck,j in general, we can determine a few speciﬁc inﬁnite sequences, which are given in the next lemma. Lemma 1. For all k ≥ 1, ck,2k =

(2k − 1)! (k − 1)!

and

ck,α = R(α, k).

Proof. For a pair of 2k element set partitions P and Q to have Rand distance k with no common blocks, the 2k elements must be paired, and each pair of elements is a block in either P or Q. Further, if {a, b} is a block in set P then set B contains the singleton blocks {a} and {b} and vice versa. Since the order of the blocks doesn’t matter, we can assume the blocks (pairs) are sorted by their smallest elements. So, for i = 1, 2, . . . , k, once we have chosen the elements for blocks 1, 2, . . . , i − 1, the ﬁrst element in block i must be the smallest remaining element and there are 2k − (2(i − 1) + 1) = 2k − 2i + 1 choices for the second element in block i. Thus the number of ways to pair the elements is k

(2k − 2i + 1) =

i=1

(2k − 1)! 2k−1 (k − 1)!

If we assume, without loss of generality, that a pair, say {a, b}, is in partition P , then there are 2k−1 unique ways to distribute the remaining pairs between P and Q. So we have cj,2k =

(2k − 1)! k−1 (2k − 1)! 2 . = − 1)! (k − 1)!

2k−1 (k

296

F. Ruskey and J. Woodcock

Table 3. Known values of ck,j for 2 ≤ j ≤ 11. The bold value at the beginning of each row is ck,α = R(α, k). k\j 2 3 4 5 6 7 8 9 10 11 1 1 2 6 6 3 1 28 120 60 4 24 180 1560 2520 840 5 6 210 1986 18900 63840 60480 15120 6 1 215 2780 28224 253246 1340640 2520000 1663200 7 60 2040 43365 463128 3998736 26878320 82328400 8 15 2610 38850 721728 8575200 74028240 554843520 9 10 1015 39060 778400 13061020 172444150 1568364600 10 1 465 28077 914480 17680572 270474480 3714220092 11 150 23478 619416 19277748 407335320 6281694045 12 35 13895 667450 19168422 482217540 10078945140 13 45 4410 376040 17848152 529667460 12553128060 14 15 1785 354060 13798458 530778780 15995950740 15 1 1295 167664 11437644 477563400 16021896264 16 252 113764 7906059 431141400 17216673870 17 210 41832 5852700 315103995 15141561930 18 140 19614 3492426 275308740 14124874940 19 105 6020 2369304 174009780 11315379955 20 21 6930 1186227 146107962 9400242852 21 1 3500 609336 80801970 7071057840 22 574 310662 60530130 5334533160 23 840 190008 31267440 3888920970 24 665 51303 25130325 2590267020 25 476 41832 10882746 1799914809 26 210 28476 6461280 1140678990 27 28 25480 3015180 753854310 28 1 7686 1926855 431506790 29 4104 1491300 290015550 30 2226 734820 169030620 31 3780 173610 110115390 32 2205 190575 50872635 33 1344 184905 33316140 34 378 134820 15268440 35 36 82152 12873861 36 1 21070 10432455 37 16200 6565900 38 15750 2310165 39 14910 1281555 40 13545 653169 41 7245 1240470 42 3270 824670 43 630 574035 44 45 214830 45 1 104302 46 62205 47 103950 48 70455 49 74250 50 45045 51 21945 52 7095 53 990 54 55 55 1

The Rand and Block Distances of Pairs of Set Partitions

Since Bi = 0 when i < 0, B0 = 1, and R(α, k) =

2k j=α

ck,j

i i

297

= 1,

α Bα−j = ck,α . j

Lemma 2. For all j ≥ 1, j c(j),j = R j, = 1. 2 2 For all j ≥ 4:

j j c(j)−1,j = R j, −1 = . 2 2 2

For all j ≥ 5: c(j )−2,j 2

j−1 j 2 = R j, −2 = . 2 2

For all j ≥ 2 + x: c(j)−x,j 2

j = R j, −x . 2

Proof. Omitted in this extended abstract. 3.2

The Numbers R(n,

n 2

− k) for Small k

We now consider the numbers at the bottom of the columns in Table 2. Clearly R(n, n2 ) = 1 (the pair is {1, 2 . . . n} and {1}{2} . . . {n}). Theorem 7. For all n ≥ 4, n n R(n, − 1) = , and R(3, 2) = 6. 2 2

Proof. For n ≥ 4, the two partitions are the full set {1, 2, . . . , n} and the partition consisting of one pair and n − 2 singleton sets. Theorem 8. For all n ≥ 5, n−1 n 1 2 R(n, − 2) = = n(n − 1)(n − 2)(n − 3), 2 2 8 and R(3, 1) = 3, R(4, 4) = 24.

298

F. Ruskey and J. Woodcock

Proof. For n ≥ 5 the two partitions are the full set {1, 2, . . . , n} and the partition consisting of two pairs and n − 4 singleton sets. The order of the two pairs does not matter so we have

R(n,

n 1 n n−2 − 2) = , 2 2 2 2

which can be shown to be equal to the two values given in the statement of the theorem. The numbers in Theorems 7 and 8 are a shifted versions of OEIS A000217 and OEIS A050534, respectively. Theorem 9. For all n ≥ 6, n n 1 n n−2 n−4 R(n, − 3) = + , 2 6 2 2 2 3 and R(4, 3) = 32, R(5, 7) = 60. Proof. For n ≥ 5 the two partitions are either the full set {1, 2, . . . , n} and the partition consisting of three pairs and n − 6 singleton sets, or the full set {1, 2, . . . , n} and the partition consisting of one triple and n − 3 singleton sets. Theorem 10. For fixed k there is a constant Kk such that R(n, n2 − k) is a polynomial of degree 2k in n for all n ≥ Kk . Proof. Omitted in this extended abstract.

Acknowledgements. We wish to thank Rod Canﬁeld for helpful discussions.

References 1. Canﬁeld, E.R.: Engel’s inequality for the Bell numbers. Journal of Combinatorial Theory, Series A 72, 184–187 (1995) 2. Filkov, V., Skiena, S.: Integrating Microarray Data by Consensus Clustering. International Journal on Artiﬁcial Intelligence Tools 13(4), 863–880 (2004) 3. Graham, R.L., Knuth, D.E., Patashnik, O.: Concrete Mathematics. AddisonWesley (1989) 4. Hubert, L.: Comparing Partitions. Journal of Classiﬁcation 2, 193–218 (1985) 5. Knuth, D.E.: The Art of Computer Programming, vol 4: Combinatorial Algorithms, Part 1. Addison-Wesley, Reading (2011) 6. Moser, L., Wyman, A.: An asymptotic formula for the Bell numbers. Transactions of the Royal Society of Canada III 49, 49–54 (1955) 7. Munagi, A.O.: Set Partitions with Successions and Separations. Int. J. Math and Math. Sc. 2005(3), 451–463 (2005)

The Rand and Block Distances of Pairs of Set Partitions

299

8. Rand, W.: Objective criteria for the evaluation of clustering methods. J. American Statistical Assoc. 66(336), 846–850 (1971) 9. Ruskey, F.: Simple Combinatorial Gray Codes Constructed by Reversing Sublists. In: Ng, K.W., Balasubramanian, N.V., Raghavan, P., Chin, F.Y.L. (eds.) ISAAC 1993. LNCS, vol. 762, pp. 201–208. Springer, Heidelberg (1993) 10. Stanley, R.R.: Enumerative Combinatorics, vol. 1. Wadsworth (1986)

On Minimizing the Number of Label Transitions around a Vertex of a Planar Graph ˇ Bojan Mohar and Petr Skoda Department of Mathematics, Simon Fraser University, 8888 University Drive, Burnaby, BC, V5A 1S6, Canada {mohar,pskoda}@sfu.ca

Abstract. We study the minimum number of label transitions around a given vertex v0 in a planar multigraph G in which the edges incident with v0 are labelled with integers 1, . . . , l, where the minimum is taken over all embeddings of G in the plane. For a ﬁxed number of labels, a linear-time FPT algorithm that (given the labels around v0 ) computes the minimum number of label transitions around v0 is presented. If the number of labels is unconstrained, then the problem of deciding whether the minimum number of label transitions is at most k is NP-complete. Keywords: label transitions, planar graph, ﬁxed-parameter tractable.

1

Introduction

Let G be a planar 2-connected multigraph. Suppose that the edges incident with a vertex v0 ∈ V (G) are labelled by integers 1, 2, . . . , l. We are interested in ﬁnding an embedding of G in the plane such that the number of label transitions around v0 is minimized. By a label transition we mean two edges that are consecutive in the local rotation around v0 and whose labels are diﬀerent. The motivation for this problem comes from investigations of minimum genus embeddings of graphs with small separations. In particular, to compute genus of a 2-sum of two graphs [11], see also [4], [5] and [10], it is necessary to know if a graph admits a planar embedding with only four label transitions (where l = 2). By deleting the vertex v0 from G and putting all edge labels onto vertices incident with the deleted edges, we obtain an equivalent formulation of the same problem. Both representations are useful and will be treated in this paper. Let H be the graph obtained from G by deleting v0 . Note that H is connected. For each v ∈ V (H) let λ(v) be the set of all labels of edges joining v and v0 in G. If v is not a neighbor of v0 , then λ(v) = ∅. The pair (H, λ) carries the whole information about G and the labels of edges around v0 (except for multiplicity of the edges with the same label). Let L be a set of labels. The graph H together with the labelling λ : V (H) → be the graph obtained from a labelled graph H 2L is a labelled graph. Let H by adding a vertex v0 to H and joining it to each vertex v by |λ(v)| edges and labelling these edges by elements of λ(v). The vertex v0 is called the center of C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 300–309, 2011. c Springer-Verlag Berlin Heidelberg 2011

Minimizing the Number of Label Transitions

301

If the graph H is planar (which can be checked in linear time, see [7]), we H. are back to an instance of the original problem. v0 , and the labelling of edges incident with v0 , consider Given (H, λ) or H, in the plane (all embeddings in this paper are into the an embedding Π of H plane). Deﬁne the label sequence Q = Q(Π) of Π to be the cyclic sequence of labels of edges coming to v0 in the clockwise order of the local rotation around v0 in Π. The origin of a label L ∈ Q that came from an edge vv0 is the vertex v. A label transition in Q is a pair of (cyclically) consecutive labels A, B in Q such that A = B. The number of transitions τ (Q) of Q is the number of label of H is the minimum τ (Q(Π)) transitions in Q. The number of transitions τ (H) taken over all planar embeddings Π of H. When considering label transitions, are used interchangeably, i.e., τ (H) ≡ τ (H). the graphs H and H The following problem will be of our main interest: Min-Trans. Given a planar 2-connected multigraph G with edges incident to a ﬁxed vertex v0 labelled by 1, . . . , l and an integer k, determine if τ (G) ≤ k. In the following, we show that Min-Trans can be solved in linear time when the number of labels l is ﬁxed. Theorem 1. For every fixed integer l, there is a linear-time algorithm that determines the minimum number of transitions τ (G) of a given planar 2-connected multigraph G with edges incident to a fixed vertex v0 labelled by 1, . . . , l. This algorithm is fixed-parameter tractable. We also show that this is best possible in the sense that Min-Trans becomes NP-complete when l is part of the input. Theorem 2. Min-Trans is NP-complete if the number of labels l is unconstrained. The problem remains NP-complete even when each label occurs precisely twice.

2

Bounded Number of Labels

In this section we develop most of the formalism needed to prove Theorem 1. In particular, it is observed that we can restrict our attention to a special class of cactus graphs; also, the basic structure of the algorithm is presented. Let H and G be labelled graphs. If every label sequence of H is also a label sequence of G, and vice versa, then H and G are said to be equivalent . A connected graph G is called a cactus if every block of G is either an edge or a cycle. A labelled cactus G is leaf-labelled if every endblock of G is an edge, every vertex of G has at most one label, and a vertex of G is labelled if and only if it is a leaf. The following lemma shows that it is enough to prove Theorem 1 for the case when H is a leaf-labelled cactus. The main idea is that the “interiors” of 2-connected components are not signiﬁcant for our problem. The proof is given in the full paper.

302

ˇ B. Mohar and P. Skoda

is planar, then there exLemma 1. Let H be a connected labelled graph. If H ists a leaf-labelled cactus G which is equivalent to H. Furthermore, G can be constructed in linear time. In our algorithm, we use a rooted version of graphs. A root r in a leaf-labelled cactus H can be any vertex of H. The root is marked by a special label Lr ∈ L. We then speak of a rooted leaf-labelled cactus, or simply a cactus (H, r). The restriction on labels in a rooted leaf-labelled cactus is slightly relaxed, every leaf still has a unique label (possibly Lr ) but a non-leaf vertex can also be labelled if it is the root. When a label sequence Q of H is cut at the label Lr (and Lr is deleted), we obtain a linear sequence called a rooted label sequence of H. Let Q(H) denote the set of all rooted label sequences of H. Similarly to the unrooted graphs, two rooted graphs are equivalent if they admit the same rooted label sequences. There exists a tree-like structure, called a PC-tree (see [12]), that captures all embeddings of a cactus in the plane. PC-trees and their rooted version, PQ-trees, are used in testing planarity [2]. We note that Min-Trans reduces to the problem of minimizing the number of label transitions over all cyclic permutations of the leaves of a PC-tree that are compatible with the PC-tree. where there is the ﬂipped embedding Π of H For every embedding Π of H each clockwise rotation in Π is a counter-clockwise rotation in Π . The following lemma formulates this for a rooted label sequence of H. For a linear sequence Q, let QR denote the sequence obtained by reversing Q. Lemma 2. Let (H, r) be a rooted leaf-labelled cactus. If Q is a rooted label sequence of H, then the reversed sequence QR is also a rooted label sequence of H. The following lemmas establish a recursive construction of rooted label sequences. Let us recall that for a cut vertex v of H, v-bridge in H is a subgraph of H consisting of a connected component of H − v together with all edges joining this component and v. Lemma 3. Let (H, r) be a rooted leaf-labelled cactus where r is a leaf. Let u be the neighbor of r. If u is labelled, then H has a unique rooted label sequence Q = λ(u). Otherwise, (H, r) is equivalent to (H − r, u). Proof. If u is labelled, then u is a leaf and H contains precisely one label λ(u) and therefore λ(u) is the unique rooted label sequence of H. Otherwise, take an embedding of H − r in the plane. Recall that u as the root of H − r is given a special label Lu and thus there is an edge connecting u and the center of H − r. with the same rooted label Subdividing this edge gives a planar embedding of H sequence. Similarly, one can obtain an embedding of H − r from an embedding of H with the same rooted label sequence. Lemma 4. Let (H, r) be a rooted leaf-labelled cactus with r in a cycle C of length k. For v ∈ V (H), let Dv be the union of v-bridges in H that do not contain C.

Minimizing the Number of Label Transitions

303

If Dr is empty, then every rooted label sequence Q of H can be partitioned into k − 1 (possibly empty) consecutive parts Pv , v ∈ V (C) \ {r}, where Pv is a rooted label sequence of (Dv , v) and Pv appear in Q in one of the two cyclic orders corresponding to the two orientations of C. Proof. Let Q be a rooted label sequence of H such that the conclusion of the lemma is not true. If labels contained in one of the subgraphs Dv do not form a consecutive subsequence of Q, we obtain a contradiction as in the proof of Lemma 5. Suppose now that Q contains a cyclic subsequence L1 L3 L2 L4 (in this order) such that the origins u1 , . . . , u4 of L1 , . . . , L4 are in Dv1 , . . . , Dv4 that and v1 , . . . , v4 appear on C in this order. Let Π be an embedding of H corresponds to Q and let G be the graph obtained from H by deleting the center v0 and adding an edge uv for every two consecutive edges uv0 , vv0 in the local rotation around v0 . Π can be easily modiﬁed to a planar embedding Π of G. It is easy to check that u1 , . . . , u4 , v1 , v3 are the branch-vertices of a subdivision of K3,3 in G, a contradiction with G being planar (see [9]). Lemma 5. Let (H, r) be a rooted leaf-labelled cactus with r a cut vertex and let B1 , . . . , Bk be the r-bridges in H. Every rooted label sequence of H can be partitioned into k consecutive parts where each of the k parts is a rooted label sequence of one of (Bi , r). Furthermore, if Qi is a rooted label sequence of (Bi , r) (1 ≤ i ≤ k) and (i1 , . . . , ik ) is a permutation of (1, . . . , k), then the concatenation Qi1 Qi2 · · · Qik is a rooted label sequence of H. Proof. Suppose for a contradiction that there is a rooted label sequence Q of H with a cyclic subsequence L1 L2 L3 L4 (in this order) such that L1 and L3 have origins in B1 and L2 , L4 have origins outside B1 . Let Π be an embedding of that corresponds to Q and v1 , . . . , v4 the origins of L1 , . . . , L4 . Let G be the H by deleting the center v0 and adding an edge uv for every graph obtained from H two consecutive edges uv0 , vv0 in the local rotation around v0 . The embedding Π can be extended to a planar embedding Π of G such that the added edges form a facial cycle. Since v1 and v3 are in B1 , there is a path P in B1 − r joining v1 and v3 . Similarly, there is a path Q in H − (B1 − r) joining v2 and v4 . Since P and Q are disjoint and both embedded inside C, their endvertices cannot interlace on C. This contradiction proves the claim and implies that all labels in each Bi appear consecutively in every rooted label sequence of H. This proves the ﬁrst part of the lemma. The second part is an easy consequence of the fact that arbitrary embeddings i (1 ≤ i ≤ k) can be combined into an embedding of H so that the cyclic of B order of r-bridges around r is Bi1 , Bi2 , . . . , Bik . We are interested in rooted label sequences that have minimum number of transitions. But to combine them later on, it is important to know what is the ﬁrst and the last label in the rooted label sequence. This motivates the following deﬁnition. Let Q be a set of (linear) label sequences. We say that a sequence Q ∈ Q is AB-minimal for labels A, B ∈ L, if τ (AQB) = min{τ (ASB) | S ∈ Q}

304

ˇ B. Mohar and P. Skoda

where AQB is the sequence obtained from Q by adding labels A and B at the beginning and at the end of Q, respectively. A rooted label sequence Q of (H, r) is AB-minimal if Q is AB-minimal in Q(H). Minimal sequences are composed of minimal sequences as shows the following lemma. This allows us to restrict our attention to minimal sequences. The proof is not diﬃcult and is included in the full paper. Lemma 6. Let Q be the set of all sequences that are concatenations of a sequence in Q1 and a sequence in Q2 (in this order). Then for A, B ∈ L, every AB-minimal sequence Q in Q is a concatenation of an AC-minimal sequence in Q1 and a CB-minimal sequence in Q2 for some label C ∈ L. Let (H, r) be a rooted leaf-labelled cactus. We can describe “optimal” embed in the plane by a set of AB-minimal rooted label sequences of H, dings of H one for each pair of labels A, B ∈ L. Let ρH [A, B] be the minimum number of label transitions in an AB-minimal rooted label sequence of H. Note that the values of ρH diﬀer by at most 2 since adding labels A and B to a sequence increases the number of label transitions by at most 2. Hence we can represent ρH by the minimum ρH [A, B] over all labels A, B and by the individual diﬀerences from this minimum. Let nH be the minimum number of label transitions in a rooted label sequence of H and let pH [A, B] = ρH [A, B] − nH be the type of H. Note that pH [A, B] ∈ {0, 1, 2}. The type pH of H is viewed as a function 2 pH : L × L → {0, 1, 2} and also as a number between 1 and t ≡ 3l . Note that the number t of diﬀerent types is a constant. We will show that cacti of the same type “behave” the same. We call the pair (pH , nH ) the descriptor of H. For simplicity, we also call ρH the descriptor of H since it is easy to compute ρH from (pH , nH ) and vice versa. Note that the “unrooted” number of transitions τ (H) can be obtained from the descriptor of H as τ (H) = min ρH [A, A]. A∈L

It is time to consider how a descriptor of a rooted leaf-labelled cactus can be computed from descriptors of its subtrees. The ﬁrst non-trivial case is when the root lies on a cycle. This case is easily dealt with using Lemmas 4 and 6 since minimal sequences of the subtrees attached to the cycle have ﬁxed cyclic order. The following lemma is proven in the full paper. Lemma 7. Let (H, r) be a rooted leaf-labelled cactus such that r is a vertex of degree 2 in a cycle C of length k in H, and let Bv , v ∈ V (C), be the union of v-bridges in H that do not contain C. Then the descriptor of H can be computed from descriptors of (Bv , v), v ∈ V (C), in time O(l3 k). Computing the descriptor of a leaf-labelled cactus rooted at a cut vertex turns out to be main issue. Let (H, r) be a rooted leaf-labelled cactus where r is a cut vertex of H and let B1 , . . . , Bk be the r-bridges in H. Let bH (i) be the number of r-bridges in H of type i, i = 1, . . . , t. We view bH as an integer vector t in Zt with b (i) = k. A non-negative integer vector b ∈ Zt is called a H i=1

Minimizing the Number of Label Transitions

305

t bridge vector and sum(b) = i=1 b(i) the sum of b. Note that there are at most O(k t+1 ) diﬀerent non-negative integer vectors b in Zt with the sum at most k. Each bridge vector b describes a problem to be solved: How to order k = sum(b) bridges of types given by b around a vertex so that the number of label transitions on the boundaries between bridges is minimized. For ﬁxed labels A, B, let RAB (b) be the set sequences of k + 1 labels A0 , A1 , . . . , Ak such that A0 = A and Ak = B. For an ordering of types in b, P = p1 , p2 , . . . , pk , and k a sequence R ∈ RAB (b), R = L0 , . . . , Lk , let m(P, R) = i=1 pi [Li−1 , Li ]. Let mb [A, B] be the the minimum m(P, R) taken over all orderings P of b and all sequences R ∈ RAB (b). This minimum depends only on the types of the bridges, not on the minimum number of label transitions of the bridges. The fact that computation of mb is a solution to the posed problem and gives a way how to compute the descriptor of a leaf-labelled cactus rooted at a cutvertex is not diﬃcult to see. The precise relation of mb and the descriptor is stated in the following lemma and the details of the proof are provided in the full paper. Lemma 8. Let (H, r) be a rooted leaf-labelled cactus and let B1 , . . . , Bk be the r-bridges in H. Then ρH [A, B] = mbH [A, B] +

k

nBi .

i=1

This gives rise to the following dynamic program. Given a non-zero bridge b vector, there are only t possibilities for the type p of the ﬁrst bridge whose label sequence starts a minimal label sequence of H (the existence of such a bridge follows from Lemma 5). By deleting the type p from b, we obtain a smaller bridge vector bp . The array mbp is computed recursively and then combined with p to obtain mb . However, using this approach would yield a polynomialtime algorithm that is not ﬁxed parameter tractable (since there are Θ(nt ) bridge vectors of sum at most n). In the next section, we sidestep this problem and present a linear-time algorithm for computing mb . Let us describe an algorithm for Min-Trans that, as we show in the next section, yields Theorem 1. We assume that the input graph has at least 3 labels to avoid trivialities. Algorithm 1 Input: a labelled graph G Output: minimal number of transitions τ (G)

4

Construct the leaf-labelled cactus H that is equivalent to G (Lemma 1). Root H at an arbitrary unlabelled vertex r. ρH ←− Descriptor(H, r). Compute τ (G) from ρH .

5

return τ (G).

1 2 3

306

ˇ B. Mohar and P. Skoda

Function. Descriptor(H, r) Input: a rooted leaf-labelled cactus (H, r) Output: the descriptor of H, ρH 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

switch according to the role of r do case r is a leaf and its neighbor u is labelled Note that F has just two vertices r and u. The descriptor ρH corresponds to the single-label sequence λ(u). case r is a leaf and its neighbor u is not labelled ρH ←− Descriptor(H − r, u). case r is in a cycle C and is of degree two foreach v ∈ V (C) \ {r} do Let Bv be the union of all v-bridges that do not contain C. ρBv ←− Descriptor(Bv , v). Use Lemma 7 to compute ρH from ρBv . case r is a cut vertex foreach r-bridge Bi do ρBi ←− Descriptor(Bi , r). Construct the bridge vector b from ρBi . Compute mb . Use Lemma 8 to compute ρH from mb and ρBi . return ρH .

Note that throughout Algorithm 1, each vertex of H appears as a root in Descriptor at most twice; once as a cut vertex and once either as a leaf or on a cycle. Therefore, each of the cases can happen at most n times, n = |V (H)|, and the basic recursion runs in linear time. By Lemma 7, the case when the root is in a cycle takes time O(l 3 n) since the sum of lengths of all cycles is bounded by n. If we can compute mb for a bridge vector b in constant time, then Algorithm 1 runs in linear time. This is the goal of the next section.

3

Dealing with Bridge Vectors

In the previous section we have sketched an algorithm for computing the minimum number of label transitions in a planar multigraph. In this section we outline an algorithm for computing mb of a bridge vector b in constant time (Lemma 11), the last ingredient for the proof of Theorem 1. We start by observing that mb is bounded independently of the bridge vector b. Let us recall that 2 t = 3l . Lemma 9. Let b be a bridge vector. Then for A, B ∈ L, mb [A, B] ≤ 2t + 2.

Minimizing the Number of Label Transitions

307

Proof. For every type p = 1, . . . , t, there are labels Ap , Bp such that p[Ap , Bp ] = 0. By Lemma 2, p[Bp , Ap ] = 0 as well. Let k = sum(b) and let P = p1 , p2 , . . . , pk be the sequence of types in b in the increasing order. Let R be the sequence of labels L0 , L1 , . . . , Lk be the sequence of labels such that L0 = A, Lk = B, and for i = 1, . . . , k − 1, Li = Api if i is odd and Li = Bpi if i is even. Note that for i = 2, . . . , k − 1, if pi−1 = pi , then either pi [Li−1 , Li ] = pi [Api , Bpi ] or pi [Li−1 , Li ] = pi [Bpi , Api ] and so pi [Li−1 , Li ] = 0. Since pi [A , B ] ≤ 2 for all labels A , B and there are at most t − 1 transitions between diﬀerent types, m(P, R) =

k

pi [Li−1 , Li ] ≤ 2(t − 1) + 4.

i=1

Thus, mb [A, B] ≤ m(P, R) ≤ 2t + 2.

Let K be the complete edge-colored and edge-weighted multigraph on vertex set L where two vertices A, B ∈ L are joined by t edges such that pth edge is colored by p and given weight p[A, B]. Note that there are t loops at every vertex of K. For a walk W in K, the weight w(W ) of W is the sum of weights of edges in W . Let P = p1 , . . . , pk be an ordering of types in a bridge vector b and R = L0 , . . . , Lk be a sequence of labels. The sequences P , R generate a walk W in K of length k where in the ith step the edge Li−1 Li with color pi is used. The weight of W is m(P, R). The walk W uses b(p) edges of color p. The converse statement also holds: A walk W that uses b(p) edges of color p gives an ordering P of types in b and a label sequence R such that m(P, R) = w(W ). This gives the following lemma. Lemma 10. Let b be a bridge vector, A, B labels, and w an integer. There is an AB-walk W of weight w in K such that W uses b(p) edges of color p if and only if there is an ordering P of types in b and a label sequence R = A, . . . , B such that m(P, R) = w. In order to show that mb can be computed in constant time, a bridge vector b equivalent to b such that the sum of b is bounded by a constant is found. The array mb (and thus also mb ) is then computed in constant time by brute force. The main idea arise from the correspondence between orderings of bridge vectors and walks in the constant-sized graph K. Given a walk W in K with enough edges, it is shown that one can ﬁnd a set of disjoint cycles in W that contain even number of edges of each color. The removal of the cycles then yields a smaller version of the problem that can be easily tested for extension to the original problem. This will be elaborated in detail in the full paper. We obtain the following lemma showing that, for a bridge vector b, the array mb can be computed in constant time. Lemma 11. Let b be a bridge vector. Then for labels A, B, mb [A, B] can be 2 computed in time O(l2 t(l2 t)4l t ).

308

ˇ B. Mohar and P. Skoda

It is likely that a ﬁxed-parameter tractable solution can also be described by the use of min-max algebra for shortest paths, see [3] and [1], [6]. Finally, let us conclude the section by sketching the proof of Theorem 1. Proof (of Theorem 1). The proof of the correctness of Algorithm 1 consists of several lemmas. Lemma 1 shows that any input graph can be transformed to an equivalent leaf-labelled cactus. Lemmas 3, 4, and 5 justify our recursive approach for computing the descriptors of rooted cacti. The linearity of Algorithm 1 was established at the end of Sec. 2 provided that we can compute mb in constant time. The cornerstone of the argument was that Lemma 8 allows us to deal with bridge vectors instead to collection of bridges. t By Lemma 11, we can compute mb for a bridge vector in time O(l4 t(l2 t)4l ) (applying the lemma for each pair of labels). This is the slowest part of the algorithm and, since there are at most n cut-vertices in the graph, the algorithm t runs in time O(l 4 t(l2 t)4l n).

4

NP-Completeness

When the number of labels is not bounded, Min-Trans becomes harder. In this section we give a proof of Theorem 2 by providing a polynomial-time reduction from the Hamiltonian Cycle Problem (see [8]). Proof (of Theorem 2). An embedding of G with small number of transitions is a certiﬁcate for Min-Trans which asserts that Min-Trans is in NP. To show that Min-Trans is NP-complete, we give a polynomial-time reduction from the Hamiltonian Cycle Problem. Let G be a graph of order n and let H be the graph whose vertex set is V (H) = {v1 } ∪ V (G) ∪ (E(G) × {0, 1}). We connect v1 to each vertex in V (G) and for each edge uv ∈ E(G) we join (uv, 0) with u and (uv, 1) with v. Only the leaves of H are labelled. Vertex (e, i) is labelled e. Thus, the number of labels is |E(G)| and each label occurs precisely twice. It is immediate that H can be constructed in polynomial time in |V (G)|. We ask if the number of transitions τ (H) is smaller or equal to k for k=

(deg(v) − 1) = 2|E(G)| − |V (G)|.

v∈V (G)

with τ (Π) ≤ k. The In the aﬃrmative, there is a planar embedding Π of H local rotation around v1 gives a cyclic order π of vertices of G. Root H at v1 . By Lemma 5, every label sequence of H is a concatenations of seqeuences Qv , v ∈ V (G), such that Qv consists of labels on leaves of H attached to v. Since labels in Qv are the edges adjacent to v, they are diﬀerent and thus τ (Qv ) = deg(v) − 1. Hence, τ (H) ≥ (deg(v) − 1) = k. (1) v∈V (G)

Minimizing the Number of Label Transitions

309

To get an equality here, we need that there are no more label transitions between neighboring sequences Qv . Let e1 (v) and e2 (v) be the ﬁrst and the last label in Qv . We have an equality in (1) if and only if for every two consecutive vertices u, v in π, e1 (u) = e2 (v). This gives a cyclic sequence C of n edges that visits every vertex precisely once. Hence C is a hamiltonian cycle in G. On the other hand, a hamiltonian cycle C in G gives a cyclic order on vertices of G. This and the cyclic order of the edges of C give a construction of an with τ (H) = k. embedding of H

References 1. Butkoviˇc, P., Cuninghame-Green, R.A.: On matrix powers in max-algebra. Linear Algebra Appl. 421, 370–381 (2007) 2. Chiba, N., Nishizeki, T., Abe, S., Ozawa, T.: A linear algorithm for embedding planar graphs using PQ-trees. J. Comput. Syst. Sci. 30, 54–76 (1985) 3. Cuninghame-Green, R.: Minimax Algebra, vol. 166. Springer, Heidelberg (1979) 4. Decker, R.W., Glover, H.H., Huneke, J.P.: The genus of the 2-amalgamations of graphs. Journal of Graph Theory 5(1), 95–102 (1981) 5. Decker, R.W., Glover, H.H., Huneke, J.P.: Computing the genus of the 2amalgamations of graphs. Combinatorica 5, 271–282 (1985) 6. Gavalec, M.: Linear matrix period in max-plus algebra. Linear Algebra and its Applications 307(1-3), 167–182 (2000) 7. Hopcroft, J., Tarjan, R.: Eﬃcient planarity testing. J. ACM 21, 549–568 (1974) 8. Karp, R.: Reducibility among combinatorial problems. In: Miller, R., Thatcher, J. (eds.) Complexity of Computer Computations, pp. 85–103. Plenum Press (1972) 9. Kuratowski, K.: Sur le probl`eme des courbes gauches en topologie. Fund. Math. 15, 271–283 (1930) 10. Mohar, B., Thomassen, C.: Graphs on Surfaces. Johns Hopkins Univ. Press, Baltimore (2001) ˇ 11. Mohar, B., Skoda, P.: Obstructions for xy-alternating embeddings of graphs in surfaces (in preparation) 12. Shih, W.K., Hsu, W.L.: A new planarity test. Theor. Comput. Sci. 223, 179–191 (1999)

A New View on Rural Postman Based on Eulerian Extension and Matching Manuel Sorge , Ren´e van Bevern , Rolf Niedermeier, and Mathias Weller Institut f¨ur Softwaretechnik und Theoretische Informatik, TU Berlin {manuel.sorge,rene.vanbevern,rolf.niedermeier,mathias.weller}@tu-berlin.de

Abstract. We provide a new characterization of the NP-hard arc routing problem Rural Postman in terms of a constrained variant of minimum-weight perfect matching on bipartite graphs. To this end, we employ a parameterized equivalence between Rural Postman and Eulerian Extension, a natural arc addition problem in directed multigraphs. We indicate the NP-hardness of the introduced matching problem. In particular, we use it to make some partial progress towards answering the open question about the parameterized complexity of Rural Postman with respect to the number of weakly connected components in the graph induced by the required arcs. This is a more than thirty years open and long-time neglected question with significant practical relevance.

1 Introduction The Rural Postman (RP) problem with its special case, the Chinese Postman problem, is a famous arc routing problem in combinatorial optimization. Given a directed, arc-weighted graph G and a subset R of its arcs (called “required arcs”), the task is to find a minimum-cost closed walk in G that visits all arcs of R. The manifold practical applications of RP include snow plowing, garbage collection, and mail delivery [1, 2, 3, 6, 7, 15]. Recently, it has been observed that RP is closely related (more precisely, “parameterized equivalent”) to the arc addition problem Eulerian Extension (EE). Here, given a directed and arc-weighted multigraph G, the task is to find a minimum-weight set of arcs to add to G such that the resulting multigraph is Eulerian [10, 4]. RP and EE are NP-hard. In fact, their mentioned parameterized equivalence means that many algorithmic and complexity-theoretic results for one of them transfer to the other. In particular, this gives a new view on RP, perhaps leading to novel approaches to attack its computational hardness. A key issue in both problems is to determine the influence of the number c of connected components1 on each problem’s computational complexity [4, 9, 11, 13, 14]. Indeed, Frederickson [9] observed that RP (and, thus, EE) is polynomial-time solvable when c is constant. However, this left

Partially supported by the DFG, project AREG, NI 369/9 and project PABI, NI 369/7. Supported by the DFG, project AREG, NI 369/9. Supported by the DFG, project DARE, NI 369/11. 1 More precisely, c refers to the number of weakly connected components in the input for EE and the number of weakly connected components in the graph induced by the required arcs for RP.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 310–323, 2011. c Springer-Verlag Berlin Heidelberg 2011

A New View on Rural Postman Based on Eulerian Extension and Matching

311

open whether c influences the degree of the polynomial or whether RP can be solved in f (c) · nO(1) time for some exponential function f . In other words, it remained open whether RP and EE are fixed-parameter tractable2 with respect to the parameter c [4]. We remark that this parameter is presumably small in a number of applications [4, 7, 9], strongly motivating to attack this seemingly hard open question. Our Results. In this work, we contribute new insights concerning the seemingly hard open question whether RP (and EE) is fixed-parameter tractable with respect to the parameter “number of components”. To this end, our main contribution is a new characterization of RP in terms of a constrained variant of minimum-weight perfect matching on bipartite graphs. Referring to this problem as Conjoining Bipartite Matching (CBM), we show its NP-hardness and a parameterized equivalence to RP and EE. Moreover, we show that CBM is fixed-parameter tractable3 when restricted to bipartite graphs where one partition set has maximum vertex degree two. This implies corresponding fixedparameter tractability results for relevant special cases of RP and EE which would probably have been harder to formulate and to detect using the definitions of these problems. Indeed, we hope that CBM might help to finally answer the puzzling open question concerning the parameterized complexity of RP with respect to the number of components. In this paper we consider decision problems. However, our results easily transfer to the corresponding optimization problems. For the sake of notational convenience and justified by the known parameterized equivalence [4], most of our results and proofs refer to EE instead of RP. Due to space constraints, most proofs are deferred to a full version of the paper.

2 Preliminaries and Preparations Consider a directed multigraph G = (V, A), comprising the vertex set V and the arc multiset A. For notational convenience, we define a component graph G as a clique whose vertices one-to-one correspond to the weakly connected components of G. Since we never consider strongly connected components, we omit the adverb “weakly”. A walk W in G is a sequence of arcs in G such that each arc ends in the same vertex as the next arc starts in. We use V(W) and A(W) to refer to the set of vertices in which arcs of W start or end, and the multiset of arcs of W, respectively. The first vertex in the sequence is called the initial vertex of the walk and the last vertex in the sequence is called the terminal vertex of the walk. A walk W in G such that A(W) is a submultiset of the multiset A(G) is called a trail of G. A trail T in G such that every vertex in G has at most two incident arcs in A(T ) is called a cycle if the initial and terminal vertices of T are equal, and path otherwise. If G is clear from the context, we omit it. We use balance(v) indeg(v) − outdeg(v) to denote the balance of a vertex v in G and IG+ and IG− to denote the set of all vertices v in G with balance(v) > 0 and balance(v) < 0, respectively. A vertex v is balanced if balance(v) = 0. 2 3

See Section 2 and the literature [5, 8, 12] for more on parameterized complexity analysis. The corresponding parameter “join set size” measures the instance’s distance from triviality and translates to the parameter “number of components” in equivalent instances of EE and RP.

312

M. Sorge et al.

Our results are in the context of parameterized complexity [5, 8, 12]. A parameterized problem L ⊆ Σ ∗ × is called fixed-parameter tractable (FPT) with respect to a parameter k if (x, k) ∈ L is decidable in f (k) · |x|O(1) time, where f is a computable function only depending on k. We consider two types of parameterized reductions between problems: A polynomialparameter polynomial-time many-one reduction (≤PPP m -reduction) from a parameterized problem L to a parameterized problem L is a polynomial-time computable function g such that (x, k) ∈ L ⇔ (x , k ) ∈ L , with (x , k ) g(x, k), and k ≤ p(k), where p is a polynomial only depending on k. If such a reduction exists, we write L ≤PPP m L . A FPT parameterized Turing reduction (≤T -reduction) from a parameterized problem L to a parameterized problem L is an algorithm that decides (x, k) ∈ L in f (k) · |x|O(1) time, where queries of the form (x , g(k)) ∈ L are assumed to be decidable in O(1) time and f, g are functions solely depending on k. If such a reduction exists, we write L ≤FPT T L . If FPT FPT FPT L ≤T L and L ≤T L, then we say that L and L are ≤T -equivalent. Note that every FPT FPT ≤PPP m -reduction is a ≤T -reduction. Also, if L ∈ FPT and L ≤T L , then L ∈ FPT. In this work, we consider the problem of making a given directed multigraph Eulerian by adding arcs. A directed multigraph G is Eulerian if it is connected and each vertex is balanced. An Eulerian extension E for G = (V, A) is a multiset over V × V such that G = (V, A ∪ E) is Eulerian. Eulerian Extension (EE) Input: A directed multigraph G = (V, A), an integer ωmax , and a weight function ω : V × V → [0, ωmax ] ∪ {∞}. Question: Is there an Eulerian extension E of G whose weight is at most ωmax ? In the context of EE we speak of allowed arcs a ∈ V × V, if ω(a) < ∞. 2.1 Preprocessing Routines A polynomial-time preprocessing routine for EE introduced by Dorn et al. [4] ensures that the balance of every vertex is in {−1, 0, 1}. This simplifies the problem and helps in constructions later on. Dorn et al. [4] showed that the corresponding transformation can be computed in O(n(n + m)) time. In the following, we assume that all input instances of EE have been transformed thusly, and hence, we assume that the following observation holds. Observation 1. Let v be a vertex in a pre-processed instance of EE. Then, balance(v) ∈ {−1, 0, 1}. We use a second preprocessing routine to make further observations about trails in Eulerian extensions. This preprocessing is a variant of the algorithm used by Dorn et al. [4] to remove isolated vertices from the input graph. Basically, it replaces the weight of a vertex pair by the weight of the “lightest” path in the graph (V, V × V) with respect to ω. Note that the resulting weight function respects the triangle inequality. Dorn et al. [4] showed that this transformation can be computed in O(n3 ) time. In the following, we assume all input instances of EE to have gone through this transformation, and hence, we assume that the following holds.

A New View on Rural Postman Based on Eulerian Extension and Matching

313

Observation 2. Let ω be a weight-function of a pre-processed instance of EE. Then, ω respects the triangle inequality, that is, for each x, y, z, it holds that ω(x, z) ≤ ω(x, y) + ω(y, z). In the subsequent sections, we use this preprocessing in parameterized algorithms and reductions. To this end, note that both transformations are parameter-preserving, that is, they do not change the number of connected components. The presented transformations lead to useful observations regarding trails in Eulerian extensions. For instance, we often need the following fact. Observation 3. For any Eulerian extension E of G, there is an Eulerian extension E of at most the same weight such that any path p and any cycle c in E does not visit a connected component of G twice, except for the initial and terminal vertex of p and c. 2.2 Advice Since Eulerian extensions have to balance every vertex, they contain paths starting in vertices with positive balance and ending in vertices with negative balance. These paths together with cycles have to connect all connected components of the input graph. In order to reduce the complexity of the problem, we use advice as additional information on the structure of optimal Eulerian extensions. Advice consists of hints which specify that there must be a path or cycle in an Eulerian extension that visits connected components in a distinct order. Hints however do not specify exactly which vertices these paths or cycles visit. For an example of advice, see Figure 1a. Formally, a hint for a directed multigraph G = (V, A) is an undirected path or cycle t of length at least one in the component graph G together with a flag determining whether t is a cycle or a path.4 Depending on this flag, we call the hints cycle hints and path hints, respectively. We say that a set of hints H is an advice for the graph G if the hints are edge-disjoint.5 For a trail t in G, G (t) is the trail in G that is obtained by making t undirected and, for every connected component C of G, substituting every maximum length subtrail t of t with V(t ) ⊆ C by the vertex in G corresponding to C. We say that a path p in the graph (V, V × V) realizes a path hint h if G (p) = h and the initial vertex of p has positive balance and the terminal vertex has negative balance in G. We say that a cycle c in the graph (V, V × V) realizes a cycle hint h if G (c) = h. We say that an Eulerian extension E heeds the advice H if it can be decomposed into a set of paths and cycles that realize all hints in H. A topic in this work is how having an advice helps in solving an instance of Eulerian extension. In order to discuss this, we introduce the following version of EE. Eulerian Extension with Advice (EEA) Input: A directed multigraph G = (V, A), an integer ωmax , a weight function ω : V × V → [0, ωmax ] ∪ {∞}, and advice H. Question: Is there an Eulerian extension E of G that is of weight at most ωmax and heeds the advice H? 4 5

The flag is necessary because a hint to a path in G may correspond to a cycle in G. Note that there is a diﬀerence between advice in our sense and the notion of advice in computational complexity theory. There, an advice applies to every instance of a specific length.

314

M. Sorge et al.

We will see that the hard part of computing an Eulerian extension that heeds a given advice H is to choose initial and terminal vertices for path hints in H. In fact, it is possible to compute optimal realizations for all cycle hints in any given advice in O(n3 ) time. Observation 4 ([16]). Let (G, ωmax , ω, H) be an instance of EEA. In O(n3 ) time we can compute an equivalent instance (G , ωmax , ω, H ) such that H does not contain a cycle hint. Furthermore, the number of components at most decreases. In this regard we note that we can compute an optimal realization of a path hint for given endpoints in the corresponding directed multigraph. This is possible in quadratic time, mainly using Observation 2, forbidding arcs contained in one connected component, and Dijkstra’s algorithm. Observation 5. Let (G, ωmax , ω, H) be an instance of EE, let h ∈ H be a path hint and let Ci , Ct be the connected components of G that correspond to the endpoints of h. Furthermore, let (u, v) ∈ (Ci × Ct ) ∩ (IG+ × IG− ). Then, we can compute a minimum-weight realization of h with initial vertex u and terminal vertex v in O(n2 ) time. Since we want to derive Eulerian extensions from an advice and every Eulerian extension for a graph connects all of the graphs connected components, we are mainly interested in “connecting” advice. We say that an advice for a directed multigraph G is connecting, if its hints connect all vertices in G . Furthermore, if there is no connecting advice H with H ⊂ H, then H is called minimal connecting advice. We consider the following restricted version of EEA that allows only minimal connecting advice (note that, by Observation 4, we can assume the given advice to be cycle-free). Eulerian Extension with Cycle-free Minimal Connecting Advice (EE∅CA) Input: A directed multigraph G = (V, A), an integer ωmax , a weight function ω : V × V → [0, ωmax ] ∪ {∞}, and minimal connecting cycle-free advice H. Question: Is there an Eulerian extension E of G with weight at most ωmax and heeding the advice H? We can show that each minimal connecting cycle-free advice can be obtained from a forest in G . Enumerating these forests allows us to generate all such advices for a given graph G with c connected components in f (c) · |G|O(1) ) time, where f is some function only depending on c. Deferring the presentation of details to a long version of this work, we state that EE is parameterized Turing reducible to EE∅CA [16]. c log(c) Lemma 1. EE is ≤FPT |G|O(1) time. T -reducible to EE∅CA in 16

3 Eulerian Extension and Conjoining Bipartite Matching This section shows that Rural Postman (RP) is parameterized equivalent to a matching problem. By the parameterized equivalence of RP and Eulerian Extension (EE) given by Dorn et al. [4], we may concentrate on the equivalence of EE and matching instead. First we introduce a variant of perfect bipartite matching. Let G be a bipartite graph, M be a matching of the vertices in G, and let P be a vertex partition with the cells C1 , . . . , Ck . We call an unordered pair {i, j} of integers 1 ≤ i < j ≤ k a join

A New View on Rural Postman Based on Eulerian Extension and Matching

315

and a set J of such pairs a join set with respect to G and P. We say that a join {i, j} ∈ J is satisfied by the matching M of G if there is at least one edge e ∈ M with e ∩ Ci ∅ and e ∩ C j ∅. We say that a matching M of G is J-conjoining with respect to a join set J if all joins in J are satisfied by M. If the join set is clear from the context, we simply say that M is conjoining. Conjoining Bipartite Matching (CBM) Input: A bipartite graph G = (V1 V2 , E), an integer ωmax , a weight function ω : E → [0, ωmax], a partition P = {C1 , . . . , Ck } of the vertices in G, and a join set J. Question: Is there a matching M of the vertices of G such that M is perfect, M is conjoining and M has weight at most ωmax ? CBM can be interpreted as a job assignment problem with additional constraints: an assignment of workers to tasks is sought such that each worker is busy and each task is being processed. Furthermore, every worker must be qualified for his or her assigned task. Both the workers and the tasks are grouped and the additional constraints are of the form “At least one worker from group A must be assigned a task in group B”. An assignment that satisfies such additional constraints may be favorable in settings where the workers are assigned to projects and the projects demand at least one worker with additional qualifications. Over the course of the following subsections, we prove the following theorem. Theorem 1. Conjoining Bipartite Matching and Eulerian Extension are ≤FPT T equivalent with respect to the parameters “join set size” and “number of connected components in the input graph.” The proof of Theorem 1 consists of four reductions, one of which is a parameterized Turing reduction. The other three reductions are polynomial-time polynomial-parameter many-one reductions. It is easy to see that the equivalence of EE and RP given by Dorn et al. [4] also holds for the parameters “number of components” and “number of components in the graph induced by the required arcs.” Thus, we obtain the following from Theorem 1. Theorem 2. Conjoining Bipartite Matching and Rural Postman are ≤FPT T -equivalent with respect to the parameters “number of components in the graph induced by the required arcs” and “join set size.” 3.1 From Eulerian Extension to Matching In this section we sketch a reduction from EE∅CA to CBM. By Lemma 1 this reduction leads to the following theorem. Theorem 3. Eulerian Extension is ≤PPP m -reducible to Conjoining Bipartite Matching with respect to the parameters “number of components” and “join set size.” Outline of the Reduction. The basic idea of our reduction is to use vertices of positive balance and negative balance in an instance of EE∅CA as the two cells of the graph bipartition in a designated instance of CBM. Edges between vertices in the new instances

316

M. Sorge et al.

1

2

3

4

5

7

6

8

(a) EE∅CA instance

1

1•7

1•5

8•2

6•2

6

8

2

8◦2

6◦2

1◦7

1◦5

5

7

(b) Long-hint gadget in CBM instance

Fig. 1. Example of the long-hint gadget. In (a) an EE∅A-instance is shown, consisting of a graph with three connected components and an advice that contains a single path hint h (dashed lines). In (b) a part of an instance of CBM is shown, comprising the cells that correspond to the initial and terminal vertices of h and a gadget to model h. The gadget consists of new vertices put into a new cell which is connected by two joins (dashed and dotted lines) to the cells corresponding to the initial and terminal vertices of h.

represent shortest paths between these vertices that consist of allowed extension arcs in the original instance. Every connected component in the original instance is represented by a cell in the partition in the matching instance and hints are basically modeled by joins. Description of the Reduction. For the description of the reduction, we need the following definition. Definition 1. Let C1 , . . . , Cc be the connected components of a directed multigraph G, and let H be a cycle-free advice for G. For every h ∈ H define connect(h) {i, j}, where Ci , C j are the components corresponding to the initial and terminal vertices of h. First, consider an EE∅CA-instance (G, ωmax , ω, H) such that H is a cycle-free minimal connecting advice that contains only hints of length one. We will deal with longer hints later. We create an instance ICBM of CBM by first defining B0 = (IG+ IG− , E0 ) as a bipartite graph. Here, the set E 0 consists of all edges {u, v} such that u ∈ IG+ , v ∈ IG− , and ω(u, v) < ∞.6 Second, we derive a vertex partition {V1 , . . . , Vc } of B0 by intersecting the connected components of G with (IG+ IG− ). The vertex partition obviously models the connected components in the input graph, and the need for connecting them according to the advice H is modeled by an appropriate join-set J0 , defined as {connect(h) : h ∈ H}. Finally, we make sure that matchings also correspond to Eulerian extensions weightwise, by defining the weight function ω ({u, v}) for every u ∈ IG+ , v ∈ IG− as ω(u, v) with ωmax = ωmax . By Observation 3 we may assume that every hint in H of length one is realized by a single arc. Since the advice connects all connected components, by the same observation, we may assume that all other trails in a valid Eulerian extension have length one. Finally, by Observation 1, we may assume that every vertex has at most one incident incoming or outgoing arc in the extension and, hence, we get an intuitive correspondence between conjoining matchings and Eulerian extensions. To model hints of length at least two, we utilize gadgets similar to the one shown in Figure 1. The gadget comprises two vertices (u ◦ v and u • v) for every pair (u, v) of vertices with one vertex in the component the hint starts and one in the component 6

This serves the purpose of modeling the structure of “allowed” arcs in the matching instance.

A New View on Rural Postman Based on Eulerian Extension and Matching

317

the hint ends. The vertices u ◦ v and u • v are adjacent and each of these two vertices is connected with one vertex of the pair it represents. The edge {u • v, u} is weighted with the cost it takes to connect u, v with a path that realizes h. This cost is computed using Observation 5. The edges {u • v, u ◦ v} and {u ◦ v, v} have weight 0. Intuitively these three edges in the gadget represent one concrete realization of h. If u ◦ v and u • v are matched, this means that this specific path does not occur in a designated Eulerian extension. However, by adding the vertices of the gadget as cell to the vertex partition and by extending the join set to the gadget, we enforce that there is at least one outgoing edge that is matched. If a perfect matching matches u ◦ v with u, then it also matches u • v with v and vice versa. This introduces an edge to the matching that has weight corresponding to a path that realizes h. 3.2 From Matching to Eulerian Extension with Advice We reduce Conjoining Bipartite Matching to Eulerian Extension with Advice: Theorem 4. Conjoining Bipartite Matching is ≤PPP m -reducible to Eulerian Extension with Advice with respect to the parameters “join set size” and “connected components in the input graph”. To reduce CBM to EEA we first observe that for every instance of CBM there is an equivalent instance such that every cell in the input vertex partition contains equal numbers of vertices from both cells of the graph bipartition. This observation enables us to model cells as connected components and vertices in the bipartite graph as unbalanced vertices in the designated instance of EEA. Lemma 2. For every instance of CBM there is an equivalent instance comprising the bipartite graph G = (V1 V2 , E), the vertex partition P = {C1 , . . . , Ck } and the join set J, such that (i) for every 1 ≤ i ≤ k it holds that |V1 ∩ Ci | = |V2 ∩ Ci |, and (ii) the graph (P, {{Ci , C j } : {i, j} ∈ J}) is connected. This equivalent instance contains at most one cell more than the original instance. Description of the Reduction. To reduce instances of CBM that conform to Lemma 2 to instances of EEA we use the simple idea of modeling every cell as connected component, vertices in V1 as vertices with balance −1, vertices in V2 as vertices with balance 1, and joins as hints. Construction 1. Let the bipartite graph B = (V1 V2 , E), the weight function ω : E → [0, ωmax], the vertex partition P = {C1 , . . . , Ck } and the join set J constitute an instance ICBM of CBM that corresponds to Lemma 2. Let v11 , v21 , . . . , v1n/2 , v2n/2 be a sequence of all vertices chosen alternatingly from V1 and V2 . Let the graph G = (V, A) (V1 ∪ V2 , A1 ∪ A2 ) where the arc sets A1 and A2 are as follows: A1 {(v1i , v2i ) : 1 ≤ i ≤ n/2}. For every 1 ≤ j ≤ k let C j = {v1 , . . . , v jk }, and let j

A2 {(vi , vi+1 ) : 1 ≤ i ≤ jk − 1} ∪ {(v jk , v1 }

318

M. Sorge et al.

j and define A2 kj=1 A2 . Define a new weight function ω for every pair of vertices (u, v) ∈ V × V by ⎧ ⎪ ⎪ ⎨ω({u, v}), u ∈ V2 , v ∈ V1 , {u, v} ∈ E ω (u, v) ⎪ ⎪ ⎩∞, otherwise. Finally, derive an advice H for G by adding a length-one hint h to H for every join {o, p} ∈ J such that h consists of the edge that connects vertices in G that correspond to the connected components Co , and C p . The graph G, the weight function ω , the maximum weight ωmax and the advice H constitute an instance of EEA. Theorem 4 follows, since Construction 1 is a ≤PPP m -reduction. 3.3 Removing Advice For Theorem 1, it remains to show, that the advice in an instance of EEA created by Construction 1 can be removed. That is, it remains to show the following theorem. Theorem 5. Eulerian Extension with Advice is ≤PPP m -reducible to Eulerian Extension with respect to the parameter “number of components in the input graph.” The basic ideas for proving Theorem 5 are as follows. First, we remove every cycle-hint using Observation 4. We use the fact that every Eulerian extension has to connect all connected components of the input graph. Thus, for each hint h, we introduce a new connected component Ch . Let the components C s , Ct correspond to the endpoints of hint h. To enforce that hint h is realized, we use the weight function to allow an arc from every vertex with balance 1 in C s to a number of distinct vertices in Ch . This number is the number of vertices with balance −1 in Ct . That is, for every pair of unbalanced vertices in C s × Ct , we have an associated vertex in Ch . Then, for every inner vertex v on h, we copy Ch and connect it to the component corresponding to v. From one copy to another, using the weight function, we allow only arcs that start and end in vertices corresponding to the same pair of unbalanced vertices in C s ×Ct . This enforces that every hint is realized and connects every component it visits. Using the weight function and Observation 5 we can ensure that the arcs corresponding to a realization of a hint have the weight of an optimal realization with the same endpoints. Using this construction, Theorem 5 can be proven which concludes the proof of Theorem 1.

4 Conjoining Bipartite Matching: Properties and Special Cases This section investigates the properties of CBM introduced in Section 3. As discussed before, CBM might eventually help us derive a fixed-parameter algorithm for EE with respect to the parameter number of connected components. Section 4.1 first shows that also CBM is NP-complete. Section 4.2 then establishes tractability of the problem on restricted graph classes and translates this tractability result into the world of EE and RP.

A New View on Rural Postman Based on Eulerian Extension and Matching

319

4.1 NP-Hardness NP-Hardness for Conjoining Bipartite Matching (CBM) does not follow from the parameterized equivalence to Eulerian Extension (EE) we gave in Section 3, since the reduction from EE we gave is a parameterized Turing reduction. To show that CBM is NP-hard, we polynomial-time many-one reduce from the well-known 3SAT, where a Boolean formula φ in 3-conjunctive normal form (3-CNF) is given and it is asked whether there is an assignment to the variables of φ that satisfies φ. Herein, a formula φ in 3-CNF is a conjunction of disjunctions of three literals each, where each literal is either x or ¬x and x is a variable of φ. In the following, we represent each clause as three-element-set γ ⊆ X × {+, −}, where (x, +) ∈ γ means that x is contained in the clause represented by γ and (x, −) ∈ γ means that ¬x is contained in the clause represented by γ. Construction 2. Let φ be a Boolean formula in 3-CNF with the variables X {x1 , . . . , xn } and the clauses γ1 , . . . , γm ⊆ X × {+, −}. We translate φ into an instance of CBM that is a yes-instance if and only if φ is satisfiable. To this end, for every variable xi , introduce a cycle with 4m edges consisting of the vertex set Vi {vij : 4m 1 ≤ j ≤ 4m} and the edge set Ei {eki {vki , vk+1 {v1i , v4m i } ⊆ Vi } ∪ {ei i }}. Let n n G ( i=1 Vi , i=1 E i ), and let ω(e) 0, e ∈ Ei for any 1 ≤ i ≤ n, and define ωmax 1. To construct an instance of CBM, it remains to find a suitable partition of the vertices of G and a join set. Inductively define the vertex partition Pm of V(G) and the join set Jm as follows: Let J0 = ∅, and let P0 ∅. For every clause γ j introduce the cell C j {vi4 j−1 : (xi , +) ∈ γ j ∨ (xi , −) ∈ γ j } ∪ {vi4 j−2 : (xi , +) ∈ γ j } ∪ {v4i j : (xi , −) ∈ γ j }. Define P j P j−1 ∪ {C j } and J j J j−1 ∪ {{0, j}}. Finally, define C0 V(G)\( mj=1 C j ). The graph G, the weight function ω, the vertex partition Pm ∪ {C0 } and the join set Jm constitute an instance of CBM. Using this construction, we can prove the following theorem. Theorem 6. CBM is NP-complete, even in the unweighted case and when the input graph G = (V W, E) has maximum degree two, and for every cell Ci in the given vertex partition of G it holds that |Ci ∩ V| = |Ci ∩ W|. Proof. CBM is contained in NP, because a perfect conjoining matching of weight at most ωmax is a certificate for a yes-instance. We prove that Construction 2 is a polynomial-time many-one reduction from 3SAT to CBM. Notice that in instances created by Construction 2 any matching has weight lower than ωmax and, thus, the soundness of the reduction implies that CBM is hard even without the additional weight constraint. Also, since the cells in the instances of CBM are disjoint unions of edges, every cell in the partition Pm contains the same number of vertices from each cell of the graph bipartition. It is easy to check that Construction 2 is polynomial-time computable. For the correctness we first need the following definition: For every variable xi ∈ X let Mitrue {eki ∈ Ei : k odd} and Mifalse Ei \ Mitrue = {eki ∈ Ei : k even}.

320

M. Sorge et al.

Observe that all perfect matchings in G are of the form ni=1 Miν(xi ) , where ν is an as signment of truth values to variables in X. We show that the matching ni=1 Miν(xi ) is a conjoining matching for G with respect to the join set Jm if and only if ν is satisfies φ. For this, it suﬃces to show that for every variable xi ∈ X it holds that { j : (xi , +) ∈ γ j } = { j : Mitrue satisfies the join {0, j}}, and

(1)

{ j : (xi , −) ∈ γ j } = { j : Mifalse satisfies the join {0, j}}.

(2)

We only show that (1) holds; (2) can be proven analogously. Assume that (xi , +) ∈ γ j . By Construction 2, vi4 j−2 ∈ C j , vi4 j−3 ∈ C0 and thus, since {vi4 j−2 , vi4 j−3 } = e4 j−3 ∈ Mitrue , the matching Mitrue satisfies the join {0, j}. Now assume that (xi , +) γ j , that is, either (1) (xi , ±) γ j or (2) (xi , −) ∈ γ j . If (xi , ±) γ j , then Vi and C j are disjoint and, thus, no matching in G[Vi ] can satisfy the join {0, j}. If (xi , −) ∈ γ j , then the only edges in Ei that can satisfy the join {0, j} are ei4 j−2 and e4i j . Both edges are not in Mitrue and, thus, this matching cannot satisfy the join {0, j}. 4.2 Tractability on Restricted Graph Classes This section presents data reduction rules and employs them to sketch an algorithm for CBM on a restricted graph class, leading to the following theorem: Theorem 7. Conjoining Bipartite Matching can be solved in O(2 j( j+1)n + n3 ) time, where j is the size of the join set, provided that in the bipartite input graph G = (V1 V2 , E) each vertex in V1 has maximum degree two. In this section, let (G, ωmax , ω, P = {C1 , . . . , Cc }, J) be an instance of CBM, where in G is as in Theorem 7. The following lemma plays a central role in the proof of Theorem 7. It implies that, in a yes-instance, every component of G consists of an even-length cycle with a collection of pairwise vertex-disjoint paths incident to it. Lemma 3. If G has a perfect matching, then every connected component of G contains at most one cycle as subgraph. Proof. We show that if G contains a connected component that contains two cycles c1 , c2 as subgraphs, then G does not have a perfect matching. First assume that c1 , c2 are vertex-disjoint. Then, there is a path p from a vertex v ∈ V(c1 ) to a vertex w ∈ V(c2 ) such that p is vertex-disjoint from c1 and c2 except for v, w. It is clear that both v, w ∈ V2 cp because they have degree three. Consider the vertices V1 (V(c1 ) ∪ V(p) ∪ V(c2 )) ∩ V1 cp cp and the set V2 (V(c1 ) ∪ V(p) ∪ V(c2 )) ∩ V2 . The set V2 is the set of neighbors of cp vertices in V1 , because they have degree two and thus have neighbors only within p, c1 , cp and c2 . It is |V1 | = (|E(c1 )| + |E(p)| + |E(c2 )|)/2 since neither of these paths and cycles cp cp overlap in a vertex in V1 . However, it is |V2 | = |V1 | − 1 because c1 and p overlap in v and c2 and p overlap in w. This is a violation of Hall’s condition and thus G does not have a perfect matching.

A New View on Rural Postman Based on Eulerian Extension and Matching

321

The case where c1 and c2 share vertices can be proven analogously. (Observe that then there is a subpath of c2 that is vertex-disjoint from c1 and contains an even number of edges.) We now present four polynomial-time executable data reduction rules for CBM. The correctness of the first three rules is easy to verify, while the correctness of the fourth one is more technical and omitted. We note that all rules can be applied exhaustively in O(n3 ) time. Reduction Rule 1 removes paths incident to the cycles of a graph G in a yes-instance. As a side-result, Reduction Rule 1 solves CBM in linear time on forests. Reduction Rule 1. If there is an edge {v, w} ∈ E(G) such that deg(v) = 1, then remove both v and w from G, and remove all joins {i, j} from J, with v ∈ Ci , w ∈ C j . Decrease ωmax by ω({v, w}). If exhaustively applying Reduction Rule 1 to G does not transform G such that each connected component is a cycle, which is checkable in linear time, then, by Lemma 3, G does not have a perfect matching and we can return “NO”. Hence, in the following, assume that each connected component of G is a cycle. Reduction Rule 2 now deletes connected components that cannot satisfy joins. Reduction Rule 2. If there is a connected component D of G such that it contains no edge that could satisfy any join in J, then compute a minimum-weight perfect matching M in G[D], remove D from G and decrease ωmax by ω(M). After exhaustively applying Reduction Rule 2, we may assume that each connected component of G contains an edge that could satisfy a join. We next present a data reduction rule that removes joins that are always satisfied. To this end, we need the following definition. Definition 2. For each connected component D (that is, each cycle) in G, denote by M1 (D) a minimum-weight perfect matching of D with respect to ω and denote by M2 (D) E(D) \ M1 (D) the other perfect matching of D.7 Furthermore, denote σ1 (D) { j ∈ J : ∃e ∈ M1 (D) : e satisfies j}, σ2 (D) { j ∈ J : ∃e ∈ M2 (D) : e satisfies j}, and the signature σ(D) of D as {σ1 (D), σ2 (D)}. Reduction Rule 3. Let D be a connected component of G. If there is a join j ∈ σ1 (D)∩ σ2 (D), then remove j from J. A final data reduction rule removes connected components that satisfy the same joins. Reduction Rule 4. Let S = {D1 , . . . , D j } be a maximal set of connected components j of G such that σ(D1 ) = . . . = σ(D j ) and j ≥ 2. Let M1∗ = k=1 M1 (Dk ), let Dl ∈ S such that ω(M2 (Dl )) − ω(M1 (Dl )) is minimum, and let M1∼ = M1∗ \ M1 (Dl ). 7

Note that in bipartite graphs every cycle is of even length.

322

M. Sorge et al.

(i) If the matching M1∗ is conjoining for the join set σ1 (D1 ) ∪ σ2 (D1 ), then remove each component in S from G, remove each join in σ1 (D1 ) ∪ σ2 (D1 ) from the join set J, and reduce ωmax by ω(M1∗ ). (ii) If the matching M1∗ is not conjoining for the join set σ1 (D1 ) ∪ σ2 (D1 ), then remove each component in S \ {Dl } from G, remove any join in σ1 (D1 ) from the join set J, and reduce ωmax by ω(M1∼ ). In either case, update the partition P accordingly. Observation 6. If Reduction Rule 4 is not applicable to G, then G contains at most one connected component for each of the 2|J|+1 possible signatures. Now, Theorem 7 follows: Exploiting Observation 6, a search-tree algorithm solving CBM can in O(n) time choose a join j ∈ J and choose one of the at most 2|J|+1 connected components of the graph that can satisfy j and match the component accordingly. Then, the algorithm can recurse on how the remaining |J| − 1 joins are satisfied. Analyzing the pre-images that lead to tractable instances of CBM under the reductions we gave in Section 3, Theorem 7 can be translated to a tractability result for EE. A similar tractability result can also be shown for Rural Postman. Due to its length, we only state it for EE here. Corollary 1. Let the graph G and the weight function ω constitute an instance IEE of EE. Let c be the number of connected components in G. (i) If every path or cycle in the set of allowed arcs w.r.t. ω has length at most one, (ii) if G contains only vertices with balance between −1 and 1, (iii) if every vertex in IG+ (every vertex in IG− ) has only outgoing allowed arcs (incoming allowed arcs), and (iv) if in every connected component C of G, either all vertices in IG+ ∩ C or in IG− ∩ C have at most two incident allowed arcs, 4 then it is decidable in O(2c(c+log(2c )) (n4 + m)) time whether IEE is a yes-instance.

5 Conclusion Clearly, the most important remaining open question is to determine whether Rural Postman is fixed-parameter tractable with respect to the number of connected components of the graph induced by the required arcs. This question also extends to the presumably harder undirected case. The newly introduced Conjoining Bipartite Matching (CBM) problem might also be useful in spotting new, computationally feasible special cases of Rural Postman and Eulerian Extension. The development of polynomial-time approximation algorithms for CBM or the investigation of other (structural) parameterizations for CBM seem worthwhile challenges as well. Finally, we remark that previous work [10, 4] also left open a number of interesting open problems referring to variants of Eulerian Extension. Due to the practical relevance of the considered problems, our work is also meant to further stimulate more research on these challenging combinatorial problems.

A New View on Rural Postman Based on Eulerian Extension and Matching

323

References [1] Assad, A.A., Golden, B.L.: Arc routing methods and applications. In: Network Routing. Handbooks in Operations Research and Management Science, vol. 8, pp. 375–483. Elsevier B.V. (1995) [2] Benavent, E., Corber´an, A., Pi˜nana, E., Plana, I., Sanchis, J.M.: New heuristic algorithms for the windy rural postman problem. Comput. Oper. Res. 32(12), 3111–3128 (2005) [3] Cabral, E.A., Gendreau, M., Ghiani, G., Laporte, G.: Solving the hierarchical chinese postman problem as a rural postman problem. European J. Oper. Res. 155(1), 44–50 (2004) [4] Dorn, F., Moser, H., Niedermeier, R., Weller, M.: Eﬃcient Algorithms for Eulerian Extension. In: Thilikos, D.M. (ed.) WG 2010. LNCS, vol. 6410, pp. 100–111. Springer, Heidelberg (2010) [5] Downey, R.G., Fellows, M.R.: Parameterized Complexity. Springer, Heidelberg (1999) [6] Dror, M.: Arc Routing: Theory, Solutions, and Applications. Kluwer Academic Publishers (2000) [7] Eiselt, H.A., Gendreau, M., Laporte, G.: Arc routing problems, part II: The rural postman problem. Oper. Res. 43(3), 399–414 (1995) [8] Flum, J., Grohe, M.: Parameterized Complexity Theory. Springer, Heidelberg (2006) [9] Frederickson, G.N.: Approximation algorithms for some postman problems. J. ACM 26(3), 538–554 (1979) [10] H¨ohn, W., Jacobs, T., Megow, N.: On Eulerian extensions and their application to no-wait flowshop scheduling. J. Sched (to appear, 2011) [11] Lenstra, J.K., Kan, A.H.G.R.: On general routing problems. Networks 6(3), 273–280 (1976) [12] Niedermeier, R.: Invitation to Fixed-Parameter Algorithms. Oxford University Press (2006) [13] Orloﬀ, C.S.: A fundamental problem in vehicle routing. Networks 4(1), 35–64 (1974) [14] Orloﬀ, C.S.: On general routing problems: Comments. Networks 6(3), 281–284 (1976) [15] Perrier, N., Langevin, A., Campbell, J.F.: A survey of models and algorithms for winter road maintenance. Part IV: Vehicle routing and fleet sizing for plowing and snow disposal. Comput. Oper. Res. 34(1), 258–294 (2007) [16] Sorge, M.: On making directed graphs Eulerian. Diplomarbeit, Institut f¨ur Informatik, Friedrich-Schiller-Universit¨at Jena (2011), Available electronically. arXiv:1101.4283 [cs.DM]

Hamilton Cycles in Restricted Rotator Graphs Brett Stevens and Aaron Williams Carleton University, Canada brett@math.carleton.ca, haron@uvic.ca

Abstract. The rotator graph has vertices labeled by the permutations of n in one line notation, and there is an arc from u to v if a preﬁx of u’s label can be rotated to obtain v’s label. In other words, it is the directed Cayley graph whose generators are σk := (1 2 · · · k) for 2 ≤ k ≤ n and these rotations are applied to the indices of a permutation. In a restricted rotator graph the allowable rotations are restricted from k ∈ {2, 3, . . . , n} to k ∈ G for some smaller (ﬁnite) set G ⊆ {2, 3, . . . , n}. We construct Hamilton cycles for G = {n−1, n} and G = {2, 3, n}, and provide eﬃcient iterative algorithms for generating them. Our results start with a Hamilton cycle in the rotator graph due to Corbett (IEEE Transactions on Parallel and Distributed Systems 3 (1992) 622–626) and are constructed entirely from two sequence operations we name ‘reusing’ and ‘recycling’.

1

Introduction

Let Πn denote the set of permutations of [n] := {1, 2, . . . , n} written in one-line notation as strings. For example, Π3 = {1 2 3, 1 3 2, 2 1 3, 2 3 1, 3 1 2, 3 2 1} and we henceforth omit spaces between individual symbols when appropriate. The operation σk is a preﬁx-rotation, or simply rotation, and it cyclically moves the ﬁrst k symbols one position to the left. In other words, σk applies the permutation (1 2 · · · k) to the indices of a string. For example, 541362 σ4 = 413562 since 413 moves one position to the left and 5 “wraps around” into the fourth position. The operation is also known as a preﬁx-shift of length k in the literature. 1.1

Rotator Graphs and Hamilton Cycles

The rotator graph Rn has nodes labeled with the strings in Πn , and arcs labeled σk directed from α ∈ Πn to β ∈ Πn when β = α σk . In group-theoretic terms, −−→ Rn is the directed Cayley graph Cay({σ2 , σ3 , . . . , σn }, Sn ) with generators σk for 2 ≤ k ≤ n and where Sn is the symmetric group corresponding to Πn . A −− → restricted rotator graph for G ⊆ [n] is Rn (G) = Cay(G, Sn ) where the generators are restricted to σk for k ∈ G. Figure 1 (a) illustrates R3 . A Hamilton cycle of Rn (G) can be described by a Hamilton sequence of integers S = s0 , s1 , · · · , sn!−1 where σsi is the label of the (i + 1)st arc in the

Research supported in part by NSERC.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 324–336, 2011. c Springer-Verlag Berlin Heidelberg 2011

Hamilton Cycles in Restricted Rotator Graphs

325

Fig. 1. (a) The rotator graph R3 , and (b) a Hamilton cycle in R3

cycle and si ∈ G for each i ∈ {0, 1, . . . , n! − 1}. A Hamilton cycle of Rn (G) can also be described by the order of node labels along the cycle. In combinatorial generation, these orders are cyclic Gray codes since each string in Πn appears exactly once, and successive strings diﬀer by some σk for k ∈ G where ‘successive’ includes last to ﬁrst. For example, Figure 1 (b) contains a Hamilton cycle for R3 that can be described by 3, 3, 2, 3, 3, 2 or 321, 213, 132, 312, 123, 231.

(1)

Restricted rotator graphs are vertex-transitive; our Hamilton cycles and their associated Gray code orders for Rn (G) will all ‘start’ at n n−1 · · · 1. Orders of strings that do not necessarily have the Gray code properties are called lists. An explicit Hamilton cycle in Rn was ﬁrst constructed by Corbett [2]. Hamilton cycles were then constructed for diﬀerent generalizations of Rn by Ponnuswamy and Chaudhary [11] and Williams [13]. Hamilton cycle constructions for Rn ({n − 1, n}) were proposed as an open problem by Knuth, and this was answered by Ruskey and Williams [12]. Observe that σn must be included in a restricted rotator graph in order to generate the entire symmetric group Sn . Moreover, σn and σc are not suﬃcient for generating Sn if and only if c and n are both odd (in these cases the parity of a permutation cannot be changed). A well-known conjecture is that a Hamilton cycle exists in every connected undirected Cayley graph, where undirected Cayley graphs include the inverse of each generator. In particular, a Hamilton cycle was constructed for Cay({σ2 , σn }, Sn ) by Compton and Williamson in a 50-page paper [1]. Corbett introduced the term “rotator graph” when considering point-to-point multiprocessor networks, where Hamilton cycles establish indexing schemes for sorting and for mapping rings and linear arrays [2] Applications of rotator graphs include fault-tolerant ﬁle transmission by Hamada et al [5] and parallel sorting by Corbett and Scherson [3]. Properties of rotator graphs have been examined including minimum feedback sets by Kuo et al [9] and node-disjoint paths by Yasuto, Ken’Ichi, and Mario [14]. Other variations of rotator graphs include incomplete rotator graphs [11], the bi-rotator graph (see Lin and Hsu [10]), and graphs where the labels can have repeated symbols [13]. The relationship between Hamilton cycles of Rn (n − 1, n) and universal cycles of Πn is discussed by Holroyd, Ruskey, and Williams along with applications [6,7].

326

1.2

B. Stevens and A. Williams

New Results

We construct a new Hamilton cycle in Rn ({n−1, n}) and the ﬁrst Hamilton cycle in Rn ({2, 3, n}). The chosen sets {n−1, n} and {2, 3, n} are natural since σn−1 is the “largest” rotation other than σn , whereas σ2 and σ3 are the “smallest” pair of rotations given the previously mentioned diﬃculty of the Compton and Williamson result for Cay({σ2 , σn }, Sn ) [1] and the trivial lack of connectivity in Cay({σ3 , σn }, Sn ) when n is odd. Our new constructions are intimately related to Corbett’s original Hamilton cycle in Rn . In fact, the beauty of our results is that all three Hamilton sequences can be described by two operations that we name ‘reusing’ and ‘recycling’. We also provide an algorithm for constructing the Hamilton sequences. The algorithm is loopless since successive values in the sequence are obtained in worst-case O(1)-time (see Ehrlich [4] for the ﬁrst use of this term). Section 2 formally deﬁnes the ‘reuse’ and ‘recycle’ operations. Section 3 constructs the three Hamilton cycles and proves that two of the constructions are correct. Section 4 gives a loopless algorithm that generates the Hamilton sequences. Section 5 extends Corbett’s recursive construction with an iterative description that is instrumental to the ﬁnal proof of correctness. Section 6 completes the ﬁnal proof of correctness by proving that Corbett’s Hamilton sequence of Rn can be ‘recycled’ into a Hamilton cycle of Rn+1 ({n, n + 1}). Section 7 concludes with open problems.

2

Sequence Building

This section deﬁnes two operations for building sequences of positive integers and examines the lists they create when they are treated as rotation indices. 2.1

Reusing and Recycling

In this subsection we deﬁne the reusing and recycling sequence operations, and describe how they are applied to create lists of strings. Given i and n satisfying 1 < i < n, the result of reusing and recycling i with respect to n is i−1 copies

copies n−i−1 reusen (i) = n, . . . , n , n−i+1 and recyclen (i) = n, n, n−1, . . . , n−1, n, . . . , n n−1 copies

respectively. Notice that both operations create sequences of n symbols that are each at least 2 and at most n. For example, reuse6 (3) = 6, 6, 6, 6, 6, 4 and recycle6 (3) = 6, 6, 5, 5, 6, 6.

(2)

We build longer sequences by applying these operations to each symbol in a sequence. If S = s1 , s2 , . . . , st is a sequence with 1 < si < n for each i, then reusen (S) = reusen (s1 ), reusen (s2 ), . . . , reusen (st ) and recyclen (S) = recyclen (s1 ), recyclen (s2 ), . . . , recyclen (st ).

Hamilton Cycles in Restricted Rotator Graphs

327

We use sequences to create lists of strings by applying successive preﬁx-rotations. If α ∈ Πn and S = s1 , s2 , . . . , st is a sequence with 1 < si ≤ n for each i, then α ◦ S = β0 , β1 , . . . , βt where β0 = α and βi = βi−1 σsi for i = 1, 2, . . . , t. For example, if α = 612345 then α ◦ reuse6 (3) = 612345, 123456, 234561, 345612, 456123, 561234, 612534

(3)

α ◦ recycle6 (3) = 612345, 123456, 234561, 345621, 456231, 562314, 623145 since reuse6 (3) = 6, 6, 6, 6, 6, 4 and recycle6 (3) = 6, 6, 5, 5, 6, 6 by (2). In some situations it is more convenient to leave oﬀ the last permutation in the list α ◦ S, and we use α • S in these cases. A symbol x is periodic in a list L of Πn if the position of x moves once to the left (cyclically) between successive strings in L. For example, 6 is periodic in both lists from (3). More generally, the ﬁrst symbol x of α ∈ Πn is periodic in any list of the form α ◦ reuse(S) or α ◦ recycle(S). This is because the ﬁrst rotation σn moves x from the ﬁrst position to the last position, the next n−1 rotations move x one position to the left, and this pattern is repeated. 2.2

Rotation Identities

In this subsection we give two identities involving rotations. In addition to σi = (1 2 · · · i) for preﬁx-rotations, let ςi = (n n−1 · · · n−i+1) denote the suﬃxrotation operation, and σi = (2 3 · · · i+1) denote a modiﬁed preﬁx-rotation that begins at the second symbol. We also let σij denote j successive copies of σi , and successive rotations are applied from left-to-right. Using these conventions we have the following simple identities i−1 n−i−1 σnn−1 σn−i+1 = ςi and σn2 σn−1 σn = σi

“reuse equality”

“recycle equality”.

(4)

The “reusing equality” on the left follows from (n n−1 · · · 1)(1 2 · · · n−i+1) = (n−i+1 n−i+2 · · · n), while the “recycling equality” on the right is the second equality of Lemma 2 in [7]. The equalities allow the last string obtained by applying reusen (i) and recyclen (i) to be computed directly. For example, when i = 3 and n = 6 we obtain the ﬁnal strings in (3) as follows 612345σ65σ4 = 612345ς3 = 612534 2.3

612345σ62σ52 σ62 = 612345σ3

(5)

= 623145.

List Quotients

In Section 2.1 we saw that every nth string in n n−1 · · · 1 ◦ S begins with n, whenever S is obtained by reusing or recycling. Furthermore, Section 2.2 gave identities for these strings. This subsection examines these strings in more detail. The quotient of a list L of Πn with a symbol x ∈ [n] is the list obtained from L by (1) removing the strings that do not begin with x, and (2) removing x from

328

B. Stevens and A. Williams

the strings that begin with x. We denote this operation by x/L. Our ﬁrst lemma uses recycling and is illustrated by the next example. If S = 3, 3, 2, 3, 3, 2 then 321 • S = 321, 213, 132, 312, 123, 231 and

(6)

4321 • recycle(S) = 4321, 3214, 2143, 1423, 4213, 2134, 1342, 3412, 4132, 1324, 3241, 2431, 4312, 3124, 1243, 2413, 4123, 1234, 2341, 3421, 4231, 2314, 3142, 1432.

Notice the quotient of the second list with 4 equals the ﬁrst list (as underlined). That is, 4/(4321 • recycle(S)) = 321 • S. Lemma 1 proves this is true for any S. Lemma 1. If sequence S has values in {2, . . . , n−1} and αi = i i−1 · · · 1, then n/(αn • recyclen (S)) = αn−1 • S. Proof. The ﬁrst string in both lists is αn−1 since n/αn = αn−1 . Since n is periodic in αn ◦ recyclen (S), every nth string begins with n. Therefore, successive strings in n/(αn ◦recyclen (S)) are obtained by successive σsi for S = s1 , . . . , st by the “recycling identity” in (4). Therefore, the two lists are equal. Our second lemma instead uses reusing and is illustrated by the next example 321 • S = 321, 213, 132, 312, 123, 231 and

(7)

4321 • reuse(S) = 4321, 3214, 2143, 1432, 4132, 1324, 3241, 2413, 4213, 2134, 1342, 3421, 4231, 2314, 3142, 1423, 4123, 1234, 2341, 3412, 4312, 3124, 1243, 2431.

In this case the quotient of the second list with 4 equals the “double-reverse” of the ﬁrst list. Given a string a1 a2 · · · an ∈ Πn the double-reverse is a1 a2 · · · aR n = (n−an +1) · · · (n−a2 +1) (n−a1 +1). In a double-reverse the relative order of symbols is changed from a1 a2 · · · an to an · · · a2 a1 and relative values are reversed from x to n−x+1. Given a list R L = α1 , . . . , αm the double-reversal of L is LR = αR 1 , . . . , αm . For example, (321, 132, 213, 231, 123, 312)R = 321R , 132R , 213R , 231R, 123R, 321R = 321, 213, 132, 312, 123, 231. This equation illustrates the relationship 4/(4321 • reuse(S)) = (321 • S)R in (7) (as underlined). Lemma 2 proves this is true for any S. Lemma 2. If sequence S has values in {2, . . . , n−1} and αi = i i−1 · · · 1, then n/(αn ◦ reusen (S)) = (αn−1 ◦ S)R . Proof. The ﬁrst string in both lists is αn−1 since n/αn = αn−1 and αR n−1 = αn−1 . Since n is periodic in αn ◦ reusen (S), every nth string begins with n. Therefore, successive strings in n/(αn ◦ reusen (S)) are obtained by successive ςsi for S = s1 , . . . , st by the “reusing identity” in (4). Notice that suﬃx-rotations in a double-reversed string are ‘equivalent’ to preﬁx-rotations in the original string. That is, if α = β R , then α σi = β ςiR . Therefore, the two lists are equal.

Hamilton Cycles in Restricted Rotator Graphs

3

329

Three Hamilton Sequences

This section constructs Hamilton sequences for Rn , Rn ({n − 1, n}), and Rn ({2, 3, n}) through reusing and recycling. Two of the three main theorems are proven in this section, and the third is proven in Sections 5 and 6. 3.1

Hamilton Sequence for Rn

This subsection proves that a Hamilton sequence for Rn can be obtained entirely with the reuse operation. The Corbett sequence is deﬁned recursively as follows 2, 2 if n = 2 C(n) = (8) reusen (C(n−1)) if n > 2. Corbett proved that C(n) is a Hamilton sequence for the rotator graph Rn [2]. Let ΠC (n) = n n−1 · · · 1 ◦ C(n) denote this Corbett Gray code of Πn . Table 1 gives C(n) and ΠC (n) for n = 3, 4. Table 1. (a)-(b) Corbett sequence for n = 3, 4, and (c)-(d) Corbett Gray code for n = 3, 4. Preﬁx-rotations in (c) and suﬃx-rotations of every fourth string in (d) are underlined according to (a) by the “reusing equality” in (4). C(3) C(4) = reuse4 (C(3)) 3, 4, 4, 4, 2, 3, 4, 4, 4, 2, 2, 4, 4, 4, 3, 3, 4, 4, 4, 2, 3, 4, 4, 4, 2, 2 4, 4, 4, 3 (a) (b)

ΠC (3) 321, 213, 132, 312, 123, 231 (c)

ΠC (4) = 4321 ◦ C(4) 4321, 3214, 2143, 1432, 4132, 1324, 3241, 2413, 4213, 2134, 1342, 3421, 4231, 2314, 3142, 1423, 4123, 1234, 2341, 3412, 4312 3124, 1243, 2431 (d)

Theorem 1 extends Corbett’s result by proving that any Hamilton sequence for Rn−1 can be ‘reused’ into a Hamilton sequence for Rn . Furthermore, we explicitly state the values used in the resulting sequence. (A simple induction proves that Corbett’s ‘canonical’ sequence C(n) uses each value in {2, 3, . . . , n}.) Theorem 1. [2] If S is a Hamilton sequence in Rn−1 (G), then reusen (S) is a Hamilton sequence in Rn (H), where i ∈ H if and only if i = n or n − i + 1 ∈ G. Proof. Let α = n n−1 · · · 1. By Lemma 2 the nth strings in α ◦ reusen (S) form a Gray code for the strings in Πn that begin with n. Each of these strings is followed by n−1 applications of σn by the deﬁnition of reusen (i). Therefore, α◦reusen (S) contains every string in Πn and so reusen (S) is a Hamilton sequence. Finally, the values in H follow immediately from the deﬁnition of reusing.

330

3.2

B. Stevens and A. Williams

Hamilton Sequence for Rn ({n−1, n})

This subsection states that a Hamilton sequence for Rn (n−1, n) can be obtained by recycling Corbett’s Hamilton sequence. In other words, a Hamilton sequence for Rn (n−1, n) can be obtained by repeated reusing following by a single recycle. Let D(n) = recyclen (C(n−1)) denote this sequence and ΠD (n) = n n−1 · · · 1 ◦ D(n) denote its Gray code. Table 2 gives D(n) and ΠD (n) for n = 4. Table 2. (a)-(b) Recycling the Corbett sequence and (c)-(d) the Corbett Gray code from n = 3 to n = 4. Preﬁx-rotations in (c) and modiﬁed preﬁx-rotations of every fourth string in (d) are underlined according to (a) by the “recycling equality” in (4). C(3) D(4) = recycle4 (C(3)) 3, 4, 4, 3, 3, 3, 4, 4, 3, 3, 2, 4, 4, 3, 4, 3, 4, 4, 3, 3, 3, 4, 4, 3, 3, 2 4, 4, 3, 4 (a) (b)

ΠC (3) 321, 213, 132, 312, 123, 231 (c)

ΠD (4) = 4321 ◦ D(4) 4321, 3214, 2143, 1423, 4213, 2134, 1342, 3412, 4132, 1324, 3241, 2431, 4312, 3124, 1243, 2413, 4123, 1234, 2341, 3421, 4231 2314, 3142, 1432 (d)

Theorem 2. If S = C(n−1) is the Corbett sequence for Rn−1 , then recyclen (S) is a Hamilton sequence in Rn ({n−1, n}). To illustrate the diﬃculty of Theorem 2, we point out that arbitrary Hamilton sequences for Rn−1 cannot be recycled into Hamilton sequences for Rn . For example, consider the following Hamilton sequence for R4 and its associated Gray code for Π4 S = 4, 3, 3, 2, 3, 4, 2, 3, 4, 2, 3, 3, 4, 4, 2, 3, 3, 2, 3, 4, 4, 4, 3, 4 (9) 4321 ◦ S = 4321, 3214, 2134, 1324, 3124, 1234, 2341, 3241, 2431, 4312, 3412, 4132, 1342, 3421, 4213, 2413, 4123, 1243, 2143, 1423, 4231, 2314, 3142, 1432. Observe that 1324 is followed by 1324 σ2 = 3124, and that 2314 is followed by 2314 σ4 = 3142 in 4321 ◦ S. Therefore, Lemma 1 implies that 51324 is followed by 51324 • recycle5 (2), and 52314 followed by 52314 • recycle5 (4) in the recycled list 54321 • recycle5 (S). These two sublists appear below 51324 • recycle5 (2)

52314 • recycle5 (4)

= 51324 • 5, 5, 4, 5, 5

= 52314 • 5, 5, 4, 4, 4

= 51324, 13245, 32451, 24531, 45312

= 52314, 23145, 31452, 14532, 45312.

(10)

Since both sublists contain 45312, the list 54321 • recycle5 (S) is not a Gray code. Furthermore, the reader can verify that recycle6 (reuse5 (S)) is also not a Hamilton sequence. In other words, an arbitrary Hamilton sequence S cannot be recycled into a Hamilton sequence, even when S is the result of reusing a previous Hamilton sequence. We prove Theorem 2 by developing results in Sections 5-6.

Hamilton Cycles in Restricted Rotator Graphs

3.3

331

Hamilton Sequence for Rn ({2, 3, n})

This subsection proves that a Hamilton sequence for Rn ({2, 3, n}) can be obtained by recycling and then reusing Corbett’s Hamilton sequence. In other words, a Hamilton sequence for Rn (2, 3, n) can be obtained by repeated reusing followed by a single recycle and then a single reuse. Let E(n) = reusen (D(n−1)) denote this sequence and ΠE (n) = n n−1 · · · 1 ◦ E(n) denote its Gray code. More generally, Theorem 3 proves that a Hamilton sequence for Rn ({2, 3, n}) can be obtained by reusing any Hamilton sequence for Rn−1 ({n−2, n−1}). Theorem 3. If S is a Hamilton sequence in Rn−1 ({n−2, n−1}), then reusen (S) is a Hamilton sequence in Rn ({2, 3, n}). Proof. By the statement of the theorem, S is a Hamilton sequence for Rn−1 (G) for G = {n−2, n−1}. By theorem 1, reusen (S) is a Hamilton sequence in Rn (H) where H = {n−(n−2)+1, n−(n−1)+1, n} = {2, 3, n}.

4

Loopless Algorithm

In this section we show how to generate each symbol of Corbett’s Hamilton sequence C(n) for the rotator graph Rn in worst-case O(1)-time. Furthermore, our CorbettLoopless(n) algorithm is signiﬁcant because 1. It adapts a well-known algorithm for generating multi-radix numbers, and 2. A modiﬁcation generates Hamilton sequences in Rn ({n−1, n}) or Rn ({2, 3, n}). 4.1

Staircase Sequence

The staircase sequence S(n) is obtained from repeated applications of the step sequence operation as deﬁned below n−1 copies 2 if n = 1 stepn (i) = n, . . . , n , i and S(n) = (11) stepn (S(n−1)) if n > 1. The step operation is identical to the reuse operation except the ﬁnal symbol i has replaced n−i+1. Lemma 3 speciﬁes each value of Corbett’s sequence in terms of the staircase sequence and gives a simple condition for the occurrence of each value. Lemma 3. If the staircase sequence is S(n) = s1 , s2 , . . . , sn! and the Corbett sequence is C(n) = c1 , c2 , . . . , cn! and n ≥ 2, then for each i satisfying 1 ≤ i ≤ n!, we have si = j if n(n − 1) · · · (j + 1) divides i but n(n − 1) · · · (j + 1)j does not divide i, and ⎧ ⎪ n ⎪ ⎪ ⎪ ⎪ ⎪2 ⎪ ⎪ ⎪ ⎪ ⎪ ⎨n−1 ci = 3 ⎪ ⎪ ⎪ n−2 ⎪ ⎪ ⎪ ⎪ ⎪ ... ⎪ ⎪ ⎪ ⎩ n+1 2

if si if si if si if si if si ... if si

=n = n−1 = n−2 = n−3 = n−4 = 2.

332

B. Stevens and A. Williams

Proof. The result is true for n = 2 since S(2) = C(2) = 2, 2. Assume the result is true for S(k) = s1 , . . . , sk! and C(k) = c0 , . . . , ck! for k ≥ 2. When n = k+1, n−1 copies

n−1 copies

S(n) = step(S(n−1)) = n, . . . , n , s1 , . . . , n, . . . , n , sn−1! C(n) = reuse(C(n−1)) = n, . . . , n , n−c1 +1, . . . , n, . . . , n , n−cn−1! +1 n−1 copies

n−1 copies

so the result follows by induction by (11) and (8), respectively.

Algorithm 1. Generate the staircase sequence S(n) by StaircaseLoopless(n) and Corbett’s Hamilton sequence C(n) for rotator graph Rn by CorbettLoopless(n). Note: The ﬁnal symbol output by StaircaseLoopless(n) is 1 instead of 2 by (11). Require: StaircaseLoopless(n) 1: 2: a1 · · · an ← 0 · · · 0 3: f1 · · · fn ← 1 · · · n 4: loop 5: j ← f1 6: output(n−j+1) 7: if j = n then 8: return 9: end if 10: f1 ← 1 11: aj ← aj + 1 12: if aj = n−j then 13: aj ← 0 14: fj ← fj+1 15: fj+1 ← j + 1 16: end if 17: end loop

4.2

Require: CorbettLoopless(n) 1: r1 · · · rn ← n 2 n−1 3 · · · n+1 n+1 2 2 2: a1 · · · an ← 0 · · · 0 3: f1 · · · fn ← 1 · · · n 4: loop 5: j ← f1 6: output(rj ) 7: if j = n then 8: return 9: end if 10: f1 ← 1 11: aj ← aj + 1 12: if aj = n−j then 13: aj ← 0 14: fj ← fj+1 15: fj+1 ← j + 1 16: end if 17: end loop

Staircase Strings

Staircase sequences arise naturally in combinatorial generation. A string α = a1 a2 · · · an is a staircase string if its symbols satisfy 1 ≤ ai ≤ i for all 1 ≤ i ≤ n. In other words, staircase strings are multi-radix numbers with radices mi = i for 1 ≤ i ≤ n. Loopless Algorithm H in The Art of Computer Programming generates multi-radix numbers in reﬂected Gray code order, meaning that successive strings diﬀer by ±1 in a single symbol (see Knuth [8] pg. 20). In the special case of staircase strings, Algorithm H generates the ± indices according to the staircase sequence. For example, the Gray code appears below for n = 3 111, 112, 113, 123, 122, 121,

Hamilton Cycles in Restricted Rotator Graphs

333

where the ± indices follow S(3) = 3, 3, 2, 3, 3, 2 (cyclically). StaircaseLoopless(n) in Algorithm 1 gives our presentation of Algorithm H, which is simpliﬁed by removing references to the multi-radix number, the ± direction array d, and by “hard-coding” the radices mi = i for 1 ≤ i ≤ n. As in Knuth’s presentation, array f stores focus pointers. To generate C(n), we introduce an auxiliary array of constants n n r1 , r2 , r3 , r4 , · · · , rn−1 , rn = n, 2, n−1, 3, · · · , , 2 2 whose values are explained by Lemma 3. Finally, CorbettLoopless(n) in Algorithm 1 is obtained by replacing output(n−j+1) on line 6 by output(rj ). Theorem 4. CorbettLoopless(n) is a loopless algorithm that generates Corbett’s sequence C(n). By Theorem 2 algorithm CorbettLoopless(n) can instead generate the Hamilton sequence D(n) for Rn+1 ({n, n+1}) via recycling by replacing line 6 with output(n+1, n+1, n, . . . , n , n+1, . . . , n+1). rj −1 copies

n−rj copies

Similarly, by Theorem 1 the algorithm can generate the Hamilton sequence E(n) for Rn+2 ({2, 3, n+2}) via recycling and reusing by replacing line 6 with n+1 copies n+1 copies n+1 copies n+1 copies n+1 copies n+1 copies output(n+2, ..., n+2, 2, n+2, ..., n+2, 2, n+2, ..., n+2, 3, ..., n+2, ..., n+2, 3, n+2, ..., n+2, 2, ..., n+2, ..., n+2, 2). rj −1 copies n−rj copies

5

Corbett’s Successor Rule

In Section 4 we showed how to generate Corbett’s sequence C(n) one symbol at a time, with Algorithm CorbettLoopless(n) creating the entire sequence and requiring two auxiliary arrays. Theorem 5 gives a successor rule that describes how each string in Corbett’s Gray code ΠC (n) can be computed from the previous string without additional state. The theorem is illustrated after its proof. Theorem 5. Suppose α = a1 a2 · · · an ∈ Πn . Let x and y be the lengths of the longest preﬁx of the form n n−1 n−2 · · · and the longest suﬃx of the form · · · 3 2 1 in a2 a3 · · · an , respectively. The string that follows α in ΠC (n) is

σy+2 (α) if x > y (12a) β= σn−x (α) otherwise (x ≤ y). (12b) Proof. Suppose Corbett’s sequence is C(n) = c1 , c2 , . . . , cn! , Corbett’s Gray code is ΠC (n) = α1 , α2 , . . . , αn! , and n ≥ 2. Consider an arbitrary αi = a1 a2 · · · an in the Gray code. By using Lemma 2 and 3 the following conditions can be proven by induction on n

334

B. Stevens and A. Williams a2 = n ⇐⇒ ci = n, and an = 1 and a2 = n ⇐⇒ ci ∈ / {n, 2}, and a3 = n−1 and an = 1 and a2 = n ⇐⇒ ci ∈ / {n, 2, n−1}, and an−1 = 2 and a3 = n−1 and an = 1 and a2 = n ⇐⇒ ci ∈ / {n, 2, n−1, 3}, and . . . ⇐⇒ . . .

α = a1 n n−1 · · · p+2 p+1 aq+1 p−2 p−3 · · · 2 1 ⇐⇒ ci = p.

where p =

n+1 2

and q =

n+1 . The rule follows from these conditions. 2

For example, if α = 48756231 then x = 2 and y = 1 due to the underlined preﬁx and overlined suﬃx of 8756231, respectively. Therefore, the string after α in ΠC (8) is α σ3 = 48756231 σ3 = 87456231 by (12a) since x > y and y = 2. Theorem 5 also allows the lookup table of size n! to be avoided in Corbett’s original application involving point-to-point multiprocessor networks [2].

6

Recycling Corbett’s Sequence

In this section we prove a restatement of Theorem 2: If S = C(n) is the Corbett sequence for Rn , then recyclen+1 (S) is a Hamilton sequence in Rn+1 ({n, n+1}). Proof. We prove an arbitrary string in Πn+1 appears in n+1 n · · · 1 ◦ recycle(S) where S = C(n). Let this arbitrary string equal ai ai+1 · · · an n+1 b1 b2 · · · bi−1 for some i satisfying 1 ≤ i ≤ n+1. We choose this expression for our arbitrary string since we will ﬁnd α and β such that the following criteria hold 1. 2. 3. 4.

α has suﬃx ai ai+1 · · · an , and β has preﬁx b1 b2 · · · bi−2 , and α is followed by β in ΠC (n) by applying σr , and α ◦ recycle(r) contains the arbitrary string ai ai+1 · · · an n+1 b1 b2 · · · bi−1 .

The result is trivial when n+1 is in the ﬁrst, last, or second-last position of the arbitrary string. In the remaining cases we deﬁne the following – – – – –

γ := g1 g2 ...gn := b1 b2 ... bi−1 ai ai+1 ... an and p = n2 −1 and q = n2 −1, xb is the length of the longest n n−1 n−2 · · · preﬁx in g1 g2 · · · gi−2 , ya is the length of the longest · · · 3 2 1 suﬃx in gi gi+1 · · · gn , x is the length of the longest n n−1 n−2 · · · preﬁx in g1 g2 · · · gp , and y is the length of the longest · · · 3 2 1 suﬃx in gn−q+1 gn−q+2 · · · gn .

One diﬀerence between (xb , ya ) and (x , y ) is that the former considers b1 b2 · · · bi−2 and ai ai+1 · · · an separately, whereas the latter considers γ as a whole. Choose ⎧ ⎪ ⎨ bi−1 b1 b2 ... bi−2 ai ai+1 ... an α := gy +2 g1 g2 ... gy +1 gy +3 gy +4 ...gn ⎪ ⎩ gn−x g1 g2 ... gn−x −1 gn−x +1 gn−x +2 ...gn

if xb ≤ya

(13a)

if xb >ya and x > y (13b) if xb >ya and x ≤ y .(13c)

Hamilton Cycles in Restricted Rotator Graphs

335

In each case, we prove the ﬁrst criterion holds for the choice of α. For (13a) this result is obvious. For (13b) there are two cases two consider. If xb ≥ x , then y + 3 ≤ x + 2 ≤ xb + 2 ≤ i where the inequalities follow from x > y , xb ≥ x , and xb ≤ i − 2, respectively. On the other hand, if xb < x then it must be that ya = y and so y + 3 = ya + 3 ≤ xb + 2 ≤ i where the equalities and inequalities follow from y = ya , xb > ya , and xb ≤ i−2, respectively. In both cases, α has the suﬃx stated in the ﬁrst criterion. For (13c) it must be that i = n − ya + 1 and xb = x . Therefore, n − x + 1 = n − xb + 1 ≤ n − ya = i − 1 where the equalities and inequalities follow from xb = x , xb < ya , and i = n − ya + 1, respectively. Therefore, α has the suﬃx stated in the ﬁrst criterion. To complete the proof, use the successor rule from Theorem 5 to verify the remaining criteria. Theorem 2 also aﬃrms Conjecture 1 in [7]. That paper uses an equivalent notion of ‘recycling’ that acts on rotation Gray codes of Πn instead of Hamilton sequences of Rn . The conjecture is that Corbett’s Gray code is ‘recyclable’ and Theorem 2 equivalently proves that Corbett’s Hamilton sequence is ‘recyclable’.

7

Open Problems

The following open problems are related to this research: 1. 2. 3. 4.

Eﬃciently generate an explicit Hamilton cycle in Rn ({2, n}). Necessary and suﬃcient conditions for recyclable Hamilton sequences of Rn . A loopless algorithm for generating a recyclable order of Πn in an array. The diameter of Rn (G) for G = {n−1, n} and G = {2, 3, n} and others.

For the fourth problem, we mention that Corbett showed the diameter of Rn is small [2] and discussed applications of this fact. For the third problem, we mention that there are many loopless algorithms that generate successive permutations in an array, but none are known to be ‘recyclable’ using the terminology from [7]. In fact, the known recyclable orders using rotations by Corbett [2] and Williams [13] cannot be generated by a loopless array-based algorithm since σn cannot be implemented in constant time. Acknowledgement. The authors wish to thank all three referees for helpful comments. In particular, we wish to thank one referee who made several corrections and the observation that the direction array d could be removed from our initial presentation of Algorithm 1.

336

B. Stevens and A. Williams

References 1. Compton, R.C., Williamson, S.G.: Doubly Adjacent Gray Codes for the Symmetric Group. Linear and Multilinear Algebra 35(3), 237–293 (1993) 2. Corbett, P.F.: Rotator Graphs: An Eﬃcient Topology for Point-to-Point Multiprocessor Networks. IEEE Transactions on Parallel and Distributed Systems 3, 622–626 (1992) 3. Corbett, P.F., Scherson, I.D.: Sorting in Mesh Connected Multiprocessors. IEEE Transactions on Parallel and Distributed Systems 3, 626–632 (1992) 4. Ehrlich, G.: Loopless Algorithms for Generating Permutations, Combinations and Other Combinatorial Conﬁgurations. IEEE Transactions on Parallel and Distributed Systems 3, 626–632 (1992); Journal of the ACM 20(3), 500–513 (1973) 5. Hamada, Y., Bao, F., Mei, A., Igarashi, Y.: Nonadaptive Fault-Tolerant File Transmission in Rotator Graphs. IEICE Transactions on Fundamentals of Electronics, Communications and Computer Sciences E79-A 4, 477–482 (1996) 6. Holroyd, A., Ruskey, F., Williams, A.: Faster Generation of Shorthand Universal Cycles for Permutations. In: Thai, M.T., Sahni, S. (eds.) COCOON 2010. LNCS, vol. 6196, pp. 298–307. Springer, Heidelberg (2010) 7. Holroyd, A., Ruskey, F., Williams, A.: Shorthand Universal Cycles for Permutations. Algorithmica (to appear) 8. Knuth, D.E.: The Art of Computer Programming. Generating All Tuples and Permutations, Fascicle 2, vol. 4. Addison-Wesley (2005) 9. Kuo, C.-J., Hsu, C.-C., Lin, H.-R., Lin, K.-K.: An Eﬃcient Algorithm for Minimum Feedback Vertex Sets in Rotator Graphs. Information Processing Letters 109(9), 450–453 (2009) 10. Lin, H.-R., Hsu, C.-C.: Topological Properties of Bi-Rotator Graphs. IEICE Transactions on Information and Systems E86-D(10), 2172–2178 (2003) 11. Ponnuswamy, S., Chaudhary, V.: Embedding of Cycles in Rotator and Incomplete Rotator Graphs. In: Proceedings of the Sixth IEEE Symposium on Parallel and Distributed Processing, October 26-29, pp. 603–610 (1994) 12. Ruskey, F., Williams, A.: An Explicit Universal Cycle for the (n−1)-Permutations of an n-set. ACM Transactions on Algorithms 6(3), article 45 (2010) 13. Williams, A.: Loopless Generation of Multiset Permutations Using a Constant Number of Variables by Preﬁx Shifts. In: Proceedings of the Twentieth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2009, New York, NY, USA, January 4-6, pp. 987–996 (2009) 14. Yasuto, S., Ken’Ichi, K., Mario, N.: Node-Disjoint Paths Problem in a Rotator Graph. Joho Shori Gakkai Shinpojiumu Ronbunshu 14, 93–100 (2003)

Eﬃcient Codon Optimization with Motif Engineering Anne Condon and Chris Thachuk Department of Computer Science, University of British Columbia, Vancouver, BC, Canada V6T 1Z4 {condon,cthachuk}@cs.ubc.ca

Abstract. It is now common to add protein coding genes into cloning vectors for expression within non-native host organisms. Codon optimization supports translational eﬃciency of the desired protein product, by exchanging codons which are rarely found in the host organism with more frequently observed codons. Motif engineering, such as removal of restriction enzyme recognition sites or addition of immuno-stimulatory elements, is also often necessary. We present an algorithm for optimizing codon bias of a gene with respect to a well motivated measure of bias, while simultaneously performing motif engineering. The measure is the previously studied codon adaptation index, which favors the use, in the gene to be optimized, of the most abundant codons found in the host genome. We demonstrate the eﬃciency and eﬀectiveness of our algorithm on the GENCODE dataset and provide a guarantee that the solution found is always optimal.

1

Introduction

Gene synthesis is now an economical and technically viable option for the construction of non-natural genes. Synthetic genes can be novel or derivatives of those found in nature. In either case, the expression levels of these genes, when inserted into the genome of a host organism, depend on many factors. One important factor is the bias of codon usage, relative to the host organism [16,7,10]. Note that for each amino acid in a protein, there may be many (up to six) valid codons, as given by the genetic code. Loosely speaking, the codon bias of a gene for the protein measures how well – or poorly – codons used in the gene match codon usage in the genome of a host organism (we describe speciﬁc measures later in this paper). Several studies have indicated that [10,3,11] codon optimization is necessary to ensure designed genes are maximally expressed within the host. In addition to optimizing the codon bias of a gene relative to the genome of a host, it is often desirable to add or remove certain motifs via silent mutation, whereby DNA sequence is altered without changing the expressed amino acid sequence. Removal or addition of motifs can be treated as optimization criteria to be minimized or maximized. For example, with immuno-regulatory CpG C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 337–348, 2011. c Springer-Verlag Berlin Heidelberg 2011

338

A. Condon and C. Thachuk

motifs in mammalian expression vectors [13] it is desirable to minimize immunoinhibitory elements and maximize immuno-stimulatory motifs. In the remainder of this work, we will refer to inclusion or exclusion of motifs, via silent mutation, as motif engineering. A number of published software tools are capable of codon optimization, including DNA Works [8], Codon Optimizer [2], GeMS [9], Gene Designer [17], JCat [4], OPTIMIZER [12], the Synthetic Gene Designer [18], UpGene [3] and a method by Satya et. al [13]. Some of these methods also consider the other problem considered here, motif engineering. Of these, only the method of Satya et. al provides a mathematical guarantee of ﬁnding an optimal solution when one exists. However, their method – based on the graph theoretic approach of ﬁnding a critical path – runs in O(n2 ) time and space, where n is the length of the DNA sequence being optimized. In this work, we propose the ﬁrst linear time and space codon optimization algorithm, which is guaranteed to ﬁnd an optimal solution that also satisﬁes motif engineering constraints. We have focused our attention on optimizing codon usage according to the Codon Adaptation Index (CAI). The index, originally proposed by Sharp and Li [14], is based on the premise of each amino acid having a ‘best’ codon for a particular organism. This perspective evolved from the observation that protein expression is higher in genes using codons of high ﬁtness and lower in genes using rare codons [6]. It is believed that this is due to the relative availability of tRNAs within a cell. We also provide an experimental study of the performance of our algorithm on a biological data set comprising 3,157 coding sequence regions of the GENECODE subset of the Encode dataset [15]. The remainder of this paper is structured as follows. In the Preliminaries section, we formally deﬁne the problem of codon optimization. We detail the general objectives of the problem, and formalize the goals of motif engineering. We then present our algorithm, providing a proof of correctness and time and space analysis. In the Empirical Results section, we describe the performance of our algorithm, both in terms of run-time eﬃciency and also in terms of the quality of optimization achieved. Finally, we conclude with a summary of our major ﬁndings and directions for future work.

2

Preliminaries

A DNA strand is a string over the alphabet of DNA. A codon is a triple over the DNA alphabet and therefore there are at most 43 = 64 distinct codons. An amino acid sequence is a string over the alphabet of amino acids, ΣAA = {Ala, Arg, Asn,. . . ,T yr,V al,stop}, with each symbol representing an amino acid and the special symbol ‘stop’ denoting a string terminal. We assume there is a predetermined ordering of amino acids, for example, lexicographic. Therefore, we can represent an amino acid sequence A as a sequence of integers, with A = α1 , α2 , . . . , α|A| , where 1 ≤ αk ≤ 21, for 1 ≤ k ≤ |A|. We denote the ith amino acid by λ(i). The genetic code is a mapping between amino acids and codons. However, as there are 64 possible codons and only 20 amino

Eﬃcient Codon Optimization with Motif Engineering Trp

His

Arg

Trp

TGG

CAC

AGA

TGG

CAT

AGG

339

CGA

CGC

CGG

CGT

Fig. 1. Shown above is an instance consisting of four amino acids, a forbidden set F = { CGC, CGA, CGG, ACC, TAG }, a desired set D = { TTG, GGT, CCG }, and therefore k = 1. Arginine has six corresponding codons, however, three of them appear in F and are shown with red boxes. A valid codon assignment for this instance must contain no occurrence of a forbidden motif and one occurrence of a desired motif. There are two valid codon assignments for this problem instance, shown as paths with bold edges. The top (bottom) path denotes an assignment containing the desired motif GGT (TTG).

acids (plus one stop symbol), the code is degenerate, resulting in a one-to-many mapping from each amino acid to a set of corresponding codons. We deﬁne |λ(i)| to be the number of codons corresponding to the ith amino acid and λj (i) to be the j th such codon, 1 ≤ j ≤ |λ(i)|, where again we use lexicographic ordering. Therefore, we can deﬁne a codon design, with respect to an amino acid sequence, as a sequence of codon indices. Again consider the problem instance in Figure 1. For the Arginine amino acid (Arg) which is the second amino acid in lexicographic order, |λ(2)| = 6 and λ3 (2) is the codon CGA. The DNA sequence TGA CAC CGA TGG can be represented by the codon index sequence S = 1, 1, 3, 1. A codon’s frequency is the number of times that it appears in nature, divided by the total number of times that all codons corresponding to the same amino acid appear in nature. By “in nature”, we mean codon frequencies present in some reference sequence or set of sequences such as a genome or set of genomes. As an example, if for some amino acid index i, |λ(i)| = 2, and the codon λ1 (i) is observed 37 times in nature, while λ2 (i) is observed 63 times, we can deﬁne the 37 frequency of λ1 (i) to be 37+63 = 0.37. Let ρj (i) denote the frequency of the j th |λ(i)| codon of the ith amino acid, 1 ≤ j ≤ |λ(i)|. Note that j=1 ρj (i) = 1.0, for any i, assuming λ(i) is in the reference set. In the example above, we say that λ2 (i) is the most frequent codon. Note that it is possible for more than one codon to have this property.

340

A. Condon and C. Thachuk

A codon’s fitness is the number of times that it appears in nature, divided by the number of occurrences of the corresponding most frequent codon (originally referred to as the relative adaptiveness of a codon [14]). Let τj (i) denote the ﬁtness value of the j th codon of the ith amino acid. Returning to our previous example, if the ith amino acid has two codons with frequencies ρ1 (i) = 0.37 and ρ2 (i) = 0.63, then their ﬁtness values, denoted by τ1 (i) and τ2 (i) respectively, are 0.37/0.63 ≈ 0.59 and 0.63/0.63 = 1.0. Note that a most frequent codon will always have a ﬁtness value of 1.0. Motif Engineering. We focus our attention on designing codon sequences which minimize occurrences of forbidden motifs from a predetermined set, F , while maximizing occurrences of desired motifs from a predetermined set, D. A codon design – a sequence of codon assignments – is said to be valid with respect to an amino acid sequence it codes for if it satisﬁes the following constraints, in order: the DNA sequence corresponding to the codon design (1) contains the minimum possible number of forbidden motifs, and (2) contains the maximum possible number of desired motifs, given that (1) is satisﬁed. It is important to recognize that a valid design does not necessarily guarantee that the number of occurrences of desired motifs is the maximum number possible, of all possible codon designs. Again, consider the problem instance of Figure 1. Two codon designs result in a minimum number of forbidden motif occurrences (none), shown with paths having bold edges. Both of these paths also contain one occurrence of a desired motif. The top (bottom) path denotes an assignment containing the desired motif GGT (TTG). Therefore, a valid codon design for this instance, by our previous deﬁnition, contains no forbidden motifs and one desired motif. Notice that the DNA sequence TGG CAC CGG TGG, corresponding to a codon design S = 1, 1, 5, 1, actually contains more desired motifs (two) than a valid codon design; however, it does contain one forbidden motif and therefore cannot be valid. We now develop some notation for motif engineering. For a sequence of amino acid indices A = α1 , α2 , . . . , α|A| , a corresponding codon design S = c1 , c2 , . . . , c|A| , a set of forbidden motifs F and a set of desired motifs D, let MF (λci (αi ) . . . λcj (αj )) and MD (λci (αi ) . . . λcj (αj )) be the number of occurrences of forbidden motifs and desired motifs, respectively, in the DNA sequence λci (αi ) . . . λcj (αj ), where j ≥ i. For convenience in our algorithms, we also in troduce MF (λci (αi ) . . . λcj (αj )) and MD (λci (αi ) . . . λcj (αj )) which respectively determine the number of forbidden and desired motifs in λci (αi ) . . . λcj (αj ) that end within the last codon position (the last 3 bases), here indexed by j. For instance consider the codon design S = 1, 1, 5, 1 of the problem instance in Figure 1. MD (TGGCACCGGTGG) = 2 as it contains the motifs CCG and GGT, however, MD (TGGCACCGGTGG) = 1 as only the motif GGT ends within the last codon. In practice, forbidden and desired motifs are short and we assume their length is bounded by a constant, g [13].

Eﬃcient Codon Optimization with Motif Engineering

341

Observation 1. If the largest forbidden or desired motif is of length g, then any forbidden or desired motif can span at most k + 1 consecutive codons, where k = g/3. Codon Optimization. The codon adaption index (CAI) is a metric deﬁned in terms of the relative ﬁtness of codons constituting a codon design. For some codon design S = c1 , c2 , . . . , c|A| , which correctly codes for a desired amino acid sequence A = α1 , α2 , . . . , α|A| , the CAI value for S with respect to A, CAI(S, A), can be calculated as in Eqn. (1). Based on this deﬁnition, if S consists only of most frequent codons, it would have a CAI value of 1.0. Intuitively, the higher the CAI value, the better. ⎛ CAI(S, A) = ⎝

|A|

1 ⎞ |A|

τci (αi )⎠

(1)

i=1

With the previously deﬁned deﬁnitions, notation, and optimization criteria, we now formally deﬁne the problem of codon optimization with motif engineering. The CAI Codon Optimization Problem with Motif Engineering Instance: Amino acid sequence represented by the sequence of indices A = α1 , α2 , . . . , α|A| , a set of forbidden motifs F, and a set of desired motifs D. Problem: Find a codon design S ∗ , with |S ∗ | = |A|, corresponding to A such that S ∗ is valid, with respect to F and D, and CAI(S ∗ , A) = max{CAI(S, A)|S ∈ S(A)}, where S(A) is the set of all valid codon designs corresponding to A. S ∗ is an optimal codon design with respect to the CAI measure.

3

A DP Algorithm for CAI Optimization

We now propose a linear time and space dynamic programming algorithm guaranteed to maximize the CAI measure, such that the codon design is valid. In terms of eﬃciency, this is a direct improvement in both run-time and space over the current state-of-the-art, previously proposed by Satya et al. [13]. Although we have chosen to ﬁrst ensure forbidden motifs are minimized, then desired motifs maximized and ﬁnally the CAI value maximized, it should be clear that the algorithm we present can be adapted to optimize these criteria in any order. One necessary feature of a codon optimization algorithm is an eﬃcient means to detect if a forbidden motif from F, or a desired motif from D, is present in a potential design. For both algorithms proposed in this work, we utilize an AhoCorasick search for this purpose. Brieﬂy, the Aho-Corasick algorithm builds a keyword tree (trie) for F and transforms the structure into an automaton with the addition of failure links. Space and time complexity for building the initial structure is O(h), where h is the sum of the lengths of the motifs in F. Queries to determine if a sequence b contains any forbidden motif take O(|b|) time [1]. Likewise, a second tree is constructed for the desired motifs in D. For a detailed

342

A. Condon and C. Thachuk

description of the algorithm and existing applications of its use in computational biology, see Gusﬁeld [5]. We note that Satya et. al [13] use the same approach for motif detection in their θ(n2 ) algorithm. We note that any dictionary matching algorithm can be employed for the same task; however, Aho-Corasick automata were chosen due to their simpler implementation. We ﬁrst deﬁne three quantities that will be important in describing our algorithm. The ﬁrst quantity, Fcii−k+1 ,...,ci−1 ,ci , denotes the minimum possible number of forbidden motifs in a DNA sequence which codes for an amino acid sequence A = α1 , α2 , . . . , αi , given that the last k codons (of i total codons) have indices denoted as ci−k+1 , . . . , ci−1 , ci . Similarly, the second quantity, Dci i−k+1 ,...,ci−1 ,ci , denotes the maximum possible number of desired motifs, among those sequences which contain a minimum number of forbidden motifs. Pcii−k+1 ,...,ci−1 ,ci denotes the maximum possible CAI score among all valid sequences. Our algorithm stores a k-dimensional entry for each position i, k ≤ i ≤ |A|, of the input amino acid sequence, where k = g/3 and g is the constant bounding the length of any forbidden or desired motif. The base case occurs when i = k and is computed as follows. Every combination of codons for the ﬁrst k amino acids is evaluated to determine, independently, the number of forbidden and desired motifs fully contained within the k consecutive codons (Eqn. (2) and Eqn. (3), respectively) and the CAI value (Eqn. (4)). Fck1 ,c2 ,...,ck−1 ,ck = MF λc1 (α1 )λc2 (α2 ) . . . λck−1 (αk−1 )λck (αk ) Dck1 ,c2 ,...,ck−1 ,ck = MD λc1 (α1 )λc2 (α2 ) . . . λck−1 (αk−1 )λck (αk ) Pck1 ,c2 ,...,ck−1 ,ck =

k

(τci (αi ))

(2) (3) (4)

i=1

The recursive case occurs for i > k. By Observation 1, a forbidden motif could span k + 1 codons. Therefore, it is necessary to evaluate the last k + 1 codons of a potential design to ensure codons are selected which 1) minimize forbidden motifs, then 2) maximize desired motifs, then 3) maximize the CAI score. For any arbitrary assignment of the last k codons, we select the codon preceding them, denoted by the index ci−k , such that the sum of forbidden motifs ending at position i − 1, Fci−1 , and the count of new forbidden motifs i−k ,...,ci−2 ,ci−1 which end in the new codon ci , determined by the function MF , is minimized. The number of forbidden motifs is recorded. Fcii−k+1 ,...,ci−1 ,ci = min1≤ci−k ≤|λ(αi−k )|

Fci−1 λ + M (α ) . . . λ (α )λ (α ) ci−k i−k ci−1 i−1 ci i F i−k ,...,ci−2 ,ci−1

(5)

Similarly, D is calculated in the same manner, after ensuring that the minimal number of forbidden motifs criteria is ﬁrst satisﬁed.

Eﬃcient Codon Optimization with Motif Engineering

343

Dci i−k+1 ,...,ci−1 ,ci = max1≤ci−k ≤|λ(αi−k )| ⎧ −∞ ⎪ ⎪ ⎪ ⎪ ⎨

⎫ + , if Fci−1 ⎪ i−k ,...,ci−2 ,ci−1 ⎪ ⎪ MF λci−k (αi−k ) . . . λci−1 (αi−1 )λci (αi ) ⎪ ⎬ i = Fci−k+1 ,...,ci−1 ,ci ⎪ ⎪ ⎪ ⎪ D i−1 ,...,c ⎪ ⎪ ⎪ ⎪ , otherwise i−2 ,ci−1 ⎩ ci−k ⎭ +MD λci−k (αi−k ) . . . λci (αi ) (6) Likewise, P is calculated to ﬁrst ensure forbidden motifs are minimized, followed by desired motifs being maximized. Of these possible codon assignments, the one with the highest CAI value is selected and the score recorded. Pcii−k+1 ,...,ci−1 ,ci = max1≤ci−k ≤|λ(αi−k )| ⎧ ⎪ ⎪ −∞ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎩

, if

Fci−1 i−k ,...,ci−2 ,ci−1 + MF λci−k (αi−k ) . . . λci (αi ) = Fcii−k+1 ,...,ci−1 ,ci

⎫ ⎪ ⎪ ⎪ ⎪ ⎬

∨Dci−1 i−k ,...,ci−2 ,ci−1 ⎪ ⎪ +MD λci−k (αi−k ) . . . λci (αi ) = Dci i−k+1 ,...,ci−1 ,ci ⎪ ⎪ ⎭ , otherwise (7)

τci (αi ) × Pci−1 i−k ,...,ci−2 ,ci−1

Eqn. (10) determines the optimal CAI score up to position i of the input amino acid sequence. Therefore, the optimal CAI value of some input sequence A of |A| length |A| is given by Pk , where i = F k

min

1≤ci ≤|λ(αi )| 1≤ci−1 ≤|λ(αi−1 )|

Fcii−k+1 ,...,ci−1 ,ci

(8)

.. .

1≤ci−k+1 ≤|λ(αi−k+1 )|

i = D k

max

1≤ci ≤|λ(αi )| 1≤ci−1 ≤|λ(αi−1 )|

i Dci i−k+1 ,...,ci−1 ,ci , if Fcii−k+1 ,...,ci−1 ,ci = F k −∞ , otherwise

(9)

.. .

1≤ci−k+1 ≤|λ(αi−k+1 )|

i = P k

⎧ ⎪ ⎨ max

1≤ci ≤|λ(αi )| 1≤ci−1 ≤|λ(αi−1 )|

.. .

⎪ ⎩

Pcii−k+1 ,...,ci−1 ,ci −∞

⎫ i ⎪ , if Fcii−k+1 ,...,ci−1 ,ci = F k ⎬ i i ∧Dci−k+1 ,...,ci−1 ,ci = Dk ⎪ (10) ⎭ , otherwise

1≤ci−k+1 ≤|λ(αi−k+1 )|

The correctness of the algorithm can be shown by induction on the position in the amino acid sequence. Lemma 1 shows that Eqn. (7) gives an optimal score

344

A. Condon and C. Thachuk

under the assumption that the previous k codons are ﬁxed. Since Eqn. (10) evaluates all combinations of the previous k codons, Theorem 1 states that an optimal design must be found, if one exists. Lemma 1. Pcii−k+1 ,,...,ci−1 ,ci of Eqn. (7) correctly determines the score of the optimal valid codon design up to the ith codon position, having the codon assignment ci−k+1 , . . . , ci−1 , ci for the last k codons, given that the maximum length of any motif is 3k. Proof. We will argue by induction. The base case (i = k) is trivially valid as Eqn. (4) correctly determines the CAI score of the ﬁrst k codons, by deﬁnition. correctly determines the score of an optimal valid Assume Pci−1 ,...,c ,c i−k

i−2

i−1

codon assignment, up to position i−1, having the codon assignment ci−k , . . . , ci−2 , ci−1 for the last k codons. Similarly, assume F i−1 and D i−1 are also correct for the corresponding codon assignment. When moving one position ahead, from i − 1 to i, we must consider the case of any new motifs we may introduce. By Observation 1, any new motif which ends within codon ci could not extend past codon ci−k . There are at most 6 possible codon assignments to position ci−k that can directly precede a speciﬁc codon assignment ci−k+1 , . . . , ci−1 , ci ending at position i as there are at most 6 codons for any amino acid. Therefore,the optimal assignment(s) to ci−k must be a subset of these possibilities. MF λci−k (αi−k ) . . . λci−1 (αi−1 )λci (αi ) calculates the number of new forbidden motifs introduced in the codon assignment ci−k , . . . , ci−1 , ci which end in codon ci . By our assumption, Fci−1 correctly determines the minimum numi−k ,...,ci−2 ,ci−1 ber of forbidden motifs having codon assignment ci−k , . . . , ci−2 , ci−1 , ending at position i − 1. Therefore, the sum of these two quantities correctly determines the minimum number of forbidden motifs. As codons ci−k+1 , . . . , ci−1 , ci are ﬁxed, and Eqn. (5) evaluates every possible assignment to ci−k to determine a minimum, then it must be the case that Fcii−k+1 ,...,ci−1 ,ci is the minimum number of forbidden motifs up to position i, having the codon assignment ci−k+1 , . . . , ci−1 , ci for the last k codons. We argue similarly for Dci i−k+1 ,...,ci−1 ,ci in Eqn. (6) with the addition that any assignment of ci−k also be forbidden motif minimal ensured by line 1 of the equation. Finally, consider Pcii−k+1 ,...,ci−1 ,ci . Line 1 of Eqn. (10) assigns the value −∞ if the codon assignment ci−k , . . . , ci−1 , ci is not valid. For all assignments which are valid, the equation (line 2) determines the CAI score by multiplying the optimal score up to position i−1 (guaranteed optimal by our assumption) with the ﬁtness of the codon represented by ci for amino acid αi . Since every assignment to codon ci−k is evaluated and the maximum is determined, then it must be the case that Pcii−k+1 ,...,ci−1 ,ci correctly determines the score of the optimal valid codon design up to the ith codon position, having the codon assignment ci−k+1 , . . . , ci−1 , ci for the last k codons, given that the maximum length of any motif is 3k. i of Eqn. (10) correctly determines the score of an optimal valid Theorem 1. P k codon design, with respect to CAI value, up to the ith codon, given that the maximum length of any motif is 3k.

Eﬃcient Codon Optimization with Motif Engineering

345

Proof. Lemma 1 guarantees that Pcii−k+1 ,...,ci−1 ,ci correctly determines the score of the optimal valid codon design up to the ith codon, having the codon assignment ci−k+1 , . . . , ci−1 , ci for the last k codons, given that the maximum length of any motif is 3k. Therefore, if every possible assignment of the last k codons is evaluated, a maximum of 6k possibilities, the score of an optimal valid codon design ending at position i can easily be determined. i correctly determines the minimum number of forbidden First, consider that F k motifs possible, up to position i, by evaluating all possible assignments of that i evaluates the maximum number of desired motifs last k codons. Similarly, D k possible, by ﬁrst ensuring that the minimum number of forbidden motifs criteria is satisﬁed. Finally, by evaluating all possible codon assignments of the last k i codons, and determining the maximum score of all those which are valid, P k must determine the optimal valid CAI score, up to position i. Under the assumption that the maximum length of any motif is constant, Theorem 2 proves that the overall time and space complexity is linear. Theorem 2. The dynamic programming algorithm for CAI optimization finds a valid nucleic acid sequence design for an amino acid sequence A in O(|A| + h) time and O(|A| + h) space, where h is the total length of forbidden and desired motifs and all motifs are of constant length.

4

Empirical Results

Data Set. We use a ﬁltered set of the 3,891 CDS (coding DNA sequence) regions of the GENECODE subset of the Encode dataset [15] (version hg17 NCBI build 35). This curated dataset comprises approximately 1% of the human genome and is representative of several its characteristics such as distribution of gene lengths and GC composition (54.31%). After ﬁltering any sequences less than 75 bases in length, the remaining 3,157 CDS regions range in length from 75 to 8186 bases, averaging 173 bases with 267 bases standard deviation. Codon Frequencies. In all cases, we use the codon frequencies of Escherichia coli as reported by the Codon Usage Database [http://www.kazusa.or.jp/codon]. Implementation and Hardware. All algorithms were implemented in C++ and compiled with g++ (GCC 4.1.0). Experiments were run on our reference Pentium IV 2.4 GHz processor machines, with 1GB main memory and 256 Kb of CPU cache, running SUSE Linux version 10.1. 4.1

Results

To evaluate the eﬀectiveness and eﬃciency of our algorithm, a forbidden and desired motif set were constructed which could be considered typical in practice.

346

A. Condon and C. Thachuk

It is common for a gene synthesis experiment to use a single restriction enzyme. Furthermore, for reasons aﬀecting gene expression, a common task is the removal of polyhomomeric regions (consecutive repeat region of identical nucleotides). Therefore, we have created a forbidden motif set containing ten elements including GAGTC, GACTC, AAAA, TTTT, GGGG, and CCCC where GAGTC is the motif for the MlyI restriction enzyme, GACTC is its reverse complement and the other motifs ensure no polyhomomeric regions greater than length three are permitted. The other four elements of the forbidden motif set (not shown) are immuno-inhibitory motifs originally used in the work of Satya et. al [13]. That work also used a desired motif set consisting entirely of thirty-three immuno-stimulatory motifs. We use this same desired motif set in our study. Performance of the CAI Optimization Algorithm Results are shown for all 3,157 sequences in Figure 2. On the left side of the ﬁgure, the diﬀerence in optimal CAI value and the original CAI value of each sequence, when forbidden motifs are minimized, is plotted against sequence length. Desired motifs were not considered. For all sequences, the CAI value is improved compared with the original, with an average improvement of approximately 0.27. Shown on the right is the diﬀerence in CAI value for each sequence when the forbidden motifs are minimized and then the desired motifs are maximized. For this case, the average improvement of CAI value drops to 0.18, with only 12 sequences ( 0.4%) reporting a worse CAI value than the original. A summary of CAI statistics is presented in Table 1. In virtually all cases, forbidden motifs were eliminated entirely. Less than 2% of all sequences contained more than one forbidden motif after optimization, with only 0.6% containing more than two. On average 10 motifs were added to optimized sequences, when desired motifs were considered. These results demonstrate that it is possible to engineer motifs while still optimizing codon usage considerably. The runtime of the algorithm scales linearly with sequence length as would be expected. Considering desired motifs, in addition to forbidden motifs, increases run-time by a small constant Table 1. The mean values and standard deviations (averaged over 3,157 sequences) of CAI score, number of forbidden motifs, and number of desired motifs are shown for the original sequences (wild-types), the optimized sequences with forbidden motifs minimized and the optimized sequences with forbidden motifs minimized and then desired motifs maximized.

motif sets none (wild-types) forbidden forbidden and desired

CAI value (std. dev.)

# forbidden (std. dev.)

# desired (std. dev.)

0.6477 (0.06) 0.9161 (0.04) 0.8280 (0.05)

9.2372 (16.24) 0.1384 (0.45) 0.1384 (0.45)

0.4869 (1.06) 0 (0.00) 10.1324 (14.84)

● ●

0.1

●

0.3

●

●

0.2

●

CAIafter − CAIbefore

0.4

0.5

0.6

347

0.0

●

●●

●

●

●

● ● ● ● ● ●● ● ●● ●●● ●● ●● ● ● ● ● ● ● ●● ● ● ●●● ● ● ●●● ● ● ● ●●●●● ● ● ● ● ●● ● ●● ● ●● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ●● ● ● ●●● ● ● ● ● ● ● ●●● ●● ●●● ● ●● ● ● ● ● ● ●● ● ● ● ●●● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●●● ●● ● ●●● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●●●● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●●●●● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ●● ●●● ● ●● ● ● ● ● ● ●● ●●● ● ● ● ● ● ● ●●● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ●●● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ●● ● ● ●●● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ●● ● ● ●● ● ●● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●●● ● ● ●● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●●●● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ● ●● ● ● ●● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●● ● ●● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ●● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ●●● ●●●●● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ●●● ●● ● ● ● ● ● ●●● ●● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●●● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ●● ●● ● ● ● ● ● ● ● ●●●●● ● ● ● ●●●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ●●● ● ●●● ● ● ●●● ●● ● ● ● ●● ●● ● ● ●● ● ●●● ● ● ● ● ●● ● ● ● ● ● ● ●

● ●

● ●

●

●

−0.1

0.3 0.2

● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ●●●● ●● ● ●●●●●● ●● ●● ● ● ● ● ● ●● ● ● ●●● ● ●● ● ● ● ● ● ●● ● ●●● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ●● ● ●● ● ● ●● ●● ● ● ● ● ● ● ●●● ● ●● ●● ● ● ● ● ● ● ●●● ● ●● ● ● ● ● ● ●● ● ● ● ●● ●● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ●●● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ●●● ● ●●●●● ● ●●● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●●●●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ●●● ●● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ●●● ● ● ●● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ●●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●●●●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ●● ●●●● ● ● ● ●● ● ●● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●●●●●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ●● ●● ● ● ● ● ●● ● ● ●● ● ●● ● ● ● ●●● ● ● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●● ●●● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ●● ●●●● ● ●●● ● ● ●● ● ● ● ● ● ● ● ●● ● ●●● ● ●●● ●● ● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●●

−0.1

0.0

0.1

CAIafter − CAIbefore

0.4

0.5

0.6

Eﬃcient Codon Optimization with Motif Engineering

100

200

500

1000

2000

sequence length [log scale]

5000

100

200

500

1000

2000

5000

sequence length [log scale]

Fig. 2. Results are shown for the diﬀerence between the optimal CAI value and the original CAI value, plotted against sequence length, for each of the 3,157 sequences. On the left, results are shown when only the forbidden motif set is considered. The right side shows the results when both the forbidden and desired motif sets are considered.

factor, on average. In the worst case, the algorithm terminates in 0.43 CPU seconds for the longest sequence (8,141 bases).

5

Conclusions

In this work we have presented the ﬁrst linear time and space algorithm for the problem of optimizing the codon adaptation index (CAI) value of a gene. The algorithm provides a guarantee that codon designs will be found which have a minimum number of forbidden motifs from some user deﬁned set. The algorithm is also capable of adding desirable motifs, when applicable. A formal proof of correctness and time and space analysis was given. An extensive empirical analysis of the algorithm has shown it to be highly eﬀective and eﬃcient in practice. An eﬃcient algorithm is a crucial ﬁrst step towards designing genes while considering other important sequence features. For instance, designing genes with a guarantee that the resulting nucleic acid sequence does not form stable nucleic acid secondary structure is an interesting future direction, and one that may greatly eﬀect translational eﬃciency. Acknowledgments. The authors would like to thank the anonymous reviewers for their constructive suggestions to improve the presentation of this manuscript.

References 1. Aho, A.V.: Algorithms for ﬁnding patterns in strings, pp. 255–300. MIT Press, Cambridge (1990) 2. Fuglsang, A.: Codon optimizer: a freeware tool for codon optimization. Protein Expression and Puriﬁcation 31(2), 247–249 (2003)

348

A. Condon and C. Thachuk

3. Gao, W., Rzewski, A., Sun, H., Robbins, P.D., Gambotto, A.: Upgene: Application of a web-based dna codon optimization algorithm. Biotechnology Progress 20(2), 443–448 (2004) 4. Grote, A., Hiller, K., Scheer, M., M¨ unch, R., N¨ ortemann, B., Hempel, D.C., Jahn, D.: Jcat: a novel tool to adapt codon usage of a target gene to its potential expression host. Nucleic Acids Research 33(web Server issue), 526–531 (2005) 5. Gusﬁeld, D.: Algorithms on strings, trees, and sequences. Cambridge Press, New York (1997) 6. Gustafsson, C., Govindarajan, S., Minshull, J.: Codon bias and heterologous protein expression. Trends in Biotechnology 22(7), 346–353 (2004) 7. Holm, L.: Codon usage and gene expression. Nucleic Acids Research 14(7), 3075– 3087 (1986) 8. Hoover, D.M., Lubkowski, J.: Dnaworks: an automated method for designing oligonucleotides for pcr-based gene synthesis. Nucleic Acids Research 30(10), e43 (2002) 9. Jayaraj, S., Reid, R., Santi, D.V.: Gems: an advanced software package for designing synthetic genes. Nucleic Acids Research 33(9), 3011–3016 (2005) 10. Kane, J.F.: Eﬀects of rare codon clusters on high-level expression of heterologous proteins in escherichia coli. Current Opinion in Biotechnology 6(5), 494–500 (1995) 11. Lithwick, G., Margalit, H.: Hierarchy of sequence-dependent features associated with prokaryotic translation. Genome Research 13(12), 2665–2673 (2003) 12. Puigbo, P., Guzman, E., Romeu, A., Garcia-Vallve, S.: OPTIMIZER: a web server for optimizing the codon usage of DNA sequences. Nucleic Acids Research 35(suppl.2), W126–W131 (2007) 13. Satya, R.V., Mukherjee, A., Ranga, U.: A pattern matching algorithm for codon optimization and cpg motif-engineering in dna expression vectors. In: CSB 2003: Proceedings of the IEEE Computer Society Conference on Bioinformatics, pp. 294– 305. IEEE Computer Society, Washington, DC, USA (2003) 14. Sharp, P.M., Li, W.H.: The codon adaptation index–a measure of directional synonymous codon usage bias, and its potential applications. Nucleic Acids Research 15(3), 1281–1295 (1987) 15. The ENCODE Consortium: The ENCODE (ENCyclopedia of DNA elements) project. Science 306(5696), 636–640 (2004) 16. Varenne, S., Lazdunski, C.: Eﬀect of distribution of unfavourable codons on the maximum rate of gene expression by an heterologous organism. Journal of Theoretical Biology 120(1), 99–110 (1986) 17. Villalobos, A., Ness, J.E., Gustafsson, C., Minshull, J., Govindarajan, S.: Gene Designer: a synthetic biology tool for constructing artiﬁcial DNA segments. BMC Bioinformatics 7, 285 (2006) 18. Wu, G., Bashir-Bello, N., Freeland, S.J.: The synthetic gene designer: a ﬂexible web platform to explore sequence manipulation for heterologous expression. Protein Expression and Puriﬁcation 47(2), 441–445 (2006)

An Algorithm for Road Coloring A.N. Trahtman Bar-Ilan University, Dep. of Math., 52900, Ramat Gan, Israel trakht@macs.biu.ac.il

Abstract. A coloring of edges of a ﬁnite directed graph turns the graph into a ﬁnite-state automaton. The synchronizing word of a deterministic automaton is a word in the alphabet of colors (considered as letters) of its edges that maps the automaton to a single state. A coloring of edges of a directed graph of uniform outdegree (constant outdegree of any vertex) is synchronizing if the coloring turns the graph into a deterministic ﬁnite automaton possessing a synchronizing word. The road coloring problem is the problem of synchronizing coloring of a directed ﬁnite strongly connected graph of uniform outdegree if the greatest common divisor of the lengths of all its cycles is one. The problem posed in 1970 has evoked noticeable interest among the specialists in the theory of graphs, automata, codes, symbolic dynamics as well as among the wide mathematical community. A polynomial time algorithm of O(n3 ) complexity in the worst case and quadratic in the majority of studied cases for the road coloring of the considered graph is presented below. The work is based on the recent positive solution of the road coloring problem. The algorithm was implemented in the freeware package TESTAS. Keywords: algorithm, road coloring, graph, deterministic ﬁnite automaton, synchronization.

Introduction The road coloring problem was stated almost 40 years ago [2], [1] for a strongly connected directed ﬁnite deterministic graph of uniform outdegree where the greatest common divisor (gcd) of the lengths of all its cycles is one. The edges of the graph being unlabelled, the task is to ﬁnd a labelling of the edges that turns the graph into a deterministic ﬁnite automaton possessing a synchronizing word. The outdegree of the vertex can be considered also as the size of an alphabet where the letters denote colors. The condition on gcd is necessary [1], [9]. It can be replaced by the equivalent property that there does not exist a partition of the set of vertices on subsets V1 , V2 , ..., Vk = V1 (k > 2) such that every edge which begins in Vi has its end in Vi+1 [9], [16]. ˇ Together with the Cerny conjecture [7], [8], [15], [20] the road coloring problem used to belong to the most fascinating problems in the theory of ﬁnite automata. C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 349–360, 2011. c Springer-Verlag Berlin Heidelberg 2011

350

A.N. Trahtman

The popular Internet Encyclopedia ”Wikipedia” mentioned it many years on the list of the most interesting unsolved problems in mathematics. For some results in this area, see [5], [6], [10], [11], [12], [13], [14], [16], [17], [19]. A detailed history of investigations can be found in [6]. The ﬁnal positive solution of the problem is stated in [24]. An algorithm for road coloring oriented on DNA computing [13] is based on the massive parallel computing of sequences of length O(n3 ). The implementation of the algorithm as well as the implementation of eﬀective DNA computing is still an open problem. Another new algorithm for road coloring (ArXiv [4]) as well as our algorithm below is based on the proof of [24]. This proof is constructive and leads to an algorithm that ﬁnds a synchronized labelling with cubic worst-case time complexity. Both of the above mentioned algorithms use concepts and ideas of the considered proof together with the concepts from [9], [14], but use diﬀerent methods to reduce the time complexity. A skillful study of the graph was added in [4]. The presented algorithm for the road coloring (see also ArXiv [22]) reduces the time complexity with the help of the study of two cycles with common vertex (Lemma 10). It gives us the possibility to reduce quite often the time complexity. The theorems and lemmas from [24] and [23] are presented below without proof. The proofs are given only for new (or modiﬁed) results. The time complexity of the algorithm for a graph with n vertices and d outgoing edges of any vertex is O(n3 d) in the worst case and quadratic in the majority of the studied cases. The space complexity is quadratic. This is the ﬁrst embedded algorithm for road coloring. The description of the algorithm is presented below together with some pseudo codes of the implemented subroutines. The algorithm is implemented in the freeware package TESTAS (http://www.cs.biu.ac.il/∼trakht/syn.html) [25]. The easy access to the package ensures the possibility to everybody to verify the considered algorithm. The role of the road coloring is substantial also in education. ”The Road Coloring Conjecture makes a nice supplement to any discrete mathematics course” [18]. The realization of the algorithm is demonstrated on the basis of a linear visualization program [25] and can analyze any kind of input graph.

Preliminaries As usual, we regard a directed graph with letters assigned to its edges as a ﬁnite automaton, whose input alphabet Σ consists of these letters. The graph is called a transition graph of the automaton. The letters from Σ can be considered as colors and the assigning of colors to edges will be called coloring. A ﬁnite directed strongly connected graph with constant outdegree of all its vertices where the gcd of lengths of all its cycles is one will be called an AGW graph (as introduced by Adler, Goodwyn and Weiss). We denote by |P | the size of the subset P of states of an automaton (of vertices of a graph).

An Algorithm for Road Coloring

351

If there exists a path in an automaton from the state p to the state q and the edges of the path are consecutively labelled by σ1 , ..., σk , then for s = σ1 ...σk ∈ Σ + we shall write q = ps. Let P s be the set of states ps for p ∈ P , s ∈ Σ + . For the transition graph Γ of an automaton, let Γ s denote the map of the set of states of the automaton. A word s ∈ Σ + is called a synchronizing word of the automaton with transition graph Γ if |Γ s| = 1. A coloring of a directed ﬁnite graph is synchronizing if the coloring turns the graph into a deterministic ﬁnite automaton possessing a synchronizing word. Bold letters will denote the vertices of a graph and the states of an automaton. A pair of distinct states p, q of an automaton (of vertices of the transition graph) will be called synchronizing if ps = qs for some s ∈ Σ + . In the opposite case, if ps = qs for any s, we call the pair a deadlock. A synchronizing pair of states p, q of an automaton is called stable if for any word u the pair pu, qu is also synchronizing [9], [14]. We call the set of all outgoing edges of a vertex a bunch if all these edges are incoming edges of only one vertex. The subset of states (of vertices of the transition graph Γ ) of maximal size such that every pair of states from the set is a deadlock will be called an F -clique.

1

Some Properties of F -Cliques and Stable Pairs

The road coloring problem was formulated for AGW graphs [1] and only such graphs are considered in Sections 1 and 2. Let us recall that a binary relation ρ on the set of the states of an automaton is called congruence if ρ is equivalence and for any word u from p ρ q follows pu ρ qu. Let us formulate an important result from [9], [14] in the following form: Theorem 1. [14] Let us consider a coloring of an AGW graph Γ . Let ρ be the transitive and reflexive closure of the stability relation on the obtained automaton. Then ρ is a congruence relation, Γ/ρ is also an AGW graph and a synchronizing coloring of Γ/ρ implies a synchronizing recoloring of Γ . Lemma 1. [24], [9] Let F be an F -clique of some coloring of an AGW graph Γ . For any word s the set F s is also an F -clique and any state p belongs to some F -clique. Lemma 2. Let A and B (with |A| > 1) be distinct F -cliques of some coloring of an AGW graph Γ such that |A| − |A ∩ B| = 1. Then for all p ∈ A \ A ∩ B and q ∈ B \ A ∩ B, the pair (p, q) is stable. Proof. By the deﬁnition of an F -clique, |A| = |B| and |B| − |A ∩ B| = 1, too. If the pair of states p ∈ A \ B and q ∈ B \ A is not stable, then for some word s the pair (ps, qs) is a deadlock. Any pair of states from the F -clique A and from the F -clique B, as well as from the F -cliques As and Bs, is a deadlock. So any pair of states from the set (A ∪ B)s is a deadlock. One has |(A ∪ B)s| = |As| + 1 = |A| + 1 > |A|. So the size of the set (A ∪ B)s of deadlocks is greater than the maximal size of F -clique. Contradiction.

352

A.N. Trahtman

Lemma 3. If some vertex of an AGW graph Γ has two incoming bunches, then the origins of the bunches form a stable pair by any coloring. Proof. If a vertex p has two incoming bunches from q and r, then the couple q, r is stable for any coloring because qσ = rσ = p for any σ ∈ Σ.

2

The Spanning Subgraph of an AGW Graph

Definition 4. Let us call a subgraph S of an AGW graph Γ , a spanning subgraph of Γ , if S contains all vertices of Γ and if each vertex has exactly one outgoing edge. (In usual graph-theoretic terms it is a 1-outregular spanning subgraph). A maximal subtree of a spanning subgraph S with its root on a cycle from S and having no common edges with the cycles of S is called a tree of S. The length of a path from a vertex p through the edges of the tree of the spanning set S to the root of the tree is called a level of p in S. A tree with a vertex of maximal level is called a maximal tree. Remark 5. Any spanning subgraph S consists of disjoint cycles and trees with roots on the cycles. Any tree and cycle of S is defined identically. The level of the vertices belonging to some cycle is zero. The vertices of the trees except the roots have positive level. The vertices of maximal positive level have no incoming edge in S. The edges labelled by a given color defined by any coloring form a spanning subgraph. Conversely, for each spanning subgraph, there exists a coloring and a color such that the set of edges labelled with this color corresponds to this spanning subgraph. max level 3 level c c 2 @ Rc -c level 1 @ Tree c ? P q c level 0 P @ c Rc @ level 0 I @ @c Cycle Lemma 6. [24] Let N be a set of vertices of maximal level in some tree of the spanning subgraph S of an AGW graph Γ . Then, via a coloring of Γ such that all edges of S have the same color α, for any F -clique F holds |F ∩ N | ≤ 1. Lemma 7. [24] Let Γ be an AGW graph with a spanning subgraph R which is a union of cycles (without trees). Then the non-trivial graph Γ has another spanning subgraph with exactly one maximal tree. Lemma 8. Let R be a spanning subgraph of an AGW graph Γ . Let T be a maximal tree of R with a vertex p of maximal positive level L and with a root r on a cycle H of R. Let us change the spanning subgraph by means of the following flips:

An Algorithm for Road Coloring

353

1)an edge a ¯ = a → p replaces the edge d¯ = a → d of R for appropriate vertices a and d = p, 2) replacing edge ¯b = b → r of T by an edge b → x for appropriate vertices b and x = r, 3) replacing edge c¯ = c → r of H by an edge c → x for appropriate vertices c and x = r. Suppose that one or two consecutive flips do not increase the number of edges in cycles (Condition∗ ) and no vertex of Γ has two incoming bunches (Condition∗∗ ). Then there exists a spanning subgraph with a single maximal nontrivial tree. Proof. In view of Lemma 7, suppose that R has non-trivial trees. Further consideration is necessary only if the maximal tree T is not single. p c - · · · T- cb ¯b a ¯ ? a c · · · c cc¯ c c r w AK ¯ A c H d ··· ··· ··· ··· Our aim is to increase the maximal level L using the three aforesaid ﬂips. If one of the ﬂips does not succeed, let us go to the next, assuming the situation in which the previous fails, and excluding the successfully studied cases. We check at most two ﬂips together. Let us begin from the edge a ¯) Suppose ﬁrst a ∈ H. If a belongs to the path in T from p to r then a new cycle with part of the path and the edge a → p is added to R extending the number of vertices in its cycles in spite of Condition∗ of lemma. In the opposite case the level of a is L + 1 in a single maximal tree. So let us assume a ∈ H. In this case the vertices p, r and a belong to a cycle H1 of a new spanning subgraph R1 obtained by removing d¯ and adding a¯. So we have the cycle H1 ∈ R1 instead of H ∈ R. If the length of the path from r to a in H is r1 , then H1 has length L + r1 + 1. A path from r to d of the cycle H remains in R1 . Suppose that its length is r2 . So the length of the cycle H is r1 + r2 + 1. The length of the cycle H1 is not greater than the length of H in view of Condition∗ . So r1 + r2 + 1 ≥ L + r1 + 1, whence r2 ≥ L. If r2 > L, then the length r2 of the path from d to r in a tree of R1 (as well as the level of d) is greater than L. The tree containing d is the desired single maximal tree. So we can assume for further consideration that L = r2 and a ∈ H. An analogous statement can be stated for any maximal tree. The edge ¯b) Suppose that the set of outgoing edges of the vertex b is not a bunch. So one can replace in R the edge ¯b by an edge v¯ = b → v (v = r). The vertex v could not belong to T because in this case a new cycle is added to R in spite of Condition∗ .

354

A.N. Trahtman

If the vertex v belongs to another tree of R but not to the cycle H, then T is a part of a new tree T1 with a new root of a new spanning subgraph R1 and the path from p to the new root has a length greater than L. Therefore the tree T1 is the unique maximal tree in R1 . If v belongs to some cycle H2 = H in R, then together with replacing ¯b by v¯, we also replace the edge d¯ by a ¯. So we extend the path from p to the new root v of H2 at least by the edge a ¯ = a → p and there is a unique maximal tree of level L1 > L which contains the vertex d. Now it remains only the case when v belongs to the cycle H. The vertex p also has level L in a new tree T1 with root v. The only diﬀerence between T and T1 (just as between R and R1 ) is the root and the incoming edge of this root. The new spanning subgraph R1 has the same number of vertices in their cycles just as does R. Let r2 be the length of the path from d to v ∈ H. For the spanning subgraph R1 , one can obtain L = r2 just as it was done earlier in the case of the edge a ¯) for R. From v = r follows r2 = r2 , though L = r2 and L = r2 . So for further consideration suppose that the set of outgoing edges of the vertex b is a bunch to r. The edge c¯) The set of outgoing edges of the vertex c is not a bunch in virtue of Condition∗∗ (r has another bunch from b.) Let us replace in R the edge c¯ by an edge u ¯ = c → u such that u = r. The vertex u could not belong to the tree T because one has in this case a cycle with all vertices from H and some vertices of T whence its length is greater than |H| and so the number of vertices in the cycles of a new spanning subgraph grows in spite of Condition∗ . If the vertex u does not belong to T , then the tree T is a part of a new tree with a new root. The path from p to the new root is extended at least by a part of H starting at the former root r. The new level of p therefore is maximal and greater than the level of any vertex in another tree. Thus in any case we obtain a spanning subgraph with a single non-trivial maximal tree. Lemma 9. For some coloring of any AGW graph Γ , there exists a stable pair of states. Proof. We exclude the case of two incoming bunches of a vertex in virtue of Lemma 3. There exists a coloring such that for some color α, the corresponding spanning subgraph R has maximum edges in cycles. By Lemma 8, we must consider now a spanning subgraph R with a single maximal tree T . Let the root r of T belong to the cycle C. By Lemma 1, in a strongly connected transition graph for every word s and F -clique F of size |F | > 1, the set F s also is an F -clique of the same size and for any state p there exists an F -clique F such that p ∈ F . In particular, some F -clique F has a non-empty intersection with the set N of vertices of maximal level L. The set N belongs to one tree, whence by Lemma 6 |N ∩ F | = 1. Let p ∈ N ∩ F .

An Algorithm for Road Coloring

355

The word αL−1 maps F on an F -clique F1 of size |F |. One has |F1 \ C| = 1 because any sequence of length L − 1 of edges of color α in any tree of R leads to a cycle. For the set N of vertices of maximal level, N αL−1 ⊆ C holds. So |N αL−1 ∩ F1 | = |F1 \ C| = 1, pαL−1 ∈ F1 \ C and |C ∩ F1 | = |F1 | − 1. Let the integer m be a common multiple of the lengths of all considered cycles colored by α. So for any r in C as well as in F1 ∩ C holds rαm = r. Let F2 be F1 αm . We have F2 ⊆ C and C ∩ F1 = F1 ∩ F2 . Thus the two F -cliques F1 and F2 of size |F1 | > 1 have |F1 | − 1 common vertices. So |F1 \ (F1 ∩ F2 )| = 1, whence by Lemma 2, the pair of states pαL−1 from F1 \ (F1 ∩ F2 ) and q from F2 \ (F1 ∩ F2 ) is stable. It is obvious that q = pαL+m−1 . Theorem 2. [24] Every AGW graph has a synchronizing coloring. Theorem 3. [23] Let every vertex of a strongly connected directed graph Γ have the same number of outgoing edges. Then Γ has synchronizing coloring if and only if the greatest common divisor of lengths of all its cycles is one. The goal of the following lemma is to reduce the complexity of the algorithm. Lemma 10. Let Γ be an AGW graph having two cycles Cu and Cv . Suppose that either Cu ∩ Cv = {p1 } or Cu ∩ Cv = {pk ,..., p1 }, where all incoming edges of pi develop a bunch from pi+1 (i < k). Let u ∈ Cu and v ∈ Cv be the distinct edges of the cycles Cu and Cv leaving p1 . Let Ru be a spanning subgraph with all edges from Cu and Cv except u. The spanning subgraph Rv is obtained from Ru by removing v and adding u. Then at least one of two spanning subgraphs Ru , Rv has a unique maximal tree whose root is p1 . Proof. Let us add to Ru the edge u and consider a set of trees with roots on the cycles Cu and Cv . The trees have no common vertices and have no vertices except a root on the cycles Cu and Cv . The same set of trees can be obtained by adding the edge v to Rv . Let us deﬁne the levels of vertices of a tree as in the case of a spanning subgraph and consider the set of maximal trees (the trees with a maximal vertex level). If all maximal trees have a common root, then Ru (and also Rv ) is a spanning subgraph with a unique maximal tree. If maximal trees have diﬀerent roots, then let as take a maximal tree T with root r such that the length of the path P from r to p1 on the cycle Cu (or Cv ) is maximal. If P belongs to Cu , then the tree T is extended by the path P , whence Ru has a unique maximal tree. In the opposite case, Rv has a unique maximal tree.

3

The Algorithm for Synchronizing Coloring

Let us start with transition graph of an arbitrary deterministic complete ﬁnite automaton.

356

3.1

A.N. Trahtman

Preliminary Steps

The study is based on Theorem 3. A synchronizing graph has a sink strongly connected component (SCC). Our aim is to reduce the study to sink SCC (if it exists) in order to remove non-synchronizing graphs without sink SCC and then check the condition on gcd. The function CheckSinkSCC veriﬁes the existence of sink SCC. We use the linear algorithm for ﬁnding strongly connected components SCC [3], [21]. Then we remove all SCC as having outgoing edges to other SCC. If only one SCC remains then let us continue. In the opposite case a synchronizing coloring does not exist. We study a strongly connected graph (with one SCC). The function FindGCDofCycles ﬁnds the great common divisor (gcd) of lengths of cycles of the automaton and veriﬁes the necessary conditions of synchronizability (gcd = 1). Let p be an arbitrary ﬁxed vertex. Suppose d(p) = 1. Then we use a depthﬁrst search from p. For an edge r → q where d(r) is already deﬁned and d(q) is not, suppose d(q) = d(r)+ 1. If d(q) is deﬁned, let us add the non-zero diﬀerence abs(d(q) − 1 − d(r)) to the set D. The integer from D is a diﬀerence of lengths of two paths from p to q. In a strongly connected graph, the gcd of all elements of D is also a gcd of lengths of all cycles [2], [23]. If gcd = 1 for all integers from D, then the graph has synchronizing coloring. In opposite case the answer is negative. So we reduce the investigation to an AGW graph. Let us proceed with an arbitrary coloring of such a graph Γ with n vertices and constant outdegree d. The considered d colors deﬁne d spanning subgraphs of the graph. We keep the preimages of vertices and colored edges by any transformation and homomorphism. If there exists a loop in Γ around a state r, then let us color the edges of a tree whose root is r with the same color as the color of the loop. The other edges may be colored arbitrarily. The coloring is synchronizing [1]. The function FindLoopColoring ﬁnds the coloring. 3.2

Help Subroutines

In the case of two incoming bunches of some vertex, the origins of these bunches develop a stable pair by any coloring (Lemma 3). We merge both vertices in the homomorphic image of the graph (Theorem 1) and obtain according to the theorem a new AGW graph of a smaller size. The pseudo code of corresponding procedure returns two such origins of bunches (a stable pair). The linear search of two incoming bunches and of the loop can be made at any stage of the algorithm. The function HomonorphicImage of linear complexity reduces the size of the considered automaton and its transition graph. The congruence classes of the homomorphism are deﬁned by a stable pair (Theorem 1). A new AGW graph of a smaller size will be the output.

An Algorithm for Road Coloring

357

The main part of the algorithm needs the parameters of the spanning subgraph: levels of all vertices, the number of vertices (edges) in cycles, trees, next and former vertices. We keep the tree and the cycle of any vertex, the root of the tree. We form the set of vertices of maximal level and the set of maximal trees. The function FindParameters (spanning subgraph S, parameters) is linear and used by any recoloring step. The subroutine MaximalTreeToStablePair of linear complexity ﬁnds a stable pair in a given spanning subgraph with unique maximal tree. The stable pair consists of two beginnings of incoming edges of the root of the unique maximal tree (Lemma 9). 3.3

A Possibility to Reduce the Complexity

Our algorithm as well as the algorithm of [4] is based on [24]. Only this section essentially diﬀers in both these papers. If there are two cycles with one common vertex (path) then we use Lemma 10 and ﬁnd a spanning subgraph with single maximal tree. Then after coloring edges of spanning subgraph by a color α, we ﬁnd a stable pair (beginnings of two incoming edges to the root of the tree). The function TwoCyclesWithIntersection as a rule returns a pair of cycles with common vertex (path). The vast majority of digraphs contains such a pair of cycles. The goal of the subroutine is to omit the cubic complexity of the algorithm. The search of a stable pair is linear in this case and thus the whole algorithm is quadratic.

TwoCyclesWithIntersection (graph G) 1 levels of all vertices ﬁrst are negative 2 level(r) = 1 and add r to stack 3 for every vertex q from stack 4 do 5 for every letter β 6 do 7 add qβ to stack 8 if level(qβ) ≥ 0 9 level(qβ) =level(q) + 1 10 keep the cycle C of vertices qβ, q and break from both cycles 11 remove q from stack 12 for every vertex r 13 do 14 if r ∈ C level((r) = −1 (for a search of second cycle) 15 for every vertex q from cycle C 16 do 17 r = qα 18 for every letter β 19 do 20 if r = qβ break

358

A.N. Trahtman

21 if r = qβ break 22 add q to stack 1 (possible intersection of two cycles) 23 for every vertex r from stack 1 24 do 25 for every letter β 26 do 27 if level(rβ) < 0 28 level(rβ) =level(r) + 1 29 add rβ to stack 1 30 if rβ = q (found second cycle) 31 develop trees with roots on both cycles, ﬁnd maximal trees 32 color the edge v from q on cycle of maximal tree by color 2 33 color the edges of trees and both cycles except v by color 1 34 FindParameters (spanning subgraph of color 1) 35 MaximalTreeToStablePair (subgraph, p, s) 36 return p, s (stable pair) 37 remove r from stack 1 38 return False 3.4

The Recoloring of the Edges

A repainting of the edges of the transition graph for to obtain a spanning subgraph with single maximal tree is a most complicated part of the algorithm. Let us ﬁx the spanning subgraph R of edges of a given color α. We consider the ﬂips from Lemmas 7 and 8. The ﬂips change R. According to the Lemmas, after at most 3d steps either the number of edges in the cycles is growing or there exists a single maximal tree. The subroutine of pseudo code Flips (spanning subgraph F ) returns either a stable pair or enlarges the number of edges in cycles of the spanning subgraph. The subroutine uses linear subroutines FindParameters, MaximalTreeToStablePair and also has linear time complexity O(nd). We repeat the procedure with pseudo code Flips for a new graph if the number of edges in cycles after the ﬂips grows. In the opposite case, we ﬁnd a stable pair and then a homomorphic image of a smaller size. For a graph of given size, the complexity of this step is quadratic. 3.5

Main Procedure and Complexity

The Procedure Main uses all above-mentioned linear procedures and returns a synchronizing coloring (if exists) of the graph.

Main() 1 arbitrary coloring of G 2 if False(CheckSinkSCC(graph G)) 3 return False 4 if FindLoopColoring(F=SCC of G)

An Algorithm for Road Coloring

359

5 return 6 if False(FindGCDofCycles(SCCF )) 7 return False 8 while |G| > 1 9 ifFindLoopColoring(F) 10 change the coloring of generic graph G 11 return 12 for every letter β 13 do 14 if FindTwoIncomingBunches(spanning subgraph,stable pair) 15 HomonorphicImage(automaton A,stable pair,new A) 16 FindParameters (A = new A) 17 break 18 while Flips(spanning subgraph F of color β) = GROWS 19 F = new F 20 if FindTwoIncomingBunches( F ,stable pair) 21 HomonorphicImage(automaton A,stable pair,new A) 22 FindParameters (A = new A) 23 break 24 MaximalTreeToStablePair (subgraph, stable pair) 25 HomonorphicImage(automaton A,stable pair,new A) 26 FindParameters (A = new A) 27 change the coloring of G on the base of the last homomorphic image Some of above-mentioned linear subroutines are included in cycles on n and d, sometimes twice on n. So the upper bound of the time complexity is O(n3 d). Nevertheless, the overall complexity of the algorithm in a majority of cases is O(n2 d). The upper bound O(n3 d) of the time complexity is reached only if the number of edges in the cycles grows slowly, the size of the automaton decreases also slowly, loops do not appear and the case of two ingoing bunches emerges rarely (the worst case). The space complexity is quadratic.

References 1. Adler, R.L., Goodwyn, L.W., Weiss, B.: Equivalence of topological Markov shifts. Israel J. of Math. 27, 49–63 (1977) 2. Adler, R.L., Weiss, B.: Similarity of automorphisms of the torus. Memoirs of the Amer. Math. Soc. 98 (1970) 3. Aho, A., Hopcroft, J., Ulman, J.: The Design and Analisys of Computer Algorithms. Addison-Wesley (1974) 4. B´eal, M.P., Perrin, D.: A quadratic algorithm for road coloring. arXiv:0803.0726v2 [cs.DM] (2008) 5. Budzban, G., Mukherjea, A.: A semigroup approach to the Road Coloring Problem. Probability on Alg. Structures. Contemporary Mathematics 261, 195–207 (2000) 6. Carbone, A.: Cycles of relatively prime length and the road coloring problem. Israel J. of Math. 123, 303–316 (2001)

360

A.N. Trahtman

ˇ 7. Cerny, J.: Poznamka k homogenym eksperimentom s konechnymi automatami. ˇ Math.-Fyz. Cas. 14, 208–215 (1964) ˇ 8. Cerny, J., Piricka, A., Rosenauerova, B.: On directable automata. Kybernetika 7, 289–298 (1971) 9. Culik, K., Karhumaki, J., Kari, J.: A note on synchronized automata and Road Coloring Problem. In: 5th Int. Conf. on Developments in Language Theory, Vienna, pp. 459–471 (2001); J. of Found. Comput. Sci.13, 459–471 (2002) 10. Friedman, J.: On the road coloring problem. Proc. of the Amer. Math. Soc. 110, 1133–1135 (1990) 11. Gocka, E., Kirchherr, W., Schmeichel, E.: A note on the road-coloring conjecture. Ars Combin. 49, 265–270 (1998) 12. Hegde, R., Jain, K.: Min-Max theorem about the Road Coloring Conjecture. In: EuroComb 2005, DMTCS Proc., AE, pp. 279–284 (2005) 13. Jonoska, N., Karl, S.A.: A molecular computation of the road coloring problem. DNA Based Computers II, DIMACS Series in DMTCS 44, 87–96 (1998) 14. Kari, J.: Synchronizing Finite Automata on Eulerian Digraphs. In: Sgall, J., Pultr, A., Kolman, P. (eds.) MFCS 2001. LNCS, vol. 2136, p. 432. Springer, Heidelberg (2001) ˇ 15. Mateescu, A., Salomaa, A.: Many-Valued Truth Functions, Cerny’s Conjecture and Road Coloring. Bull. of European Ass. for TCS 68, 134–148 (1999) 16. O’Brien, G.L.: The road coloring problem. Israel J. of Math. 39, 145–154 (1981) 17. Perrin, D., Schˇ utzenberger, M.P.: Synchronizing preﬁx codes and automata, and the road coloring problem. Symbolic Dynamics and Appl. Contemp. Math. 135, 295–318 (1992) 18. Rauﬀ, J.V.: Way back from anywhere: exploring the road coloring conjecture. Math. and Comput. Education 01 (2009) 19. Roman, A.: Decision Version of the Road Coloring Problem Is NP-Complete. In: M. (eds.) FCT 2009. LNCS, vol. 5699, Kutylowski, M., Charatonik, W., Gebala, pp. 287–297. Springer, Heidelberg (2009) 20. Rystsov, I.C.: Quasioptimal bound for the length of reset words for regular automata. Acta Cybernetica 12, 145–152 (1995) 21. Tarjan, R.E.: Depth ﬁrst search and linear graph algorithms. SIAM J. Comput. 1, 146–160 (1972) 22. Trahtman, A.N.: A subquadratic algorithm for road coloring. arXiv:0801.2838 v1 [cs.DM] (2008) 23. Trahtman, A.N.: Synchronizing Road Coloring. In: 5-th IFIP WCC-TCS, vol. 273, pp. 43–53. Springer, Heidelberg (2008) 24. Trahtman, A.N.: The road coloring problem. Israel Journal of Math. 172(1), 51–60 (2009) 25. Trahtman, A.N., Bauer, T., Cohen, N.: Linear visualization of a Road Coloring. In: 9th Twente Workshop on Graphs and Comb. Optim. Cologne, pp. 13–16 (2010)

Complexity of the Cop and Robber Guarding Game ˇ amal , Rudolf Stolaˇr, and Tomas Valla Robert S´ Charles University, Faculty of Mathematics and Physics, Institute for Theoretical Computer Science (ITI) Malostransk´e n´ am, 2/25, 118 00, Prague, Czech Republic {samal,ruda,valla}@kam.mff.cuni.cz

Abstract. The guarding game is a game in which several cops has to guard a region in a (directed or undirected) graph against a robber. The robber and the cops are placed on vertices of the graph; they take turns in moving to adjacent vertices (or staying), cops inside the guarded region, the robber on the remaining vertices (the robber-region). The goal of the robber is to enter the guarded region at a vertex with no cop on it. The problem is to determine whether for a given graph and given number of cops the cops are able to prevent the robber from entering the guarded region. The problem is highly nontrivial even for very simple graphs. It is known that when the robber-region is a tree, the problem is NP-complete, and if the robber-region is a directed acyclic graph, the problem becomes PSPACE-complete [Fomin, Golovach, Hall, Mihal´ ak, Vicari, Widmayer: How to Guard a Graph? Algorithmica, DOI: 10.1007/s00453-009-9382-4]. We solve the question asked by Fomin et al. in the previously mentioned paper and we show that if the graph is arbitrary (directed or undirected), the problem becomes E-complete. Keywords: pursuit game, cops and robber game, graph guarding game, computational complexity, E-completeness.

1

Introduction and Motivation

The guarding game (G, VC , c), introduced by Fomin et al. [1], is played on a graph → − G = (V, E) (or directed graph G = (V, E)) by two players, the cop-player and the robber-player, each having his pawns (c cops and one robber, respectively) on V . There is a protected region (also called cop-region) VC ⊂ V . The remaining region V \ VC is called robber-region and denoted VR . The robber aims to enter VC by a move to vertex of VC with no cop on it. The cops try to prevent the robber from entering a vertex of VC with no cop on it. The game is played in alternating turns. In the ﬁrst turn the robber-player places the robber on some vertex of VR . In the second turn the cop-player places his c cops on vertices of VC

ˇ P201/10/P337. Partially supported by grant GA CR Supported by the GAUK Project 66010 of Charles University Prague. Supported by ITI, Charles University Prague, under grant 1M0021620808.

C.S. Iliopoulos and W.F. Smyth (Eds.): IWOCA 2011, LNCS 7056, pp. 361–373, 2011. c Springer-Verlag Berlin Heidelberg 2011

362

ˇ amal, R. Stolaˇr, and T. Valla R. S´

(more cops can share one vertex). In each subsequent turn the respective player can move each of his pawns to a neighbouring vertex of the pawn’s position (or leave it where it is). However, the cops can move only inside VC and the robber can move only on vertices with no cops. At any time of the game both players know the positions of all pawns. The robber-player wins if he is able to move the robber to some vertex of VC in a ﬁnite number of steps. The cop-player wins if the cop-player can prevent the robber-player from placing the robber on a vertex in VC indeﬁnitely. Note that after exponentially many (in the size of the graph G) turns the positions has to repeat and obviously if the robber can win, he can win in less than 2|V |(c+1) turns, as 2|V |(c+1) is the upper bound on the number of all possible positions of the robber and all cops, together with the information who is on move. For a given graph G and guarded region VC , the task is to ﬁnd the minimum number c such that cop-player wins. The guarding game is a member of a big class called the pursuit-evasion games, see, e.g., Alspach [4] for introduction and survey. The discrete version of pursuit-evasion games on graphs is called the Cops-and-Robber game. This game was ﬁrst deﬁned for one cop by Winkler and Nowakowski [5] and Quilliot [6]. Aigner and Fromme [7] initiated the study of the problem with several cops. The minimum number of cops required to capture the robber is called the cop number of the graph. In this setting, the Cops-and-Robber game can be viewed as a special case of search games played on graphs. Therefore, the guarding game is a natural variant of the original Cops-and-Robber game. The complexity of the decision problem related to the Cops-and-Robbers game was studied by Goldstein and Reingold [11]. They have shown that if the number of cops is not ﬁxed and if either the graph is directed or initial positions are given, then the problem is E-complete. Another interesting variant is the “fast robber” game, which is studied in Fomin et al. [12]. See the annotated bibliography [10] for reference on further topics. A diﬀerent well-studied problem, the Eternal Domination problem (also known as Eternal Security) is strongly related to the guarding game. The objective in the Eternal Domination is to place the minimum number of guards on the vertices of a graph G such that the guards can protect the vertices of G from an inﬁnite sequence of attacks. In response to an attack of an unguarded vertex v, at least one guard must move to v and the other guards can either stay put, or move to adjacent vertices. The Eternal Domination problem is a special case of the guarding game. This can be seen as follows. Let G be a graph on n vertices and we construct a graph H from G by adding a clique Kn on n vertices and connecting the clique and G by n edges which form a perfect matching. The cop-region is V (G) and the robber-region is V (Kn ). Now G has an eternal dominating set of size k if and only if k cops can guard V (G). Eternal Domination and its variant have been considered for example in [15,16,17,18,19,20,21,22]. In our paper we focus on the complexity issues of the decision problem related to the guarding game: Given the guarding game G = (G, VC , c), who has the

Complexity of the Cop and Robber Guarding Game

363

winning strategy? Observe that the task of ﬁnding the minimum c such that G is cop-win is at least as hard as the decision version of the problem. Let us deﬁne the computational problem precisely. The directed guarding de→ − → − cision problem is, given a guarding game ( G , VC , c) where G is a directed graph, to decide whether it is a cop-win game or a robber-win game. Analogously, we deﬁne the undirected guarding decision problem with the diﬀerence that the underlying graph G is undirected. The guarding problem is, given a a directed or undirected graph G and a cop-region VC ⊆ V (G), to compute the minimum number c such that the (G, VC , c) is a cop-win. The directed guarding decision problem was introduced and studied by Fomin et al. [1]. The computational complexity of the problem depends heavily on the chosen restrictions on the graph G. In particular, in [1] the authors show that if the robber’s region is only a path, then the problem can be solved in polynomial time, and when the robber moves in a tree (or even in a star), then the problem is NP-complete. Furthermore, if the robber is moving in a directed acyclic graph, the problem becomes PSPACE-complete. Later Fomin, Golovach and Lokshtanov [13] studied the reverse guarding game which rules are the same as in the guarding game, except that the cop-player plays ﬁrst. They proved in [13] that the related decision problem is PSPACE-hard on undirected graphs. Nagamochi [8] has also shown that that the problem is NP-complete even if VR induces a 3-star and that the problem is polynomially solvable if VR induces a cycle. Also, Thirumala Reddy, Sai Krishna and Pandu Rangan have proved [9] that if the robber-region is an arbitrary undirected graph, then the decision problem is PSPACE-hard. Let us consider the class E = DTIME(2O(n) ) of languages recognisable by a deterministic Turing machine in time 2O(n) . We consider log-space reductions, this means that the reducing Turing machine is log-space bounded. Very little is known how the class E is related to PSPACE. However, it is known [3] that E = PSPACE. Fomin et al. [1] asked, whether the guarding decision problem for general graphs is PSPACE-complete too. We disprove this conjecture in the following theorem. Theorem 1. The directed guarding decision problem is E-complete under logspace reductions. Immediately, we get the following corollary. Corollary 1. The guarding problem is E-complete under log-space reductions. We would like to point out the fact that we can prove Theorem 1 without prescribing the starting positions of players. We also state Theorem 2, a theorem similar to Theorem 1 for general undirected graphs. Unfortunately, we omit the proof of Theorem 2 due to the page limit imposed on the paper. We deﬁne the guarding game with prescribed starting positions G = (G, VC , c, S, r), where S : {1, . . . , c} → VC is the initial placement of cops and r ∈ VR is the initial placement of robber. The undirected guarding decision problem with prescribed starting positions is, given a guarding game with

364

ˇ amal, R. Stolaˇr, and T. Valla R. S´

prescribed starting positions (G, VC , c, S, r) where G is an undirected graph, to decide whether it is a cop-win game or a robber-win game. The directed guarding decision problem with prescribed starting positions is deﬁned analogously. Theorem 2. The undirected guarding decision problem with prescribed starting positions is E-complete under log-space reductions. Here, we would like to point out the fact that with the exception of the result in [13], all known hardness results for cops and robbers, or pursuit evasion games are for the directed graph variants of the games [1,11]. For example, the classical Cop and Robbers game was shown to be PSPACE-hard on directed graphs by Goldstein and Reingold in 1995 [11] while for undirected graphs, even an NP-hardness result was not known until recently by Fomin, Golovach and Kratochv´ıl [14]. For the original Cops-and-Robber game, Goldstein and Reingold [11] have proved that if the number c of cops is not ﬁxed and if either the graph is directed or initial positions are given, then the related decision problem is E-complete. In a sense, we show analogous result for the guarding game as Goldstein and Reingold [11] have shown for the original Cops-and-Robber game. Similarly to Goldstein and Reingold, we can prove the complexity of the undirected guarding decision problem only when having prescribed the initial positions of players. Dealing with this issue now seems to be the main task in this family of games.

2

The Directed Case

In order to prove E-completeness of the directed guarding decision problem, we ﬁrst note that the problem is in E. Lemma 1. The guarding decision problem (directed or undirected) is in E. The proof is standard and easy (we just have to realize that the cops are mutually indistinguishable so the number of all conﬁgurations is 2O(n) ) and we omit it. Let us ﬁrst study the problem after the second move, where both players have already placed their pawns. We reduce the directed guarding decision problem with prescribed starting positions from the following formula-satisfying game F . A position in F is a 4-tuple (τ, FR (C, R), FC (C, R), α) where τ ∈ {1, 2}, FR and FC are formulas in 12-DNF both deﬁned on set of variables C ∪ R, where C and R are disjoint and α is an initial (C ∪ R)-assignment. The symbol τ serves only to diﬀerentiate the positions where the ﬁrst or the second player is on move. Player I (II) moves by changing the values assigned to at most one variable in R (C); either player may pass since changing no variable amounts to a “pass”. Player I (II) wins if the formula FR (FC ) is true after some move of player I (II). More precisely, player I can move from (1, FR , FC , α) to (2, FR , FC , α ) in one move if and only if α diﬀers from α in the assignment given to at most one variable in R and FC is false under the assignment α; the moves of player II are deﬁned symmetrically.

Complexity of the Cop and Robber Guarding Game

365

According to Stockmeyer and Chandra [2], the set of winning positions of player I in the game F is an E-complete language under log-space reduction. Let us ﬁrst informally sketch the reduction from F to G, i.e., simulating F by an equivalent guarding game G. The setting of variables is represented by positions of certain cops so that only one of these cops may move at a time (otherwise cop-player loses the game). The variables (or more precisely the corresponding cops) of C are under control of cop-player. However, in spite of being represented by cops, the variables of R are under control of the robber-player by a gadget in → − the graph G , which allows him to force any setting of cops representing R. When describing the features of various gadgets, we will often use the term normal scenario. By normal scenario S of certain gadget (or even the whole game) we mean a ﬂow of the game that imitates the formula game F . The graph G will be constructed in such a way that if the player (both cop-player and robber-player) does not exactly follow the normal scenario S, he loses the game in a few moves. There are four cyclically repeating phases of the game, determined by the current position of the robber. The normal scenario is that robber cyclically goes through the following phases marked by four special vertices and in diﬀerent phases he can enter certain gadgets. 1. “Robber Move” (RM ): In this step the robber can enter the Manipulator gadget, allowing him to force setting of at most one variable in R. 2. “Robber Test” (RT ): In this step the robber may pass through the Robber Gate into the protected region VC , provided that the formula FR is satisﬁed under the current setting of variables. 3. “Cop Move” (CM ): In this step (and only in this step) one (and at most one) variable cell Vx for x ∈ C is allowed to change its value. This is realized by a gadget called Commander. 4. “Cop Test” (CT ): In this step, if the formula FC is satisﬁed under the current setting of variables, the cops are able to block the entrance to the protected region forever (by temporarily leaving the Cop Gate gadget unguarded and sending a cop to block the entrance to VC provided by the Robber Gate gadgets). See Fig. 1 for the overview of the construction. Manipulators

Robber gates RM

RT Variables

CT Cop gates

CM Commander

Fig. 1. The sketch of the construction

366

2.1

ˇ amal, R. Stolaˇr, and T. Valla R. S´

The Variable Cells Tx T Fx

F Tx Fx

Fig. 2. Variable cell Vx

For every variable x ∈ C ∪ R we introduce a variable cell Vx , which is a directed cycle (Tx , T Fx , Fx , F Tx ) (see Fig. 2). There is one cop (variable cop) located in every Vx and the position of the cop on vertices Tx , Fx represents the boolean values true and false, respectively. The prescribed starting position of the variable cop is Tx if α(x) is true, and Fx otherwise. All the vertices of Vx belong to VC . The cells are organised into blocks C and R. The block C is under control of cop-player via the Commander gadget, the block R is represented by cops as well, however, there are the Manipulator gadgets allowing the robber-player to force any setting of variables in R, by changing at most one variable in his turn. Every variable cell Vy , y ∈ R has assigned the Manipulator gadget My . Manipulator My consists of directed paths (RM, Ty , Ty , Ty ) and (RM, Fy , Fy , Fy ) and edges (Ty , RT ) and (Fy , RT ) (see Fig. 3).

Cop region Robber region Fy

RT Fy

T Fy

Fy

F Ty

Ty

RM

Ty Ty

Fig. 3. The Manipulator gadget My

The vertices {Ty , Fy , Ty , Fy , RM, RT } ⊂ VR , the rest belongs to VC . Lemma 2. Let us consider variable cell Vy , y ∈ R, and the corresponding Manipulator My . Let the robber be at the vertex RM , let the cop be either on Ty or Fy and suppose no other cop can access any vertex of My in less than three moves. Then the normal scenario is following: By entering the vertex Ty (Fy ), the robber forces the cop to move towards the vertex Ty (Fy ). Robber then has to enter the vertex RT .

Complexity of the Cop and Robber Guarding Game

367

Proof. If the cop refuses to move, the robber advances to Ty or Fy and easily reaches VC before the cop can block him. On the other hand, if the robber moves to Ty or Fy even though the cop moved towards the opposite vertex, then cop ﬁnishes his movement to the opposite vertex and robber cannot move anymore. Note that this is not enough to ensure that the variable cop really reaches the opposite vertex and that only one variable cop from variable cells can move. We deal with this issue later. When changing variables of C, we have to make sure that at most one variable is changed at a time. We ensure that by the gadget Commander (see Fig. 4), connected to every Vx , x ∈ C. It consists of vertices {fx , gx , hx ; x ∈ C} ∪ {HQ} and edges {(HQ, hx ), (hx , HQ), (hx , fx ), (Tx , fx ), (Fx , fx ), (gx , fx ), (CM, gx ); x ∈ C}.

Cop region hx Tx

Fx

Robber region

fx

HQ

gx

CM

Fig. 4. The Commander gadget

The vertices {gx ; x ∈ C} and CM belong to VR , the rest belongs to VC . There is one cop, the “commander”, whose prescribed starting position is the vertex HQ. From every vertex w ∈ V \ (VC ∪ {CM } ∪ {gx ; x ∈ C}) we add → − the edge (w, HQ) to G , thus the only time the commander can leave HQ is when the robber stands at CM . The normal scenario is as follows: If the robber moves to CM , the commander decides one variable x to be changed and moves to hx , simultaneously the cop in the variable cell Vx starts its movement towards the opposite vertex. The commander temporarily guards the vertex fx , which is otherwise guarded by the cop in the cell Vx . Then the robber moves (away from CM ) and the commander has to return to HQ in the next move.

368

ˇ amal, R. Stolaˇr, and T. Valla R. S´

Lemma 3. Let us consider the Commander gadget and the variable cells Vx for x ∈ C with exactly one cop each, standing either on Tx or Fx . Let the robber be at the vertex CM and the cop at HQ, with the cop-player on move. Suppose no other cop can access the vertices in the Commander gadget. Then the normal scenario is that in at most one variable cell Vx , x ∈ X the cop can start moving from Tx to Fx or vice versa. Proof. Only the vertex fx is temporarily (for one move) guarded by the commander. If two variable cops starts moving, some fy is unsecured and robber exploits it by moving to gy in his next move. Note that the Manipulator allows the robber to “pass” changing of his variable by setting the current position of cop in some variable. Also note, that the robber may stay on the vertex CM , thus allowing the cop-player to change more than one of his variables. However, in any winning strategy of the robber-player this is not necessary and if the robber-player does not have a winning strategy, this trick does not help him as the cops may pass. 2.2

The Gates to VC

For every clause φ of FR , there is one Robber gate gadget Rφ . If φ is satisﬁed by the current setting of variables, Rφ allows the robber to enter VC .

Cop region

Robber region

R zφ

zφ

RT

C

Fig. 5. The Robber Gate Rφ

The Robber gate Rφ consists of a directed path (RT, zφ , zφ ) and the following edges. Let φ = (1 & . . . &12 ) where each i is a literal. If i = x then we put the → − → − edge (Fx , zφ ) to G . If i = ¬x then we put the edge (Tx , zφ ) to G . See Fig. 5 for illustration. The vertices {zφ ; φ ∈ FR } and RT belong to VR , the rest belongs to VC . Lemma 4. Let φ be a clause of FR , consider a Robber Gate Rφ . Let the robber stand at the vertex RT and let there be exactly one cop in each Vx , x ∈ φ,

Complexity of the Cop and Robber Guarding Game

369

standing either on Tx or Fx . Suppose no other cop can access Rφ in less than three moves. Then in the normal scenario robber can reach zφ if and only if φ is satisfied under the current setting of variables (given by the positions of cops on variable cells). Proof. If φ is satisﬁed, no cop at the variable cells can reach zφ in two (or less) steps. Therefore, the robber may enter zφ . On the other hand, if φ is not satisﬁed, at least one cop is one step from zφ and the robber would be blocked forever if he moves to zφ . For every clause ψ of FC , there is one Cop Gate gadget Cψ (see Fig. 6). If ψ is satisﬁed, Cψ allows cops to forever block the entrance to VC , the vertices zφ from each Robber Gate Rφ . The Cop Gate Cψ consists of directed paths (CT, bψ,x , bψ,x ) for each variable x of the clause ψ, the directed cycle (aψ , aψ , aψ , a ψ ) and edges {(aψ , bψ,x ), (aψ , bψ,x ); x ∈ ψ} and {(aψ , zφ ); φ ∈ FR }. Let ψ = (1 & . . . &12 ) where each i is a literal. If i = x then we put the → − → − edge (Tx , bψ,x ) to G . If i = ¬x then we put the edge (Fx , bψ,x ) to G . From the vertices aψ and aψ there is an edge to every bψ,x and from aψ there is an edge to every zφ (from each Robber Gate Rφ ). There is a cop, we call him Arnold, and his prescribed starting position is aψ . Each Cψ has its own Arnold, it would be therefore more correct to name him ψ-Arnold, however, we would use the shorter name if no confusion can occur. The vertices {bψ,x ; ψ ∈ FC , x ∈ ψ} and CT belong to VR , the rest belongs to VC . C

R zψ1

aψ

zψ2 zψ3

bψ,x

a ψ

aψ aψ

bψ,x

Cop region Robber region

CT Fig. 6. The Cop Gate Cψ

Lemma 5. Let us consider a Cop Gate Cψ . Let there be one cop at the vertex aψ (we call him Arnold) and let there be exactly one cop in each Vx , x ∈ ψ, standing on either Tx or Fx . Let the robber be at the vertex CT and no other cop can access Cψ in less than three moves. Then in the normal scenario, Arnold is able to move to aψ (and therefore block all the entrances zφ forever) without

370

ˇ amal, R. Stolaˇr, and T. Valla R. S´

permitting robber to enter VC if and only if ψ is satisfied under the current setting of variables (given by the position of cops in the variable cells). Proof. If ψ is satisﬁed, the vertices bψ,x , x ∈ ψ are all guarded by the variable cops, therefore Arnold can start moving from aψ towards aψ . If the robber meanwhile moves to some bψ,x , the variable cop from Vx will intercept him by moving to bψ,x and the robber loses the game. On the other hand, if ψ is not satisﬁed, there is some bψ,x unguarded by the cop from Vx . Therefore, Arnold cannot leave aψ , because otherwise robber would reach bψ,x before Arnold or the cop from Vx could block him. 2.3

The Big Picture

We further need to assure that the cops cannot move arbitrarily. This means, that the following must be the normal scenario: 1. During the “Robber Move” phase, the only cop who can move is the cop in variable cell Vx chosen by the robber when he enters Manipulator Mx . All other variable cops must stand on either Tx of Fx vertices for some variable x. The cop in Vx must reach the vertex Tx from Fx (or vice versa) in two consecutive moves. 2. During the “Robber Test” phase, no cop can move. 3. During the “Cop Move” phase, only the commander and the cop in exactly one variable cell Vx can move. The cop in Vx must reach the vertex Tx from Fx (or vice versa) in two consecutive moves. 4. During the “Cop Test” phase, no other cop than Arnold may move. Arnold may move from vertex aψ to aψ and he must do that in two consecutive steps (and of course Arnold may do that only if the clause ψ is satisﬁed). We say that we force the vertex w by the vertex set S, when for every v ∈ S → − we add the oriented path Pv,w = (v, pvw , pvw , w) of length 3 to the graph G . The vertices pvw , pvw belong to VR . We say that we block the vertex w by the vertex set S, when for every v ∈ S we add the Blocker gadget Bwv . The Blocker Bwv consists of vertices pv1 , pv2 ∈ VR and q1v , q2v ∈ VC and the edges (v, pvi ), (pvi , qiv ), (w, qiv ) for i = 1, 2. A cop on a vertex w blocked by v cannot leave w even for one move when the robber is on v. Note also that if the cop on w enters qiv when it is not necessary to block pvi , then he is permanently disabled until the end of the game and the next time the robber visits v he may enter the cop-region through the other pvj . Forcing serves as a tool to prevent moving of more than one variable cops (and Arnolds) however, because of the structure of variable cells, we cannot do it by simply blocking the vertices Tx , Fx and we have to develop the notation of forcing. Case 1: For every variable x ∈ C ∪ R do the following construction. Let Sx = {RM, RT } ∪ {V (My ); y ∈ R, x = y} where V (My ) are the vertices of Manipulator for variable y. We force the vertices Tx and Fx by the set Sx . Let S1 = {RM } ∪ {V (My ); y ∈ R}. For each Cop Gate Cψ , we force the vertex aψ by the set S1 . Finally, we block the vertex HQ by the set S1 . Observe that

Complexity of the Cop and Robber Guarding Game

371

whenever a cop from any other Vy than given by the Manipulator Mx is not on Ty or Fy , the robber can reach VC faster than the variable cop can block him. On the other hand, if all variable cops are in t