SICP Exercise 3.17 correct count-pairs

Exercise 3.17.  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.)

SOLUTION

The code is here:

Exercise 3.17 correct count-pairs

The explanation and the box-and-pointer diagram is here:

Diagram


Comments

Popular posts from this blog

SICP Exercise 1.22 search-for-primes

SICP Exercise 4.2 Louis Reasoner eval

SICP Exercise 3.45 deadlock