Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CSE/ISE 215 Foundations of Computer Science

Sample Problems for Exam III - December 4, 2014

1. Let A be the set {1, 3, 5, 7, 9} and B be the set of all digits occurring
in your Stony Brook ID-number. (For example, if the ID number is
100105255, then B is {0, 1, 2, 5}.) Give functions as indicated (or else
explain why there is no function that meets the stated conditions).
(a) Give a function f1 : A B that is one-to-one but not onto.
(b) Give a function f2 : A B that is onto but not one-to-one.
(c) Give a function f3 : B A that is one-to-one but not onto.
(d) Give a function f4 : B A that is neither one-to-one nor onto.
2. Consider the following binary relations on the integers: R1 is the empty
relation, R2 is Z Z, and R3 is the set of all pairs (i, j) such that
i j 1. Indicate which of the following properties each relation
satisfies.
R1

R2

R3

reflexive
symmetric
antisymmetric
transitive
3. Let A be the set {1, 2, 3, 4}. Find a smallest relation R on A that is
symmetric, but neither reflexive nor transitive.
4. Let R and S be binary relations on a nonempty set A. For each of
the following properties indicate whether it is preserved under union
and intersection. That is, suppose R and S satisfy property P . Does
R S satisfy P ? Does R S satisfy P ?
Property
reflexive
symmetric
transitive

RS

RS

5. Give definitions of recursive functions as specified below. You may use


the basic list functions, cons, first, rest, and concat, but need to
define any other auxiliary functions.
(a) Write a function desc that takes as argument a list of integers
L and checks whether its elements are in descending order; that
is, each element is greater than the next element. For example,
desc([8,3,2])=true but desc([8,3,2,2])=false.

(b) Write a function sum that takes two arguments, a list of integers L
and an integer k 1, and returns the sum of the first k elements
in L. (If L is empty, the value 0 should be returned. If the
length of L is less than k, the sum of all elements in L should be
returned.)
For example, sum([2,1,3,7],3)=6 and sum([7],3)=7.

You might also like