CMP337
Sample Questions for Midterm Exam 2
Each question counts 4 points
- What
is a binary relation from X to Y?
- Define
a symmetric relation and give an example.
- Define
partial order and give an example.
- Write
the relation R as a table, where R is defined by (x,y) in R if x2
> y
- List
the elements of the following relations R on the set {1,2,3,4,5}
- (x,y) in R if 3 divides x-y.
- (x,y)
in R if 3 divides x+y.
- Show
that the relation R on the set of all positive integers defined by (x,y)
in R if 3 divides x-y is a partial order
- What
is an equivalence relation?
- Suppose
that R is an equivalence relation over a set X and that [a] = { b | bRa }.
Show that the set S = { [a] | a in S } is a partition of X.
- Is the
relation {(1,1), (2,2), (3,3), (4,4), (5,5), (1,3), (3,1) } an equivalence
relation?
- Which
of the following relations are functions?
- {
(1,a), (2,a), (3,a), (4,a) }
- {
(1,c), (2,a), (3,b), (4,c), (2,d)}
- {
(x,y) | y = x2 }
- {
(x,y) | x = y2 }
- What
is the domain of a function from X to Y?
- How is the modulus operator used to
define a hash function?
- Draw
the arrow diagram for the function f: { (x,a), (y,c), (z,a), (w,d) }.
- Which of the following functions is injective?
- f(x) = x2, where domain(f) = positive
and negative real numbers
- f(x) = x3, where domain(f) = positive
and negative real numbers
- f(x) = x mod 5, where domain(f) = positive integers
- f(x)
= floor(x), where domain(f) = positive real numbers
- Let X={1,2,…,10}.
Define a relation R on X x X by (a,b)R(c,d) if ad=bc. Show
that R is an equivalence relation.
- Let f
(n) = n2 and g (n) = 2n. What is f°g?
- Let f be a function
from X to Y and g be a function from Y to Z. Is it true or false that if f and g are
both onto (surjective), then so is f°g? Explain why or why not.
- Write
an algorithm to multiply two numbers, digit by digit, as is taught in
elementary school.
- Trace
the Euclidean algorithm with inputs 110, 273.
- Write
an algorithm to tile a “deficient” board with 2n squares on a
side with right trominoes.
- Select
a theta notation for each of the following functions:
- 6n+1
- (6n+1)2
- 1 +
2 + 3 + … + n
- 2 lg
n + 4
- How
many times is the statement x:=x+1 executed in the following code:
for i:= 1 to n
for j := 1 to n
for k := 1 to n
x := x+1
Explain why.
- Suppose
that you have a deck of 52 cards, with 4 suits and denominations
2,…,10,J,Q,K,A
- How
many ways can you order the cards?
- How
many ways can you pick a 5-card hand from the deck?
- How
many 5 card hands include either the ace of spades or the king of hearts?
- Suppose
we ignore suit – how many ways are there to pick a 4-card hand?
- Consider the set of letters { U, V, W, X, Y, Z }
- How
many 5-letter strings can you make with these letters, with no
repetitions?
- How
many 5-letter strings can you make with these letters, with repetitions?
- How
many 12-letter strings have 4 U’s, 3 V’s, and 2 W’s?
- How
many ways can you pick sets of 5 letters from this string consisting only
of U’s, V’s, and W’s?
- Show
by induction that the tromino (or Euclidean) algorithm works.