0% found this document useful (0 votes)
37 views4 pages

Assign2 23s1 Qns

Uploaded by

sikka.arshin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views4 pages

Assign2 23s1 Qns

Uploaded by

sikka.arshin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CS1231S Assignment #2

AY2023/24 Semester 2
Deadline: Monday, 6 November 2023, 1:00pm

IMPORTANT: Please read the instructions below


This is a graded assignment worth 10% of your final grade. There are seven questions (“question” 0 and six
problem-solving questions) with a total score of 40 marks. Please work on it by yourself, not in a group or in
collaboration with anybody. Anyone found committing plagiarism (submitting other’s work as your own), or
sending your answers to others, or other forms of academic dishonesty will be penalised with a straight zero
for the assignment, and possibly an F grade for the module. Please see SoC website “Preventing Plagiarism”
https://www.comp.nus.edu.sg/cug/plagiarism/.
You are to submit your assignment to Canvas > Assignments before the deadline.
Your answers may be typed or handwritten. Make sure that it is legible (for example, don’t use very light
pencil or ink if it is handwritten, or font size smaller than 11 if it is typed) or marks may be deducted.
You are to submit a SINGLE pdf file, where each page is A4 size. Do not submit files in other formats. If you
submit multiple files, only the last submitted file will be graded.
Late submission will NOT be accepted. We will set the closing time of the submission folders to slightly later
than 1pm to give you a few minutes of grace, but in your mind, you should treat 1pm as the deadline. If you
think you might be too busy on the day of the deadline, please submit earlier. Also, avoid submitting in the
last minute; the system may get sluggish due to overload and you will miss the deadline.
Note the following as well:
▪ Name your pdf file with your Student Number. Your student number begins with ‘A’ (eg: A0234567X).
(Do not mix up your student number with your NUSNET-id which begins with ‘e’.)
▪ At the top of the first page of your submission, write your Name and Tutorial Group.
▪ To keep the submitted file short, please submit your answers without including the questions.
▪ As this is an assignment given well ahead of time, we expect you to work on it early. You should
submit polished work, not answers that are untidy or appear to have been done in a hurry, for
example, with scribbling and cancellation all over the places. Marks may be deducted for untidy work.
▪ It is always good to be clear and leave no gap so that the marker does not need to make guesswork
on your answer. When in doubt, the marker would usually not award the mark.
▪ Do not use any methods that have not been covered in class. When using a theorem or result that
has appeared in class (lectures or tutorials), please quote the theorem number/name, the lecture
and slide number, or the tutorial number and question number in that tutorial, failing which marks
may be deducted. Remember to use numbering and give justification for important steps in your
proof, or marks may be deducted.
To combine all pages into a single pdf document for submission, you may find the following scanning apps
helpful if you intend to scan your handwritten answers:
* for Android: https://fossbytes.com/best-android-scanner-apps/
* for iphone:
https://www.switchingtomac.com/tutorials/ios-tutorials/the-best-ios-scanner-apps-to-scan-documents-
images/
If you need any clarification about this assignment, please do NOT email us or post on telegram, but
post on the Canvas > Discussions> Assignments forum or on QnA “Assignment” topic so that
everybody can read the answers to the queries.

Page 1 of 4
Question 0. (Total: 2 marks)
Check that …
▪ you have submitted a pdf file with your Student Number as the filename. [1 mark]
▪ you have written both your name and tutorial group number (eg: T02) at the top of the
first page of your file. (If you miss either one you will not be given any mark.) [1 mark]

Question 1. (Total: 6 marks)


The following definitions were given in tutorial 6:
Given a function 𝑓: 𝐴 → 𝐵, we say that
▪ 𝑔: 𝐵 → 𝐴 is a left inverse of 𝑓 if and only if 𝑔(𝑓(𝑎)) = 𝑎 for all 𝑎 ∈ 𝐴.
▪ ℎ: 𝐵 → 𝐴 is a right inverse of 𝑓 if and only if 𝑓(ℎ(𝑏)) = 𝑏 for all 𝑏 ∈ 𝐵.

Define the function 𝑓 ∶ ℤ → ℤ as follows:


