skip to main content
research-article

Efficient nondestructive equality checking for trees and graphs

Published:20 September 2008Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

Video

References

  1. William D. Clinger. SRFI 85: Recursive equivalence predicates, March 2006. URL http://srfi.schemers.org/srfi-85/.Google ScholarGoogle Scholar
  2. 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 ScholarGoogle Scholar
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle Scholar
  6. 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 ScholarGoogle Scholar
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Efficient nondestructive equality checking for trees and graphs

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      • Published in

        cover image ACM SIGPLAN Notices
        ACM SIGPLAN Notices  Volume 43, Issue 9
        ICFP '08
        September 2008
        399 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/1411203
        Issue’s Table of Contents
        • cover image ACM Conferences
          ICFP '08: Proceedings of the 13th ACM SIGPLAN international conference on Functional programming
          September 2008
          422 pages
          ISBN:9781595939197
          DOI:10.1145/1411204

        Copyright © 2008 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 20 September 2008

        Check for updates

        Qualifiers

        • research-article
      • Article Metrics

        • Downloads (Last 12 months)1
        • Downloads (Last 6 weeks)1

        Other Metrics

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!