0% found this document useful (0 votes)
34 views2 pages

CSE/ISE 215 Foundations of Computer Science Solutions For Sample Exam Problems III

This document contains sample exam problems and solutions for a foundations of computer science course. It includes questions about functions between sets, binary relations, constructing the smallest symmetric but not reflexive or transitive relation on a set, properties preserved under union and intersection of relations, and defining recursive functions to check if a list is in descending order and to sum the first k elements of a list.

Uploaded by

Max
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

CSE/ISE 215 Foundations of Computer Science Solutions For Sample Exam Problems III

This document contains sample exam problems and solutions for a foundations of computer science course. It includes questions about functions between sets, binary relations, constructing the smallest symmetric but not reflexive or transitive relation on a set, properties preserved under union and intersection of relations, and defining recursive functions to check if a list is in descending order and to sum the first k elements of a list.

Uploaded by

Max
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CSE/ISE 215 Foundations of Computer Science

Solutions for Sample Exam Problems III

1. Let A be the set {1, 3, 5, 7, 9} and B the set {0, 1, 2, 5}.


(a) Give a function from A to B that is one-to-one but not onto:
Since A is a finite set with more more elements than B there is no
one-to-one function from A to B (cf. the Pigeonhole Principle).
(b) Give a function f : A B that is onto but not one-to-one: Define
f by f (1) = f (3) = 0, f (5) = 1, f (7) = 2, and f (9) = 5.
(c) Give a function g : B A that is one-to-one but not onto: Define
g by g(0) = 1, g(1) = 3, g(2) = 5, and g(5) = 7.
(d) Give a function h : B A that is neither one-to-one nor onto:
Define h by h(0) = h(1) = h(2) = h(5) = 1.
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 of integers (i, j)
such that i j 1. Indicate which of the following properties each
relation satisfies.
R1
reflexive
symmetric
antisymmetric
transitive

x
x
x

R2
x
x

R3

Note that R3 does not contain the pair (0, 0).


3. Let A be the set {1, 2, 3, 4}. We construct a smallest relation R on A
that is symmetric, but neither reflexive nor transitive.
If R is not transitive it must contain two pairs (x, y) and (y, z), but
not (x, z). Suppose R contains (1, 2) and (2, 3). By symmetry, R must
also contain the two pairs (2, 1) and (3, 2). This relation,
R = {(1, 2), (2, 1), (2, 3), (3, 2)},
is symmetric but neither reflexive nor transitive. It is a smallest such
relation as no subset of R meets the stated conditions.
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
Yes
Yes
Yes

RS
Yes
Yes
No

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.
The definition is by recursion on the list argument:
i. If L = nil then desc(L) = true.
ii. If L 6= nil and rest(L) = nil, then desc(L) = true.
iii. If L =
6 nil, rest(L) 6= nil, and f irst(L) f irst(rest(L)),
then desc(L) = f alse.
iv. If L 6= nil, rest(L) 6= nil, and f irst(L) > f irst(rest(L)),
then desc(L) = desc(rest(L)).
(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.
There several cases:
i. If L = nil then sum(L, k) = 0.
ii. If L 6= nil and rest(L) = nil, then sum(L, k) = f irst(L).
iii. If L =
6 nil, rest(L) 6= nil), and k = 1, then sum(L, k) =
f irst(L).
iv. If L 6= nil, rest(L) 6= nil), and k > 1, then sum(L, k) =
f irst(L) + sum(rest(L), k 1).

You might also like