Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Describe an algorithm that determines whether a function from a finite set of integers to another finite set of integers is onto.

Short Answer

Expert verified

An algorithm that determines whether a function from a finite set of integers to another finite set of integers is onto, can be given as below:

\user1procedure onto fxX=x1,x2,...,xn,y=y1,y2,...,ym:setofintegers

\user1fori:=1 to m

Algorithm will return false if given function is not onto function, otherwise, it will return true.

Step by step solution

01

Steps Algorithm follows

Steps that algorithm has to follow are:

  1. We will use for loop to select element from Y having condition i = 1 to m . Then, use another for loop to select element from X , having condition j = 1 to n .
  2. Then if statement will check that every element in has corresponding element in X . Condition for if loop will befxj=yi .
  3. We use one variable c to count how many elements Y in have corresponding element in X . If there is no corresponding value in X for any element in Y i.e., then algorithm will return false, otherwise it will return true.
02

Step 2:

The algorithm based on above conditions given as below:

\user1 procedure onto_fxX=x1,x2,....,xn,y=y1,y2,...,ym:setofintegers

\user1 fori:=1to m

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Study anywhere. Anytime. Across all devices.

Sign-up for free