Math for CS: Chapter 7 Review

Functions: One-to-One, Onto, and Definitions

Question 1

Define the two strict requirements for a relation \(R\) from set \(A\) to set \(B\) to be considered a function \(f: A \to B\).

Answer 1

  1. Existence: Every element \(a \in A\) must be mapped to at least one element in \(B\).
  2. Uniqueness: Every element \(a \in A\) must be mapped to exactly one element in \(B\) (no “one-to-many” mappings).

Question 2

Consider the set \(A = \{1, 2, 3\}\) and \(B = \{x, y\}\). Is the relation \(f = \{(1, x), (2, y)\}\) a function from \(A\) to \(B\)? Why or why not?

Answer 2

No. It fails the existence requirement. The element \(3 \in A\) does not have a corresponding image in \(B\).

Question 3

State the formal definition of a One-to-One (Injective) function using logic notation.

Answer 3

A function \(f: A \to B\) is injective if: \[\forall a_1, a_2 \in A, f(a_1) = f(a_2) \implies a_1 = a_2\] Alternatively: Distinct inputs must yield distinct outputs.

Question 4

Let \(f: \mathbb{Z} \to \mathbb{Z}\) be defined by \(f(n) = n^2\). Is this function one-to-one?

Answer 4

No. Counterexample: \(f(2) = 4\) and \(f(-2) = 4\). Since \(f(2) = f(-2)\) but \(2 \neq -2\), it is not injective.

Question 5

What is the formal definition of an Onto (Surjective) function?

Answer 5

A function \(f: A \to B\) is surjective if: \[\forall b \in B, \exists a \in A \text{ s.t. } f(a) = b\] In plain English: The Range is equal to the Codomain.

Question 6

Let \(f: \mathbb{R} \to \mathbb{R}\) be defined by \(f(x) = x + 5\). Is this function onto?

Answer 6

Yes. To prove it, pick any \(y \in \mathbb{R}\) (the codomain). We need an \(x\) such that \(x + 5 = y\). Solving for \(x\) gives \(x = y - 5\). Since \(y - 5\) is always a real number, every \(y\) has a pre-image.

Question 7

If a function is both one-to-one and onto, what is it called?

Answer 7

A Bijection (or a one-to-one correspondence). Bijections are the only functions that have a well-defined inverse function \(f^{-1}\).

Question 8

If \(|A| = 5\) and \(|B| = 3\), can there exist an injective function \(f: A \to B\)?

Answer 8

No. By the Pigeonhole Principle, if you try to map 5 items into 3 slots, at least one slot must contain more than one item. Therefore, at least two elements in \(A\) must map to the same element in \(B\).

Question 9

If \(|A| = 3\) and \(|B| = 5\), can there exist a surjective function \(f: A \to B\)?

Answer 9

No. There are not enough elements in the domain to “cover” every element in the codomain. At least 2 elements in \(B\) will be left without a pre-image.

Question 10

Consider the Python function below. In mathematical terms, what is the Domain of this function?

def reciprocal(n):
    if n != 0:
        return 1/n

Answer 10

The domain is \(\mathbb{R} \setminus \{0\}\) (all real numbers except zero), or more specifically in CS terms, all non-zero floats.

Question 11

What is the horizontal line test used for in coordinate geometry?

Answer 11

It determines if a function is one-to-one. If any horizontal line intersects the graph more than once, the function is not injective because multiple \(x\)-values produce the same \(y\)-value.

Question 12

Let \(A = \{1, 2, 3\}\) and \(B = \{a, b, c\}\). How many total functions are possible from \(A\) to \(B\)?

Answer 12

For each of the 3 elements in \(A\), there are 3 choices in \(B\). \[|B|^{|A|} = 3^3 = 27 \text{ functions}\]

Question 13

True or False: Every function is a relation, but not every relation is a function.

Answer 13

True. A relation is simply any set of ordered pairs. A function is a specific type of relation that obeys the existence and uniqueness rules.

Question 14

Determine if \(f(n) = 2n\) is a bijection from \(\mathbb{Z} \to \mathbb{Z}\).

Answer 14

No. It is one-to-one, but it is not onto. The codomain is all integers, but the range is only even integers. There is no integer \(n\) such that \(2n = 3\).

Question 15

What is the composition \((g \circ f)(x)\) if \(f(x) = x^2\) and \(g(x) = x + 1\)?

Answer 15

\[(g \circ f)(x) = g(f(x)) = g(x^2) = x^2 + 1\]