Project #4: μScheme Practice

Submit: Turn in your hw4.uscm source file using the turnin command on morbius.mscsnet.mu.edu or one of the other Systems Lab machines.

Work is to be completed in teams of two. Be certain to include both teammates names in the file. You may submit multiple times, but only the last turnin will be kept. The automatic submission system will not accept work after the deadline.

This assignment makes use of the Binary Tree Demo from class. To use these definitions for your assignment, copy the ~brylow/cosc3410/demo/tree-manual.uscm source file into the same directory as your hw4.uscm file. Include at the top of your file:

(use tree-manual.uscm)

Do not turnin (use tree-manual.uscm) with your assignment; I will provide my own copy when grading.

Q1 - path

Write a function path that given an integer and a sorted binary tree of integers, returns a list of the turns that must be taken to reach the integer from the root, or #f if the element does not exist in the tree.

path : Int x BinaryTree(Int) → S-List
Usage: (path n t) = lst, a list of lefts and rights showing how to re ach the node in t that contains n.
This problem relies upon the binary tree demonstration from lecture. See abo ve.

Examples:
> (path 3 (tree-add 5 (tree-add 3 (tree-add 7 (tree-make-null)))))
(left)
> (path 5 (tree-add 5 (tree-add 3 (tree-add 7 (tree-make-null)))))
(left right)
> (path 7 (tree-add 5 (tree-add 3 (tree-add 7 (tree-make-null)))))
()
> (path 2 (tree-add 5 (tree-add 3 (tree-add 7 (tree-make-null)))))
#f

Q2 - Traversals

Chapter 2.16.5, exercise 11. Write inorder and postorder, but use the manually defined tree data structure from class, as above.

Examples:
> (postorder (tree-add 7 (tree-add 5 (tree-add 6 (tree-add 3 (tree-add 1 (tree-add 2 (tree-add 4 (tree-make-null)))))))))
(1 3 2 5 7 6 4)
> (inorder (tree-add 7 (tree-add 5 (tree-add 6 (tree-add 3 (tree-add 1 (tree-add 2 (tree-add 4 (tree-make-null)))))))))
(1 2 3 4 5 6 7)

Q3 - Exploding and Imploding digits

Chapter 2.16.2, exercise 2.

Q4 - Dot Product

Chapter 2.16.2, exercise 5.

Q5 - From Lists to S-Exps

Chapter 2.16.4, exercise 8.


[back]

[Revised 2023 Oct 02 13:56 DWB]