Efficient graph algorithms using lazy monolithic arrays

From MaRDI portal





Many, perhaps even most, algorithms that involve data structures are traditionally expressed by incremental updates of the data structures. In functional languages, however, incremental updates are usually both clumsy and inefficient, especially when the data structure is an array. In functional languages, we instead prefer to express such array algorithms using monolithic arrays -- wholesale creation of the final answer -- both for succinctness of expression, efficiency (only one array created) and (sometimes) implicit parallelism. The ease with which the solution can be reformulated of course depends on the problem, and varies from trivial (e.g. matrix multiplication), to challenging (e.g. solving linear equation systems using Gauss elimination, which in fact can be done by creating only two arrays, recursively defined, of which one is the answer). Other problems have been notoriously resistant to attack; these usually involve some unpredictable processing order of the elements. One such problem is graph marking, i.e. marking the nodes reachable from a set of roots. Hitherto, no functional method has been known except emulating the traditional imperative solution. The contribution of this paper is to show how this problem, and some related ones, can be solved using a novel array creation primitive, lazier than previous ones. Thus, in section 2 we specify the array creation primitive lazyArray. In section 3, we give the solution to the graph marking and depth-first numbering problems using our lazy arrays. In section 4, we show how a related and more general problem, that of computing the transitive closure of a binary relation, can be solved in a similar manner. Graph based unification is an essential ingredient in a time and space efficient type inferencer: in section 5, we give such an algorithm in the same style. In section 6, we show how lazy arrays can be implemented efficiently with low-level graph reduction code. In section 7, we discuss space efficiency. Finally, in section 8, we relate our approach to state monadic computations, and show how to cast lazy array programs into monadic form. Programs in this paper will be given in the non-strict purely functional language Haskell.











This page was built for publication: Efficient graph algorithms using lazy monolithic arrays

Report a bug (only for logged in users!)Click here to report a bug for this page (MaRDI item Q4236881)