Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SICP HW box-and-pointer diagrams Ben decides to write a procedure to count the number of pairs in any list structure. It's easy, he reasons. The

SICP HW box-and-pointer diagrams

Ben decides to write a procedure to count the number of pairs in any list structure. It's easy, he reasons. The number of pairs in any structure is the number in the car plus the number in the cdr plus one more to count the current pair. So Ben writes the following procedure:

(define (count-pairs x) (if (not (pair? x)) 0 (+ (count-pairs (car x)) (count-pairs (cdr x)) 1)))

Show that this procedure is not correct. In particular, draw box-and-pointer diagrams representing list structures made up of exactly three pairs for which Ben's procedure would (1) return 3; (2) return 4; (3) return 7; (4) never return at all. The following example is the answer for (1) return 3; You are requested to draw for the case of 4, 7, and never return at all

image text in transcribed

(1) CASE: return 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

temperature alarm project

Answered: 1 week ago