CS计算机代考程序代写 algorithm Question 1 [10 marks]

Question 1 [10 marks]

Students enrolled in CSC263 connect to the synchronous lecture from many time zones. Consider
the following algorithm which takes 3 students from the Zoom attendees’ list 1 and gives away smart
watches based on their time zone compatibility:

def TimeZoneGiveaway(s1,s2,s3):
1. watches = 3 # we order extra just in case some get lost in the mail
2. t1,t2,t3 = getTimZone(s1), getTimZone(s2), getTimZone(s3)
3. if t1 == t2 == t3:
4. for i in range(1:125): #both range bounds are inclusive
5. print “everyone enrolled in CSC263 gets a smart watch :)”
6. watches = watches + 1
7. return watches
8. else if t2 == t3:
9. for i in range(1:10): #both range bounds are inclusive
10. print “a few get a smart watch :|”
11. watches = watches + 1
12. return watches
13. print “no one gets a watch… just extra homework :(”
14. return watches

To simplify comparisons, getTimZone(s) returns an integer from the range {1, 2, …,m}, where 1
refers to the EST time zone, 2 to MST, 3 to PST etc. Note that m is the number of time zones
represented by the class (and not the number of the time zones in the world). The actual mapping
of time zones to integers does not matter in this question, just that you are guaranteed there is m of
them for some m ≥ 1. You can assume that the probability of a student being in a certain time zone is
random, uniformly distributed, and independent from any other events (this simplification is not true
in practise but it’s ok for our problem set).

We are interested in evaluating the number of times a print statement is executed. The “best
case” here means the case with the smallest number of print statements executed (rather than the
smallest or largest number of watches given away). Similarly, the “worst case” means the case with
the largest number of print statements executed rather than extra homework given. Answer the
following questions and provide sufficient justification (no partial marks will be given to solutions
without justification):

1. In the worst case, how many lines are printed by TimeZoneGiveaway and how many watches
are returned? Justify your answer.

2. What is the probability that the worst case occurs? Justify carefully.

3. In the best case, how many lines are printed by TimeZoneGiveaway and how many watches
are returned? Justify your answer.

4. What is the probability that the best case occurs? Justify carefully.

5. What is the expected return value (number of watches) of TimeZoneGiveaway? Give a
detailed analysis based on the probability distribution described above. Make sure to state the
random variable you use and to simplify your final answer. When applicable, write P using the
the probability mass function convention from Week 2 Module.

6. How many time zones (i.e. m) should there be in total so that the expected number of watches
to be given away is between 9 watches and 15? Show your calculations.

1How the students are chosen, what their probability distribution is, or how frequently the give away is done are not
relevant to this question and you do not need to account for that in your calculations

2