Linear-Time Graph Programs without Preconditions
Ziad Ismaili Alaoui, Detlef Plump
TL;DR
The paper tackles the room for linear-time non-destructive graph programs in GP 2 by removing connectivity and degree preconditions that hampered previous approaches. It introduces two compiler enhancements that index edges by marks and orientation and organize nodes by marks, enabling constant-time matching and constant-time access to candidates. Through three case studies—recognising acyclic graphs, numbering connected components, and performing breadth-first search—the authors demonstrate linear-time performance on graphs with unbounded degree and possible disconnection, supported by empirical timings. This work broadens the practical reach of rule-based graph programming and points toward a library of advanced data structures to sustain further linear-time variants of standard graph algorithms.
Abstract
We report on a recent breakthrough in rule-based graph programming, which allows us to reach the time complexity of imperative linear-time algorithms. In general, achieving the complexity of graph algorithms in conventional languages using graph transformation rules is challenging due to the cost of graph matching. Previous work demonstrated that with rooted rules, certain algorithms can be executed in linear time using the graph programming language GP 2. However, for non-destructive algorithms that retain the structure of input graphs, achieving linear runtime required input graphs to be connected and of bounded node degree. In this paper, we overcome these preconditions by enhancing the graph data structure generated by the GP 2 compiler and exploiting the new structure in programs. We present three case studies, a cycle detection program, a program for numbering the connected components of a graph, and a breadth-first search program. Each of these programs runs in linear time on both connected and disconnected input graphs with arbitrary node degrees. We give empirical evidence for the linear time complexity by using timings for various classes of input graphs.
