Abstract
The Revised6 Report on Scheme requires its generic equivalence predicate, equal?, to terminate even on cyclic inputs. While the terminating equal? can be implemented via a DFA-equivalence or union-find algorithm, these algorithms usually require an additional pointer to be stored in each object, are not suitable for multithreaded code due to their destructive nature, and may be unacceptably slow for the small acyclic values that are the most likely inputs to the predicate.
This paper presents a variant of the union-find algorithm for equal? that addresses these issues. It performs well on large and small, cyclic and acyclic inputs by interleaving a low-overhead algorithm that terminates only for acyclic inputs with a more general algorithm that handles cyclic inputs. The algorithm terminates for all inputs while never being more than a small factor slower than whichever of the acyclic or union-find algorithms would have been faster. Several intermediate algorithms are also presented, each of which might be suitable for use in a particular application, though only the final algorithm is suitable for use in a library procedure, like equal?, that must work acceptably well for all inputs.
Supplemental Material
Available for Download
Supplemental material for: Efficient nondestructive equality checking for trees and graphs
- William D. Clinger. SRFI 85: Recursive equivalence predicates, March 2006. URL http://srfi.schemers.org/srfi-85/.Google Scholar
- William D. Clinger. SRFI 85: Recursive equivalence predicates (corrected reference implementation), December 2007. URL http://srfi.schemers.org/srfi-85/post-mail-archive/msg00001.html.Google Scholar
- Zvi Galil and Giuseppe F. Italiano. Data structures and algorithms for disjoint set union problems. ACM Comput. Surv., 23(3):319--344, 1991. ISSN 0360-0300. doi: http://doi.acm.org/10.1145/116873.116878. Google Scholar
Digital Library
- Benrard A. Galler and Michael J. Fisher. An improved equivalence algorithm. Commun. ACM, 7(5):301--303, 1964. ISSN 0001-0782. doi: http://doi.acm.org/10.1145/364099.364331. Google Scholar
Digital Library
- Abdulaziz Ghuloum and R. Kent Dybvig. Generation-friendly eq hash tables. In 2007 Workshop on Scheme and Functional Programming, pages 27--35, 2007. URL http://sfp2007.ift.ulaval.ca/programme.html.Google Scholar
- John E. Hopcroft and R. M. Karp. A linear algorithm for testing equivalence of finite automata. Technical Report 71-114, Cornell University, Ithaca, NY, 1971. URL http://ecommons.library.cornell.edu/handle/1813/5958.Google Scholar
- Richard Kelsey, William Clinger, and Jonathan Rees (eds.). Revised5 report on the algorithmic language Scheme. Higher-Order and Symbolic Computation, 11(1):7--105, 1998. Also appears in ACM SIGPLAN Notices 33(9), September 1998. Google Scholar
Digital Library
- Michael Sperber, R. Kent Dybvig, Matthew Flatt, and Anton van Straaten (eds.). Revised6 report on the algorithmic language Scheme, September 2007. URL http://www.r6rs.org/. Google Scholar
Digital Library
- Robert E. Tarjan and Jan van Leeuwen. Worst-case analysis of set union algorithms. J. ACM, 31(2):245--281, 1984. ISSN 0004-5411. doi: http://doi.acm.org/10.1145/62.2160. Google Scholar
Digital Library
- Robert Endre Tarjan. Efficiency of a good but not linear set union algorithm. J. ACM, 22(2):215--225, 1975. ISSN 0004-5411. doi: http://doi.acm.org/10.1145/321879.321884. Google Scholar
Digital Library
Index Terms
Efficient nondestructive equality checking for trees and graphs
Recommendations
Efficient nondestructive equality checking for trees and graphs
ICFP '08: Proceedings of the 13th ACM SIGPLAN international conference on Functional programmingThe Revised6 Report on Scheme requires its generic equivalence predicate, equal?, to terminate even on cyclic inputs. While the terminating equal? can be implemented via a DFA-equivalence or union-find algorithm, these algorithms usually require an ...
Experiments on union-find algorithms for the disjoint-set data structure
SEA'10: Proceedings of the 9th international conference on Experimental AlgorithmsThe disjoint-set data structure is used to maintain a collection of non-overlapping sets of elements from a finite universe. Algorithms that operate on this data structure are often referred to as Union-Find algorithms. They are used in numerous ...
Proof Search in Intuitionistic Logic with Equality, or Back toSimultaneous Rigid E -Unification
We characterize provability in intuitionistic logic with equality in terms of a constraint calculus. This characterization uncovers close connections between provability in intuitionistic logic with equality and solutions to simultaneous rigid E -...







Comments