0, 3 ∤ (𝑥 − 2)
𝑓(𝑥) = {
(𝑥 − 2)/3, 3 | (𝑥 − 2)
(a) Find 𝑓 −1 ({0}). (2 marks)
(b) Does 𝑓 have a left inverse? If yes, find it. If not, prove that it does not have one. (2 marks)
(c) Does 𝑓 have a right inverse? If yes, find it. If not, prove that it does not have one. (2 marks)
Hint: You may use the following facts:
▪ (Fact 1) A function is injective if and only if it has a left inverse.
▪ (Fact 2) A function is surjective if and only if it has a right inverse.

Question 2. (Total: 6 marks)


Prove or disprove the following statements:
(a) Define an injective function 𝑓 ∶ {0} → {−1,1} such that 𝑓(0) = 1.
There exists a function 𝑔 ∶ {−1,1} → 𝐶 such that 𝑔 is not injective but 𝑔 ∘ 𝑓 is injective.
(3 marks)
(b) For all injective functions 𝑓 ∶ 𝐴 → 𝐵, there exists a function 𝑔 ∶ 𝐵 → 𝐶 such that
𝑔 is not injective but 𝑔 ∘ 𝑓 is injective. (3 marks)

Question 3. (Total: 6 marks)


Consider the Fibonacci function 𝐹 ∶ ℕ → ℕ defined as follows:
𝐹(0) = 0; 𝐹(1) = 1; 𝐹(𝑛 + 1) = 𝐹(𝑛) + 𝐹(𝑛 − 1), 𝑛 ≥ 1.
This function takes time exponential to its input to compute. Aiken told you that there is a more
efficient recursive solution that can compute two Fibonacci values in linear time.
𝐻 ∶ℕ×ℕ→ℕ×ℕ
𝐻((𝑎, 𝑏)) = (𝑏, 𝑎 + 𝑏)
𝐹2 ∶ ℕ → ℕ × ℕ
𝐹2(0) = (0,1)
𝐹2(𝑛) = 𝐻(𝐹2(𝑛 − 1)), if 𝑛 > 0.
Use mathematical induction to prove that 𝐹2 is in fact related to 𝐹 by the following:
𝐹2(𝑛) = (𝐹(𝑛), 𝐹(𝑛 + 1)) ∀𝑛 ∈ ℕ
You are to state your inductive hypothesis in your proof.
Page 2 of 4
Question 4. (Total: 6 marks)
The Aiken Dueet balloon shop sells balloons with five different colours.
(Do not just write the final answers. Show your workings as well.)
(a) If the shop has at least 20 of each colour in its stock, how many combinations of 20 balloons
can you choose? (1 mark)
(b) If the shop has only 5 red balloons but has at least 20 of each of the other colours, how many
combinations of 20 balloons can you choose? (2 marks)
(c) If the shop has only 5 red balloons and 5 green balloons but has at least 20 of each of the other
colours, how many combinations of 20 balloons can you choose? (3 marks)

Question 5. (Total: 7 marks)


A language 𝐿 is defined over an alphabet Σ = {𝑎, 𝑏, 𝑐}. A string is a sequence of symbols where
ordering matters (i.e. “𝑎𝑏𝑐” is not equal to “𝑏𝑐𝑎”). The length of a string is the number of symbols
the string contains. For example, “𝑎𝑏𝑐” has length 3.
(a) How many strings of length 4 are there? (1 mark)
(b) How many strings of length 4 do not have consecutive symbols being the same? (1 mark)
(c) Let 𝐴, 𝐵 be sets and the universal set 𝑈 = 𝐴 ∪ 𝐵. Prove that |𝐵| − |𝐴 ∩ 𝐵| = |𝐴̅ ∩ 𝐵|. Justify
your steps. You may skip commutative laws. (Do not use diagram to prove!) (2 marks)
(d) How many strings of length 4 contain neither “𝑐𝑎𝑏” nor “𝑏𝑎𝑐”, or do not have consecutive
symbols being the same? Working is expected for this question. (3 marks)

Question 6. (Total: 7 marks)


You are to explain or show the working of your answers.
(a) A pack of card consists of 52 cards with 4 suits: spades (), hearts (), diamonds () and clubs
(). Each suit has 13 cards: 2, 3, 4, 5, 6, 7, 8, 9, Ten, Jack, Queen, King and Ace.
If we draw three cards at random without replacement from a pack of cards, what is the
probability that they are of the same suit? Write your answer as a fraction in its lowest terms.
(A fraction in its lowest terms is a fraction whose numerator and denominator are relatively
prime, that is, they have no common positive divisors other than 1.) (2 marks)
(b) Given a list of integers from 1 to 1000 inclusive, if you pick 𝑘 numbers from this list, what is the
smallest 𝑘 so that no matter which 𝑘 numbers you pick from this list, it would guarantee that
they contain 3 consecutive numbers? You are to explain your answer by defining your
pigeonholes. (2 marks)

Page 3 of 4
(c) How many positive integers not exceeding 2000 are multiples of 3 as well as multiples of either
4 or 5? (Do not list out all these integers exhaustively!) (3 marks)
You may use the following fact without proof:
Given positive integers 𝑥 and 𝑦, the number of integers that are multiples of both 𝑥
and 𝑦 is the number of integers that are multiples of the lowest common multiplier
of 𝑥 and 𝑦.
Definition: The lowest common multiplier (or least common multiplier) of two integers 𝑎 and
𝑏, denoted 𝑙𝑐𝑚(𝑎, 𝑏), is the smallest positive integer that is divisible by both 𝑎 and 𝑏.
Important steps in your working should be justified.

=== End of paper ===

Page 4 of 4

You might also like