Discrete Mathematics with Applications 4th Edition

Published by Cengage Learning
ISBN 10: 0-49539-132-8
ISBN 13: 978-0-49539-132-6

Chapter 7 - Functions - Exercise Set 7.2 - Page 416: 58

Answer

See explanation

Work Step by Step

Below is a simple algorithmic approach to check **surjectivity** (onto property) of a function \(f\) whose domain and codomain are both finite. We assume: - The domain is a finite set \(X = \{x_1, x_2, \dots, x_m\}\). - The codomain is a finite set \(Y = \{y_1, y_2, \dots, y_n\}\). - We have access to a procedure \(\mathrm{Compute}(f,x)\) that returns \(f(x)\) for any \(x \in X\). --- ## Idea of the Algorithm A function \(f\) is **onto** if **every element** of \(Y\) has at least one preimage in \(X\). Equivalently, as you evaluate \(f(x)\) for all \(x \in X\), you must produce **every** element of \(Y\) at least once. ### Pseudocode ``` Algorithm IsOnto(f, X, Y): 1. Create an empty set S to store images of f. 2. For each element x in X (the domain): a. y ← Compute(f, x) // Get the image of x under f b. Add y to S 3. // After processing all x, check if S covers Y: 4. If S contains all elements of Y: return "f IS onto" Else: return "f is NOT onto" ``` ### Explanation 1. **Initialize a set \(S\)** to keep track of values (in \(Y\)) that we have seen so far. 2. **Loop** over each element \(x\) in the domain \(X\). - Compute \(f(x)\). - Insert \(f(x)\) into \(S\). 3. **After** visiting every \(x \in X\), check if \(S\) contains all elements of \(Y\). - If yes, then for every \(y \in Y\), there is an \(x\) with \(f(x) = y\). Hence \(f\) is onto. - If no, then at least one \(y \in Y\) is missing, so \(f\) is not onto. --- ## Complexity - We make **one pass** over all elements of the domain \(X\). - Each pass involves: 1. **Computing** \(f(x)\) (done by the existing procedure). 2. **Inserting** \(f(x)\) into a data structure \(S\). - Finally, we check whether \(S\) contains all elements of \(Y\). If we use an efficient data structure (like a hash set) for \(S\), insertion and membership checks can be done in \(O(1)\) average time, making the overall process \(O(m + n)\) where \(m=|X|\) and \(n=|Y|\). Either way, since the sets are finite, this procedure will definitively determine whether \(f\) is onto.
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.