0% found this document useful (0 votes)
7 views7 pages

Problem Set 8

This document outlines Problem Set #8 for CS 5002 at Northeastern University, due on November 21, 2024. It consists of five problems, with the first three to be completed individually and the last two in groups, emphasizing the importance of original work and understanding in solving the problems. The problems cover various topics in discrete structures, including functions, equivalence relations, and programming tasks.

Uploaded by

chen.sizhi
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)
7 views7 pages

Problem Set 8

This document outlines Problem Set #8 for CS 5002 at Northeastern University, due on November 21, 2024. It consists of five problems, with the first three to be completed individually and the last two in groups, emphasizing the importance of original work and understanding in solving the problems. The problems cover various topics in discrete structures, including functions, equivalence relations, and programming tasks.

Uploaded by

chen.sizhi
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/ 7

Northeastern University

CS 5002 – Discrete Structures


Spring 2024 Semester, Timothy Edmunds

Problem Set #8

This Problem Set is due at 11:59 pm Pacific time on 2024-11-21, and will be submitted on Canvas.

This Problem Set is worth 6% of the final course grade. There are five problems.

Problems #1 and #2 and #3 are to be completed individually, while Problems #4 and #5 are to
be completed in your assigned small groups.

Please type (or neatly handwrite) your solutions on standard 8.5 × 11 (or A4) paper, with your name(s)
at the top of each solution. Ensure that you submit five separate PDF files on Canvas, one for each
problem. Make sure you label your Problem Set #1 submissions appropriately - e.g. timothy-1-1.pdf,
timothy-1-2.pdf, timothy-1-3.pdf, timothy-1-4.pdf, timothy-1-5.pdf.

Given that the last two problems are done in a group, your final two PDF files will be identical to
some of your classmates. (For example, timothy-4.pdf might be identical to yvonne1-4.pdf and bethany1-
4.pdf). This is completely fine, and enables you to have a record of all of your submitted work in this
course.

While a solution must be absolutely perfect to receive full marks, I will be generous in awarding partial
marks for incomplete solutions that demonstrate progress.

So that there is no ambiguity, there are two non-negotiable rules. A violation of either rule constitutes
plagiarism and will result in you receiving an F for this course.

(a) If you meet with a classmate to discuss one of the Problems, the articulation of your thought process
(i.e., what you submit to me), must be an individual activity, done in your own words, away from
others. Please remember that the solution-writing process is where so much of your learning will
occur in this course - even more than the time you spend on solving the problems. Do not be
surprised if it takes you 3 to 5 times as long to write up a solution as it takes you to actually solve
the problem.

(b) This Problem Set has been designed to be challenging, because struggling through problems is how
we learn best. When stuck on a problem, it can be helpful to get a small hint that will allow you to
make some progress without robbing you of the opportunity to solve the problem. Online searches,
and even well-intentioned classmates, may be unable to provide you with just a small insight. If
you need support/a small hint, the best plan is to post your query on the Canvas discussion forum.
I will be readily available during office hours, or by appointment.
CS 5002, Spring 2024 Semester, Timothy Edmunds – Problem Set #8 2

Problem #1 – INDIVIDUAL
In each of the functions below, the domain is the set of Northeastern Align students enrolled in CS 5002
this semester, with several hundred students affiliated with one of the Northeastern regional campuses
(Vancouver, Seattle, Boston, Oakland, Silicon Valley, Portland, Arlington, Miami, and Online).

(a) Let f be the function that maps each student to a Northeastern ID number.

For example, f (Chen) = NU123456.


The co-domain of f is the set of ID numbers between NU000000 and NU999999.

(b) Let g be the function that maps each student to a Northeastern campus.

For example, g(Chen) = Vancouver.


The co-domain of g is the following campuses: {Vancouver, Seattle, Boston, Oakland, Silicon Val-
ley, Portland, Arlington, Miami, Online}.

(c) Let h be the function that maps each student to a CS 5002 instructor.

For example, h(Chen) = Timothy Edmunds.


The co-domain of h is the set of all Northeastern Computer Science professors.

For each of these three functions, determine whether the function is bijective, injective but not surjective,
surjective but not injective, or neither injective nor surjective.

Clearly justify your answers.


CS 5002, Spring 2024 Semester, Timothy Edmunds – Problem Set #8 3

Problem #2 – INDIVIDUAL
Let f : X → Y be a function with domain X and co-domain Y .

If f is bijective (i.e., invertible), then there exists a function g : Y → X for which the following property
holds: f (x) = y ⇔ g(y) = x.

The function g is called the inverse of f , and is written as f −1 .

By definition, f (f −1 (y)) = y and f −1 (f (x)) = x for all x ∈ X and y ∈ Y .

9x
(a) Let f (x) = + 32. Determine f −1 (x). Show your steps.
5

(b) We say that a function is an involution if f −1 (x) = f (x). In other words, f is its own inverse. Show
that the following functions are all involutions:
100 2x − 3
f (x) = −x, f (x) = , f (x) = .
x x−2

(c) Define f n+1 (x) = f (f n (x)) for all n ≥ 1. Thus, f 2 (x) = f (f (x)) and f 3 (x) = f (f (f (x))).
2x − 3
If f (x) = , determine the value of f 2024 (2024). Clearly justify your answer.
x−2
CS 5002, Spring 2024 Semester, Timothy Edmunds – Problem Set #8 4

Problem #3 – INDIVIDUAL
Let S be the set of squares on an 8 by 8 chessboard.

Each element of S is an ordered pair (x, y), where 1 ≤ x ≤ 8 is the x-coordinate and 1 ≤ y ≤ 8 is the
y-coordinate. The bottom-left corner square is (1, 1) and the top-right corner square is (8, 8).

There are numerous relations R : S → S, relating the elements of S to itself. For example, consider
the relation (x1 , y1 ) R (x2 , y2 ) ⇔ |x1 − x2 | + |y1 − y2 | = 1. Convince yourself that for this relation R, two
chessboard squares are related precisely when they share a common side.

You can show that R is not reflexive, R is symmetric, and R is not transitive. Therefore, R is not
an equivalence relation.

For each of the following relations R : S → S, prove that R is indeed an equivalence relation. Then
determine the total number of equivalence classes of R, clearly justifying your answer.

(a) (x1 , y1 ) R (x2 , y2 ) ⇔ x1 = x2 .

(b) (x1 , y1 ) R (x2 , y2 ) ⇔ (x1 − x2 ) + (y1 − y2 ) is even.

(c) (x1 , y1 ) R (x2 , y2 ) ⇔ x1 + y2 = x2 + y1 .


CS 5002, Spring 2024 Semester, Timothy Edmunds – Problem Set #8 5

Problem #4 – GROUP
Let S = {0, 1, 2, . . . , n − 1} be the set of the first n non-negative integers, and let R : S → S be a relation
from S to S.

In this problem, you will create a Python program to determine whether R is an equivalence relation.

If R is indeed an equivalence relation (i.e., it is reflexive, symmetric, and transitive), your program
will also determine the total number of equivalence classes.

Go to the interactive Python notebook at https://mybinder.org/v2/gh/thetedmunds/CS-5002-handouts/


HEAD?labpath=Problem%20Set%208%20-%20Equivalence%20Relations.ipynb. This is the Python pro-
gram that you will complete for this problem. You can edit and run the notebook on the web then
download it when complete, or you can download it and work on it in the development environment of
your choice. For this problem all you need to do is submit your completed .ipynb file.

This Python program contains a function called BuildM atrix(R, n), which accepts a relation R and
a positive integer n, and outputs an n by n matrix M , where the M [x][y] entry (namely the entry in row
x and column y) equals 1 if x R y, and is equal to 0 otherwise.

Each relation R accepts two integers from set S, called x and y, and returns 1 if x R y and returns
0 otherwise. In this context, 1=True and 0=False. For example, the relation R1 below is defined as
follows: x and y are related if and only if their difference x − y is even. (Thus, x R1 y ⇔ (x − y) %2 = 0.)
def R1(x,y):
if (x-y) % 2 == 0: return 1
else: return 0
You can convince yourself that R1 is an equivalence relation, and that there are exactly two equivalence
classes: odd integers and even integers.

