Version: 4.1.1.3

## Homework 4

Language: Beginning Student with List Abbreviations

### 1Binary search trees

Do exercises 14.2.3, 14.2.5, and 14.2.6 from HtDP.

### 2Sorted lists

 ; A sorted-list is either ; - empty ; - (cons number[n] sorted-list[l]) ; INVARIANT: each number in ‘l’ is larger than ‘n’

Write the following function:

 ; in? : sorted-list number -> boolean ; determines if ‘n’ is in ‘l’ (define (in? l n) ---)

You must exploit the sorted-list invariant.

### 3Heap

 ; A heap is either ; - false ; - (make-node number[n] heap[l] heap[r]) ; INVARIANT: each number in ‘l’ is larger than ‘n’ ; INVARIANT: each number in ‘r’ is larger than ‘n’

Write the following functions:

 ; in-heap? : heap number -> boolean ; determines if ‘n’ is in ‘h’ (define (in-heap? h n) ---) ; insert-in-heap : heap number -> heap ; constructs a new heap that contains ; all of the numbers in ‘h’, plus ‘n’ (define (insert-in-heap h n) ---)

You must exploit/maintain the heap invariant in each function (as appropriate).