Your name __________________________

 

 

Harvey Mudd College

CS 60 Mid-Term Exam

Spring semester, 1998

Six Problems

100 Points

Closed book

Instructions

During the exam, the only item to which you may refer is your own reference sheet, one double-sided sheet of 8.5" x 11" paper.

The exam is planned for 1 hour, 15 mins., ending at 4:00 p.m. You may use the time from 4:00-4:15 if the classroom is not otherwise in use, but all papers must be in by 4:15 at the latest.

Please provide answers to the problem groups directly on these pages. It is suggested that you look over the exam first to get an idea of how to apportion your time. Work so as to maximize total points; do not get stuck on one problem at the expense of others.

For each problem, the action items are shown in boldface.

When code is requested, exhibiting the correct idea is more important than syntactic precision. However, keep your definitions clean and readable. Use the clearest program structure possible.

The answers to these problems should not be exceptionally long. Please think through your solution before you plunge into a long exposition that might not address the main point of the question.

1. [10 points]

The concept of an "and-or tree" is used in artificial intelligence problem solving. For our purpose, assume the following inductive definition of and-or tree:

The above rules describe the only ways to get an and-or tree.

For example, using a typical tree-as-list representation, the following are each and-or trees:

Moreover, an and-or tree is called solvable according to the following inductive rules:

The above rules describe the only ways in which a tree is solvable.

For example, ["+", 0, 1, 1, 0] is solvable, but ["*", 1, ["+", 0, 1, 1, 0], ["+", 0, 1], 0] is not.

Give a set of rex rules for computing a function solvable, which tells whether its and-or tree argument is solvable. You may assume the tree is well-formed; you do not have to perform error-checking on the argument.

answer

 

2. [15 points]

Who said you can't add apples to oranges? The generic calculator™ can add anything to anything, as shown in the following examples:

Input

Output

5 apples + 3 apples

8 apples

3 oranges + 5 oranges

8 oranges

5 apples + 3 oranges

5 apples, 3 oranges

5 apples, 2 bananas - 3 apples

2 apples, 2 bananas

2 bananas + 5 apples + 3 oranges

5 apples, 2 bananas, 3 oranges

5 apples, 5 bananas - 2 bananas

5 apples, 3 bananas

5 apples - 4 apples

1 apples

Assume the following things are true about the generic calculator™:

Describe an internal data representation for the generic calculator™. This representation should have the property of making the calculations easy to code (see next problem). (Some kind of list should probably be used.)

answer

 

3. [25 points]

Give code for the add function, which carries out the + operation, assuming your chosen data representation above. I would recommend using rex, but any common language will do.

answer

 

4. [20 points]

Suppose we wished to provide free-form input for the generic calculator™ of the previous problem. Give a grammar for the input language assuming that the comma binds more tightly than the +. Please use S as the root of your grammar, so I will know which symbol is the root.

answer

 

5. [15 points]

Sketch an algorithm for solving the problem of counting the number of "connected regions" (of blanks) on a grid of pixels. For example, in the following diagram, there are five connected regions inside the grid boundary. For purposes of defining connectedness, two pixels are connected if one is either directly above, directly below, directly to the left, or directly to the right, of the other.

answer

 

6. [15 points]

A search engine is to be applied to finding pages on the worldwide web with a specific set of search criteria. The user wishes to find all pages such that the page satisfies one or more of the following:

    1. contains the words "computer" and "science", or
    2. contains the word "logic" but not "science", or
    3. contains the word "computer", but not "logic" and not "science", or
    4. contains the words "science" and "logic", but not "computer".

Derive, by using a Karnaugh map, the most simplified search criterion you can which is equivalent to the above.

answer