Be sure you have version 6.1.1 of Racket installed. (This is the latest version from the Racket web page.) It is installed on the tlab machines in `/home/software/racket-6.2.1/bin/drracket`, or you can use your own machine. Install it via `http://www.racket-lang.org`.

Open DrRacket, set the language to “The Racket Language” (via the Language | Choose Language menu item), put the following program into the upper window (replacing whatever is there), and click “Run”

#lang plai (expt 2 100)You should see the prompt in the interactions window (a

Install `nwu-321-2015.plt` by using DrRacket’s “File | Install .plt file...” menu item. In the dialog box, make sure the “Web” option at the top is selected and paste this url into the box:

Wait for the

After restarting DrRacket, select the **Manage EECS 321 PL Handin Account...** menu item from DrRacket's **File** menu. Change to the **New User** panel, and pick a username and password. (Use your real name and real NetID, so that we can connect your homework submissions with you. **DON'T** use your real password.)

You will have to install the `.plt` file in DrRacket for each different filesystem that you want to have **Handin** button. However, after creating a handin account once from any machine, you can use DrRacket's **Handin** button on any other machine.

There is a quick reference to things Rackety available from the course webpage. You may wish to have a look if you're not familiar with Racket.

Every homework assignment you hand in must begin with the following definition (taken from the Provost's website; see that for a more detailed explanation of these points):

(define eight-principles (list "Know your rights." "Acknowledge your sources." "Protect your work." "Avoid suspicion." "Do your own work." "Never falsify a record or permit another person to do so." "Never fabricate data, citations, or experimental results." "Always tell the truth when discussing your work with your instructor."))

If the definition is not present, you receive no credit for the assignment.

The following `Tree` datatype implements binary trees with numbers in each node and leaf:

(define-type Tree [leaf] [node (val number?) (left Tree?) (right Tree?)])

Every problem must come with an appropriate set of test cases. At a minimum the test cases must cover every branch in each function you write.

Implement a `smallest` function that takes a tree and returns the smallest number in the tree. If the tree is empty, `smallest` should return `+inf.0`, Racket's way of writing positive infinity.

Example: `(smallest (node 5 (leaf) (leaf)))` should produce `5` or `5.0`.

Impement the function `negate`, which takes a tree and returns a tree that has the same shape, but with all the numbers negated.

Example: `(negate (node 5 (leaf) (leaf)))` should produce `(node -5 (leaf) (leaf))`.

Impement the function `contains?`, which takes a tree and a number and returns `#t` if the number is found anywhere in the tree, `#f` otherwise.

Example: `(contains? (node 5 (leaf) (leaf)) 6)` should produce `#f`.

The second argument to the `contains?` function is “along for the ride”.

Impement the function `sorted?`, which takes a tree and determines whether it is sorted in the sense that the numbers increase (or stay the same) in a inorder traversal of the tree.

Your function should run in time proportional to the size of the tree, which rules out making a list of the tree numbers using `append` on recursive calls. Instead, you must accumulate some information as the function traverses the tree.

Implement the function `is-braun?`, which takes a tree and returns a boolean that indicates whether it is a Braun tree or not.

A Braun tree is one that satisfies one of the two criterion:

- It is a
`leaf`, or - It is a
`node`and both of its children are Braun trees and either their sizes are the same, or the left sub-tree has one more element than the right one.

The size of a Braun tree is the number of `node` constructors in it (`leaf`s do not contribute to the size).

Like the previous exercise, your function should run in time proportional to the size of the tree (no repeated traversals).

Implement the function `make-sorted-braun`, which takes a natural number and returns a braun tree with that size containing the natural numbers between zero and the given number minus one (inclusive), in order according to `sorted?`.

In other words, for any natural number `n`, it should be the case that both of these expressions return `#t`:

(is-braun? (make-sorted-braun n)) (sorted? (make-sorted-braun n))and if

(= (smallest (make-sorted-braun n)) 0) (= (smallest (negate (make-sorted-braun n))) (- 1 n))

For example, `(make-sorted-braun 4)` should produce:

(node 2 (node 1 (node 0 (leaf) (leaf)) (leaf)) (node 3 (leaf) (leaf)))and

Click the handin button in DrRacket to hand in your submission before the deadline. Late homework will not be accepted.

Last update: Saturday, September 12th, 2015robby@eecs.northwestern.edu |