The number of distinct pairs in a structure

Devise a correct version of the count-pairs procedure of exercise 3.16 that returns the number of distinct pairs in any structure. (Hint: Traverse the structure, maintaining an auxiliary data structure that is used to keep track of which pairs have already been counted.)

There are no comments yet.

Authentication required

You must log in to post a comment.

(define p1 (cons 'a nil))
(define p2 (cons p1 nil))
(define p3 (cons p1 p2))
(define p4 (cons p2 p1))
(define p5 (cons p1 p1))
(define p6 (cons p5 p5))

(check-equal? (count-pairs p3) 3)
(check-equal? (count-pairs p4) 3)
(check-equal? (count-pairs p6) 3)
(check-equal? (count-pairs '()) 0)