This review sheet is intended to help you study for the midterm exam. It is not intended to be an exhaustive list of everything we've covered, but it should help you identify the "big ideas".
You should also review your lecture notes and the solutions to your homework problems. The lecture "quizzes" are especially useful in helping you study for the exam.
Please remember that you may use at the exam a 8.5 by 11 sheet of self-made notes.
These don't hope to span all of the topics we've covered, but they are meant to give a sense of the size and scope of possible exam problems.
Racket> (foldr (lambda (X, Y) (+ X Y)) 0 '(1, 2, 3, 4))You should assume that foldr "associates" (orders operations) like this: 1 + 2 + 3 + 4 = 1 + (2 + (3 + (4 + 0))). (Notice that the 0 at the end is the unit for addition.) Write the foldr function from scratch. That is, your implementation my use Racket's list notation and recursion, but no built-in functions. Notice that foldr should not be written exclusively to handle addition! It's first argument can be any function of two variables, its second argument is the unit for that function, and its third argument is a list of elements of the type operated on by the given function.
10
Write a function (closest-sum target L) that takes in a numeric target and a list of numbers L. Then, closest-sum should return the subset of the elements of L whose sum is as close as possible to target.
For example,
Ties may be handled arbitrarily... any best answer is OK.
(closest-sum 19 '(3 4 7 7 22))
'(4 7 7)
You've been hired by Millisoft, a major software company. Your first job is to write a class called BasicDictionary that supports the dictionary abstract data type operations of insert and find. The insert method takes a reference to an object and inserts it into the dictionary. The dictionary will be implemented as a binary search tree.
The objects that are being inserted and found are Strings: these can be compared with the compareTo method, which works like "less than" using alphabetical order.
Your job is to give an implementation of the BasicDictionary class using a binary search tree implementation. Below is the starter code with comments. Just implement the insert method, not the find method.
class BasicDictionary
{
class TreeNode
{
private String data;
private TreeNode lessChild;
private TreeNode greaterChild;
TreeNode(String data)
{
this.data = data;
this.lessChild = null;
this.greaterChild = null;
}
}
protected TreeNode root; // Reference to the root of the tree
BasicDictionary()
{
this.root = null;
}
public void insert(String data)
{
// FILL IN THIS CODE
}
}