Test #1 Review – Rivka Ligier Section 3.1 Ex: 24

Question: Describe an algorithm that determines whether a function from a finite set to another finite set is one-to-one

Code/Algorithm:

Procedure one-to-one([A=(a1,a2,a3, …], [B= b1, b2, b3 …] : integers)

for i = 1 to m
k = 0 (counter variable)
for j = 1 to n
if Aj = Bi then k = k+1
if k ==! (doesn’t equal) 1 then return false
if k = 1 then return true

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *