ArticlePDF Available

Lazy Depth-First Search and Linear Graph Algorithms in Haskell

Authors:

Abstract and Figures

Depth-first search is the key to a wide variety of graph algorithms. In this paper we explore the implementation of depth first search in a lazy functional language. For the first time in such languages we obtain a linear-time implementation. But we go further. Unlike traditional imperative presentations, algorithms are constructed from individual components, which may be reused to create new algorithms. Furthermore, the style of program is quite amenable to formal proof, which we exemplify through a calculational-style proof of a strongly-connected components algorithm. 1 Introduction Graph algorithms have long been a challenge to programmers of lazy functional languages. It has not been at all clear how to express such algorithms without using side effects to achieve efficiency. For example, many texts provide implementations of search algorithms which are quadratic in the size of the graph (see Paulson (1991), Holyer (1991), or Harrison (1993)), compared with the standard linear im...
Content may be subject to copyright.
500
1000
1500
2000
2500
3000
3500
4000
4500
5000
0
500
1000
1500
2000
2500
3000
3500
4000
4500
5000
5
10
15
20
25
30
Vertices
Edges
Seconds
... Thus the Haskell implementation is based on the assumption that the Ports Collection can be represented as a directed acyclic graph, where ports are the nodes, and edges are the dependency relations (Figure 3). Fortunately, a graph module, Data.Graph [4] is immediately at the implementers' hands as it can be found the base Haskell libraries. Hence all we have to do is to parse the describe file, turn the ports tree into a graph, and query which nodes can be reached from the one representing the changed port. ...
Article
In the last decades, scene of functional programming has changed dramati-cally as many new compilation and programming techniques were introduced, and then became available. Many research efforts put into development of better languages and compilers is focused in Haskell, a standardized, general-purpose, lazy, pure functional language. It supports several features to make today's software engineering easier with a minimal loss in performance. This paper investigates the possibilities on how to employ these features in sup-porting the development of an "unknown giant among free operating systems", namely FreeBSD. On the other hand, FreeBSD, as a descendant of AT&T UNIX via the Berkeley Software Distribution, represents reliable and stable UNIX-compliant internals and system APIs, which might help to keep devel-opment of the de facto standard Glasgow Haskell Compiler in a reasonably good shape. We believe that these open source projects would be able to help each other in a promising way.
... For a given evolving graph, the computation of most of these metrics is simple. Computing N CCi uses well known graph algorithms [9]. Computing Li and Qi requires simple accumulation of information about link changes. ...
Conference Paper
Research into wireless data networks with mobile nodes has mostly considered Mobile Ad Hoc Networks (or MANETs). In such networks, it is generally assumed that end-to-end, possibly multi-hop paths between node pairs exist most of the time. Routing protocols designed to operate in MANETs assume that these paths are formed by a set of wireless links that exist contemporaneously. Disruption or delay tol- erant networks (DTNs) have received significant attention recently. Their primary distinction from MANETs is that in DTNs links on an end-to-end path may not exist con- temporaneously and intermediate nodes may need to store data waiting for opportunities to transfer data towards its destination. We call such DTN paths space-time paths to distinguish them from contemporaneous space paths used in MANETs. We argue in this paper that MANETs are actu- ally a special case of DTNs. Furthermore, DTNs are, in turn, a special case of disconnected networks where even space- time paths do not exist. In this paper we consider the ques- tion of how to classify mobile and wireless networks with the goal of understanding what form of routing is most suitable for which network. We first develop a formal graph-theoretic classification of networks based on the theory of evolving graphs. We next develop a routing-aware classification that recognizes that the boundaries between network classes are not hard and are dependent on routing protocol parameters. This is followed by the development of algorithms that can be used to classify a network based on information regard- ing node contacts. Lastly, we apply these algorithms to a selected set of mobility models in order to illustrate how our classification approach can be used to provide insight into wireless and mobile network design and operation.
... F.N , where N is the type of node identiers and F is some functor. King and Launchbury (1993) implement some graph algorithms (topological sort, connected components, strong components, reachability) by imperatively performing a depth-rst search on the graph, and declaratively manipulating the resulting depth-rst-search forest. Burton and Yang (1990) implement graphs in a pure functional language eectively by implementing an imperative store and threading this through the program. ...
Article
Full-text available
The initial-algebra approach to modelling datatypes consists of giving constructors for building larger objects of that type from smaller ones, and laws identifying different ways of constructing the same object. The recursive decomposition of objects of the datatype leads directly to a recursive pattern of computation on those objects, which is very helpful for both functional and parallel programming. We show how to model a particular kind of directed acyclic graph using this initial-algebra approach.
Article
This paper presents a Haskell library for graph processing: DeltaGraph. One unique feature of this system is that intentions to perform graph updates can be memoized in-graph in a decentralized fashion, and the propagation of these intentions within the graph can be decoupled from the realization of the updates. As a result, DeltaGraph can respond to updates in constant time and work elegantly with parallelism support. We build a Twitter-like application on top of DeltaGraph to demonstrate its effectiveness and explore parallelism and opportunistic computing optimizations.
Conference Paper
This paper presents a Haskell library for graph processing: DeltaGraph. One unique feature of this system is that intentions to perform graph updates can be memoized in-graph in a decentralized fashion, and the propagation of these intentions within the graph can be decoupled from the realization of the updates. As a result, DeltaGraph can respond to updates in constant time and work elegantly with parallelism support. We build a Twitter-like application on top of DeltaGraph to demonstrate its effectiveness and explore parallelism and opportunistic computing optimizations.
Conference Paper
Graph algorithms have fundamental applications in the real world but can be both cumbersome to implement in traditional languages and difficult to execute efficiently on modern multicore hardware. The Bulk Synchronous Parallel model of computation has recently been used to define vertex-centric computations on graphs. We describe an em- bedded domain specific language (using Haskell as the underlying host language) for specifying such algorithms, and show an implementation of an execution platform that allows to execute them on multicore systems in parallel. For several benchmarks varying in algorithm, graph size and edge distribution, we achieved speedups ranging from 9 up to 11 for 16 threads.
Article
The "software crisis" is yet to be solved. The problem is that software development and maintenance is too time consuming and thereby too expensive. One way to try to solve or partly solve the problem is to employ new programming languages with properties that reduce development time and help in maintenance. Erlang, a language developed by an Ericsson company, may be such a language. The topic of this report is whether Erlang is a better platform for developing a specific telecom application, a SCF-debugger, than the currently used language, C++. To evaluate Erlang a prototype for this debugger was developed. ii A Comparison Between Erlang and C++ for Implementation of Telecom Preface After living in the coffee room for half a year we are getting quite used to the other inhabitants here at Ericsson. We wish to thank: our supervisors at Ericsson, Konstantin Zervas and Krister Arlinger who have endured us for so long, the Erlang people who have been incredibly fast to answer question...
Conference Paper
Full-text available
Functional programs are widely appreciated for being declarative (algorithms are not over-specified) and implicitly paralle. However, when modeling state, both properties are compromised because the state variables must be threaded through most functions. Further, state up-dates may require much copying. A solution is to introduce assignments, as in ML and Scheme; however, for meaningful semantics, they resort to strict, sequential evaluation. We present an alternative approach called M-structures, which are imperative data structures with implicit synchronization. M-structures are added to Id, a parallel non-strict functional language. We argue that some programs with M-structures improve on their functional counterparts in three ways: they are (1) more declarative; (2) more parallel; and (3) more storage efficient. Points (1) and (2) contradict conventional wisdom. We study two problems: histogramming a tree, and graph traversal, comparing functional and M-structure solutions.
Conference Paper
Full-text available
We present a new model, based on monads, for performing input/output in a non-strict, purely functional language. It is composable, extensible, efficient, requires no extensions to the type system, and extends smoothly to incorporate mixed-language working and in-place array updates.
Article
We present a new linear algorithm for constructing all strongly connected components of a directed graph, and show how to apply it in iterative solution of data-flow analysis problems, to obtain a simple algorithm which improves the Hecht-Ullman algorithm.
Article
Efficient algorithms are presented for partitioning a graph into connected components, biconnected components and simple paths. The algorithm for partitioning of a graph into simple paths is iterative and each iteration produces a new path between two vertices already on paths. (The start vertex can be specified dynamically.) If V is the number of vertices and E is the number of edges each algorithm requires time and space proportional to max(V,E) when executed on a random access computer.
Article
An abstract is not available.
Article
This paper concerns the computational complexity of depth-first search. Suppose we are given a rooted graph G with fixed adjacency lists and vertices u, v. We wish to test if u is first visited before v in depth-first search order of G. We show that this problem, for undirected and directed graphs, is complete in deterministic polynomial time with respect to deterministic log-space reductions. This gives strong evidence that depth-first search ordering can be done neither in deterministic space (log n)c nor in parallel time (log n)c, for any constant c > 0.
Conference Paper
We encourage a specific view of graph algorithms, which can be paraphrased by "iterate over the graph elements in a specific order and perform computations in each step". Data structures will be used to define the processing order, and we will introduce recursive mapping/array definitions as a vehicle for specifying the desired computations. Being concerned with the problem of implementing graph algorithms, we outline the extension of a functional programming language by graph types and operations. In particular, we explicate an exploration operator that essentially embodies the proposed view of algorithms. Fortunately, the resulting specifications of algorithms, in addition to being compact and declarative, are expected to have an almost as efficient implementation as their imperative counterparts. 1 Introduction Looking at graph algorithms, we observe that many of them have a very similar structure, namely iterating over nodes or edges and thereby performing computations. Since grap...