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

The midterm exam for the cpsc 201: introduction to computer science course. The exam covers topics such as binary search trees, majority functions, and machine code. Students are required to write the type and function for a binary search tree, create a truth table and boolean expression for a majority function, construct a circuit using and and or gates, and understand machine code instructions.

Typology: Exams

Pre 2010

Uploaded on 11/08/2009

koofers-user-s8q-1
koofers-user-s8q-1 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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:
pf3

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.