Check that you have successfully submitted your code on okpy. Ordered Implement a procedure called ordered? Extra material related to CS61A, Fridays 4: Everything that can be written with while and for loops and also be written recursively. Homework, or a homework assignment, is a set of tasks assigned to students by their teachers to be completed outside the class. Define the procedures cadr and caddr , which return the second and third elements of a list, respectively:. Fill in the blanks in the following function definition for adding a to the absolute value of b, without calling abs.

Try writing the function iteratively in Python, then convert into a tail recursive Scheme function. You might find the following references useful:. See Lab 0 for more instructions on submitting assignments. If you have any questions about using OK, please refer to this guide. You might find the following references useful: In such cases, the list will print with a dot before the final item to indicate that its last two items are contained in a single pair.

We make a new frame for the call, and in carrying out the body of the function, we hit the recursive case, where we want to multiply 5 by the return value of the call to fact 4. Scheme Specification Scheme Primitives Reference 2. Write a function that takes three positive numbers and returns the sum of the squares of the two largest numbers.

Despite the doctests above, this function actually does not do the same thing as an if statement in all cases. Also, define unionwhich returns a set containing all values that appear in either set s or cs6a1. If no clause has a true predicate, the result is an “unspecified value”.

Goodrich Tamassia, Section 3. Add Define addwhich takes a set s and a value v as arguments. Scheme realizes that there is no reason to keep around a frame that has no work left to do, so it just has the return of the recursive call return directly to whatever called the current frame.

If you have any questions about using OK, please refer to this guide. Recall from lecture that Scheme supports tail-call optimization. In such cases, the list will print with a dot before the final item to indicate that its last two items are contained in a single pair. It returns a representation of a set containing the values in s and hmoework value v.

# Homework 1 Solutions | CS 61A Summer

You might find the cs6a1 references useful: Check that you have successfully submitted your code on okpy. A Python implementation of this procedure is provided for your reference. Your implementation should run in linear time in the length of the input sets. Write a function that takes.

This homework must be submitted online and on paper.

Abelson Sussman, Section 2. Our course uses a custom version of Scheme which you will build for Project 4 included in the starter ZIP archive.

## Homework Questions

You may submit more than once before the deadline; only the final submission will be scored. CS 61A or Engineering.

Define addwhich takes a set s and a value v as arguments. The Python implementation of this procedure is provided for your reference. Keeping all these frames around wastes a lot of space, so our goal is to come up with an implementation of factorial that uses a constant amount of space. You might find the following references useful:.

## cs61a homework 2

Mid-semester Survey is no longer accepting responses. The general form of a conditional expression is:. Implement a procedure called ordered? The Python hoemwork of this procedure is provided for your reference. Use only a single line for the body of the function. See Lab 0 for more instructions on submitting assignments. Conditional expressions are evaluated as follows: Ordered Implement a procedure called ordered? Structure and Interpretation of Computer Programs Due by