Question

(a) Write an algorithm (use pseudo-code) to determine whether a function f ∶ Z100 → Z100...

(a) Write an algorithm (use pseudo-code) to determine whether a function
f ∶ Z100 → Z100 is surjective. That is, supply a “Method” to go with
Input: A function (array) f with f(i) ∈ Z100 for i = 0, 1, . . . , 99.
Output: Boolean B. B=‘true’ if f is surjective, ‘false’ otherwise.
Try to make your algorithm as efficient as possible.
Do NOT include an implementation of your algorithm in a programming language.
(b) How many comparisons does your algorithm perform for a worst case when f is
surjective? Count all tests for =, ≠, < and >. Include all comparisons used, not just
comparisons of function values. For example, remember that each pass of a loop
will require at least one comparison to test whether the exit condition(s) has/have
been met.

Homework Answers

Answer #1

a) We create a set i=0,1,2...99 and another set of possible outputs j=0,1,2...99

We go through each element of the input set and check if its output f(i) lies in the output set. The element is marked as belonging to the output set. And we do this for each f(i). We also count the number elements in the output set that have been marked. IF/When this count reaches 100, we can claim to have a surjective function

b) For each f(i) we have to check if 0<=f(i)<=99 which is 2 comparisons.This is always the case (we always go through all elements of i=0,1,2...99)

So there are a total of 200 comparisons always (2 for each of the 100 elements)

Please do rate this answer positively if you found it helpful. Thanks and have a good day!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The following algorithm finds the initial substring of y that can be reversed and found in...
The following algorithm finds the initial substring of y that can be reversed and found in y. For example, longestInitialReverseSubstringLength(“aabaa”) = 5, because “aabaa” is the same string forwards and backwards, so the longest initial substring that can be reversed and found in the string is “aabaa”. Also, longestInitialReverseSubstringLength(“bbbbababbabbbbb”) is 6, because “babbbb” can be found in the string (see color-highlighted portions of the string), but no longer initial string exists reversed in any part of the string. longestInitialReverseSubstringLength(String y)...
using dr.racket programing language If we write a function that tests whether a list contains only...
using dr.racket programing language If we write a function that tests whether a list contains only strings, odd numbers, or even numbers, you will notice that the code that iterates through the list stays the same, with the only change being the predicate function that checks for the desired list element. If we were to write a new function for each of the tests listed above, it would be more error-prone and an example of bad abstraction. We could write...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Implement the following functions in the given code: def random_suit_number(): def get_card_suit_string_from_number(n): def random_value_number(): def get_card_value_string_from_number(n):...
Implement the following functions in the given code: def random_suit_number(): def get_card_suit_string_from_number(n): def random_value_number(): def get_card_value_string_from_number(n): def is_leap_year(year): def get_letter_grade_version_1(x): def get_letter_grade_version_2(x): def get_letter_grade_version_3(x): Pay careful attention to the three different versions of the number-grade-to-letter-grade functions. Their behaviors are subtly different. Use the function descriptions provided in the code to replace the pass keyword with the necessary code. Remember: Parameters contain values that are passed in by the caller. You will need to make use of the parameters that each...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to the method header that will be a boolean variable: public boolean add(T newEntry, boolean sorted) The modification to the add method will makeit possible toadd new entriesto the beginning of the list, as it does now, but also to add new entries in sorted order. The sorted parameter if set to false will result in the existing functionality being executed (it will add the...
Select the letter (a, b, c,d, e, f) with the most appropriate answer 1) The first...
Select the letter (a, b, c,d, e, f) with the most appropriate answer 1) The first step is to: A) Take care of the worst looking victim first B) Start where you stand C) Stop, look, listen and think D) Conduct voice triage Ans:........ 2) Triage which victim first? A) The worst looking victim B) The worst sounding victim C) The closest victim D) The youngest victim Ans:........ 3) An example of check mental status is: A) Do I remember...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT