Docsity

CPSC 201 Midterm Exam: Introduction to Computer Science, Exams of Computer Science

Partial preview of the text

Download CPSC 201 Midterm Exam: Introduction to Computer Science and more Exams Computer Science in PDF only on Docsity!

CPSC 201: Introduction to Computer Science Carsten Sch¨urmann Date: February 26, 2002

Midterm

Friday, March 1, 2002.

Name:

Problem 1:

Problem 2:

Problem 3:

Sum:

Problem 1: Programming in ML

Assume that we are given a binary search tree. A binary search tree

5

with the representation invariant that any tree of the form Node (left, x, right) satisfi It has the following form.

Question 1: Write

  1. What is the type of this function?
  2. What is the invariant of this function?
  3. Write the function itself.

Problem 3: Boolean Logic (40 Points)

A majority function Mn(x 1 ,... , xn) is true if a majority of its inputs are true and f alse otherwise (assume n odd). In this assignment we study majority functions with three inputs.

  1. Write the truth table for a majority function M 3 (x 1 , x 2 , x 3 ) with just three inputs.
  2. Write the Boolean expression for this majority function.
  3. Construct the circuit for M 3 (x 1 , x 2 , x3) using only AN D and OR gates. Hint: A typical implementation uses three AN D gates and three OR gates. Re- formulate your answer from 2. using distributivity laws.
  4. Does M 3 (x 1 , x 2 , x 3 ) and N OT gate form a complete Boolean basis? Justify your answer. Hint: A NAND Gate alone, a NOR Gate alone, or the set of AND, OR and NOT gate form a complete Boolean basis. Try to implement one of these (or possibly other basis) using the M 3 (x 1 , x 2 , x 3 ) and a N OT gate.