lab3 - Lab 3: Abstract Data Types Introduction This lab has...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
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 data-structures 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 definition, 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 specified by the following BNF specification: h bin-tree i ::= () | ( h number i h bin-tree i h bin-tree i ) For example, (5 (2 () (4 () ())) (7 (6 () ()) (15 () ()))) is a valid h bin-tree 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 bin-tree i is similar to that of Null pointers in C, indicating the absence of any nodes at all. Therefore, a leaf is a h bin-tree i with form ( h number i () ()) . For any nonempty
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

lab3 - Lab 3: Abstract Data Types Introduction This lab has...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online