Discrete Mathematics and Its Applications, Seventh Edition

Published by McGraw-Hill Education
ISBN 10: 0073383090
ISBN 13: 978-0-07338-309-5

Chapter 3 - Section 3.1 - Algorithms - Exercises - Page 203: 24

Answer

procedure onetoone $(x1,x2,x3,...xn,y1,y2,y3,...ym: $the domain and co-domain of some function $f(x),$ respectively$)$ Define a new set representing $m$ boolean values such that $b_i$ is true if and only if for some $x_α,f(x_α)=y_i$. {Initially, all $b_i:=$ false} count $:=0$ for $i:=1$ to $n$ $\space\space\space$curvalue $:=f(x_i)$ $\space\space\space$ if $b_{curvalue}$ is false then $b_{curvalue}:=$ true $\space\space\space$ else count $:= $ count + $1$ {This constitutes a violation of being one-to-one; count checks how many such violations occur} if count is not $0$ then return true else return false {true and false here refer to the status of function as one-to-one}

Work Step by Step

This algorithm attempts to evaluate if a function is one-to-one or not. For a function to be one-to-one, each value of $x$ should map to a unique value of $y$ such that no two $x$ values map to the same $y$ value. It does this by checking if for two different $x$ values, we get the same value $y$. If we've encountered this value of $y$ before, we increment one to count (indicating that we have found a violation) Note that we could terminate the algorithm as soon as such a violation occurred but this algorithm counts how many such violations occur.
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.