(a) Each relation R is either reflexive or not reflexive, symmetric or not symmetric, transitive or not
transitive. Define a relation R for each of these 2 × 2 × 2 = 8 different options. You will call these
relations R1 , R2 , R3 , R4 , R5 , R6 , R7 , R8 . The first two relations have been provided for you. You are
welcome to use these, or replace them with your own.

(b) Complete the implementation of the function EquivalenceT est(R, n) to determine whether R is re-
flexive or not reflexive, symmetric or not symmetric, transitive or not transitive. Use “comments”
in your code to explain how and why your code is correct.

(c) If R is an equivalence relation, output the total number of equivalence classes. Briefly add com-
ments in your code to explain how your code determines the total number of equivalence classes.

For example, the output for the above relation R1 should look something like this:

This relation is reflexive


This relation is symmetric
This relation is transitive
This relation is an equivalence relation and has 2 equivalence classes.
CS 5002, Spring 2024 Semester, Timothy Edmunds – Problem Set #8 6

Problem #5 – GROUP
There are n people standing around in a circle. Rachel, who is not one of the n players, goes around the
circle clockwise and taps the head of every second person still standing. As soon as a player has their
head tapped, that person sits down. Rachel keeps going around the circle until only one person is left
standing, and that person is declared the winner.

For example, if there are n = 9 players, then Rachel taps players 2, 4, 6, 8 on her first trip around
the circle. Then in her next trip around the circle, she taps players 1, 5, 9. Finally, in her last trip around
the circle she taps player 7. Thus, player 3 is the winner.

For each integer n, let f (n) denote the position number of the winning player when the game consists of
n players. For example, f (9) = 3.

(a) For each n satisfying 1 ≤ n ≤ 15, determine the value of f (n).

n 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
f (n) 3

No proof is necessary. You will get full points for producing the correct table.

(b) Let N be the set of positive integers. Determine whether the function f : N → N is injective
and/or surjective. Clearly justify your answers.

(Hint: for each integer k, there is a simple relationship between f (k) and f (2k), as well as a
simple relationship between f (k) and f (2k + 1). What is that relationship, and can you prove it?)

(c) Suppose there are n = 2024 people around the circle, with you being player t. Determine the value
of t that ensures you win this game.
CS 5002, Spring 2024 Semester, Timothy Edmunds – Problem Set #8 7

(d) (OPTIONAL BONUS) When Richard was in elementary school (in the mid-1980s), he played
a hand-slapping game called Stella Ella Ola with his classmates. They sang a song together and
went clockwise around a circle slapping hands for each syllable.

Richard played this game every single day, so he still remembers the words 35 years later!

stella ella ola, clap, clap, clap,


say es chico, chico, chico, chico, chack, chack
say es chico, chico, vello, vello, vello, vello, vello, go
one, two, three, four, five!

When the song ended, the person whose hand was slapped was eliminated from the game.

The game continued with the next person (to the left of the eliminated player) beginning the
song again.1

To see this game in action, check out this 40-second YouTube clip.
https://www.youtube.com/watch?v=KBBWtaXEHhU

Notice how the Stella Ella Ola game is identical to the game presented in parts (a) to (c) above,
except that we eliminate every 34th person instead of every 2nd person.

Write a Python program that solves this game. Your program will input two variables: n (number
of players) and m (number of syllables in the song), and output the value of f (n, m), the position
number of the winning player.

In your Python program, clearly explain HOW and WHY your code returns the correct value
of f (n, m).

p.s. If you know of any 7-year-olds who play Stella Ella Ola at their school, you can give them
your Python program and they will be able to figure out how to win every single time!

1
Regional Variant Alert! The lyrics Timothy remembers from his childhood are:
stella ella ola, clack, clack, clack,
singing, “yes chico-chico, chico-chico-chack-chack”
“yes chico-chico, fallo, fallo, fallo-fallo, fallo-va”
one, two, three, four, ...
You would call out what number to count up to before starting.
Also, you could avoid being “slapped out” if you yanked your hand away just in time. But these rules add more complication
than is necessary for our purposes.

You might also like