This preview shows pages 1–2. Sign up to view the full content.
Lab 3: Abstract Data Types
Introduction
This lab has two main purposes:
1. To provide you with more practice working with lists in Scheme
2. To illustrate one method for implementing abstract data types in Scheme
The lab requires you to remember a little about trees from your datastructures
class (CIS 351); if you have trouble with the terminology, check with a labmate
or the TA or me.
This lab is not intended to be tricky; in particular, don’t rule out an obvious
answer because you think it can’t be that simple.
Binary Trees
A binary tree is a tree where every node has either no children, a left child, a right
child, or both a left and right child; under this deﬁnition, the empty tree (i.e.,
the tree with no nodes) is also a binary tree. If we assume that every node has a
numeric id, then binary trees can be speciﬁed by the following BNF speciﬁcation:
h
bintree
i
::=
()

(
h
number
i h
bintree
i h
bintree
i
)
For example,
(5 (2 () (4 () ())) (7 (6 () ()) (15 () ())))
is a valid
h
bintree
i
(convince yourself before continuing), corresponding to the (abstract)
tree that we might sketch as follows:
n
5
±
±
Q
Q
n
2
J
J
n
7
²
²
J
J
n
4
n
6
n
15
Note that the role of
()
in
h
bintree
i
is similar to that of
Null
pointers in C,
indicating the absence of any nodes at all. Therefore, a
leaf
is a
h
bintree
i
with
form
(
h
number
i
() ())
.
For any nonempty
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Winter '10
 someone
 Computer Science

Click to edit the document details