O(log n) persistent on-line lowest common ancestor calculation without preprocessing

Version on this page:0.3
LTS Haskell 8.2:0.3
Stackage Nightly 2017-02-20:0.3
Latest on Hackage:0.3
BSD3 licensed by Edward A. Kmett
Maintained by Edward A. Kmett

Module documentation for 0.3

There are no documented modules for this package.

lca: O(log h) Online Lowest Common Ancestor Search

Build Status

This package provides a reference implementation of my skew binary random access algorithm for performing an online lowest common ancestor in logarithmic time without preprocessing. This improves the previous known asymptotic bound for this problem from O(h) to O(log h), where h is the height of the tree. Mostly importantly this bound is completely independent of the width or overall size of the tree, enabling you to calculate lowest common ancestors in a distributed fashion with good locality.

While algorithms exist that that provide O(1) query time, they all require O(n) preprocessing, where n is the size of the entire tree, and so are less suitable for LCA search in areas such as revision control where the tree is constantly updated, or distributed computing where the tree may be too large to fit in any one computer's memory.

Slides are available as Purely Functional Data Structures for On-Line LCA

Contact Information

Contributions and bug reports are welcome!

Please feel free to contact me through github or on the #haskell IRC channel on

-Edward Kmett



  • Updated to build without warnings in the wake of GHC 7.10.
  • Use (and re-export) the new overloaded null and length from Prelude on GHC 7.10+
  • Modified mkeep, mdrop and mlca to parameterize them by monoid homomorphisms. This permits cheaper summaries to be calculated over the dropped path, when only a portion of the information in the path is required.


  • Fixed a bug in path reconstruction


  • Improved documentation to also note that this package also provides an improvement in the online version of the level ancestor problem.


  • Added README
  • Better haddock coverage
  • Added links to documentation
Depends on:
Used by 1 package:
comments powered byDisqus