cs 30 problem set 2

11
CS 30 Course Slides Discrete Mathematics for Computer Science 02 Problem Set

Upload: ivan-carlo-balingit

Post on 10-Jul-2016

6 views

Category:

Documents


0 download

DESCRIPTION

Problem Set

TRANSCRIPT

Page 1: CS 30 Problem Set 2

CS 30 Course SlidesDiscrete Mathematics for Computer Science

02 Problem Set

Page 2: CS 30 Problem Set 2

Instructions

Write your answers on A4/letter-size bond papers.

Do not write your answers at the back (only your solutions and scratch).

You are encouraged to recycle used papers (such as old handouts).

At the top of the front sheet, write and sign the Honor Code.

Refer to the syllabus for the honor code and policies on problem sets.

For probabilities, express your answers in percentage with 4 decimal places.

For answers with large values (e.g. 20!/5!), express them in simplest (not necessarily lowest) form.

In this case you may write 20!/5! or P(20,15).

This is a 30-point problem set.

Page 3: CS 30 Problem Set 2

2 Problem Set

2.1 Sets and Functions Learning outcomesA. Find the union, intersection, difference and complement of a set, as well as the cartesian product, cardinality, and power sets

Happiness is a byproduct of three things: function, purpose and conflict. Those who seek happiness for itself seek victory without war.- W. Burroughs

Sets [5 pts]Define the following sets as: SCS30 = the set of all students (undergrad, grad, phd) currently enrolled in CS30 (UPD DCS) SCS12 = the set of all students (undergrad, grad, phd) currently enrolled in CS12 (UPD DCS) SDCS = the set of all students (undergrad, grad, phd) in UPD DCS FUP = the set of all first year students (undergrad) in UPD TUP = the set of all teachers in UPD TDCS = the set of all teachers in UPD DCS

In the following questions, describe how to solve the given sets.For example, the set of all students currently enrolled in CS30 and CS12 can be described as SCS30 ∪ SCS12.

1. The set of all non-first year students currently enrolled in CS30.2. The number of all students and teachers in UPD DCS.3. The set of all first year undergrad students in UPD DCS not currently enrolled in CS30

In the following questions, describe the given sets.For example, |SCS30| can be described as the number of students currently enrolled in CS30.

4. P(SCS30) 5. FUP × TUP

Page 4: CS 30 Problem Set 2

2 Problem Set

2.1 Sets and Functions Learning outcomesB. Describe Russel's paradox

C. Determine whether a function is a surjection, injection or bijection

Happiness is a byproduct of three things: function, purpose and conflict. Those who seek happiness for itself seek victory without war.- W. Burroughs

Russel’s Paradox [1 pt]Suppose there’s an app called Freeze that can tell whether an app will freeze your phone or not. A suspicious app may freeze the phone by performing illegal operations such infinite loops. Even though we don’t know how the Freeze app works, we know that it will work for any app.

6. Explain why this app cannot be made using proof by contradiction.[Hint: the answer is a variant of the Halting problem; and the actual solution is also available on online. But before you dig into research, try thinking what happens if you create an app that will reverse the output of the Freeze app.]

Functions [2 pts]Let R be a relation from a set X to a set Y.

7. Describe how to determine if R is a function using the graph of R.8. Describe how to determine if R is a surjection but not a bijection using the graph of R.

Page 5: CS 30 Problem Set 2

2 Problem Set

2.2 Relations Learning outcomesA. Draw a directed graph of a function

B. Determine whether a relation is reflexive, symmetric, or transitive

C. Determine whether a relation is an equivalence relation

D. Find the equivalence classes of a relation

Never be afraid to stand with the minority when the minority is right, for the minority which is right will one day be the majority.- W. J. Bryan

Relation properties [3 pts]Determine whether the following relations are reflexive, symmetric or transitive.

9. A is the absolute value relation, x A y ⇔ |x| = |y|, for x, y ∈ R

10. Q is the rational relation, x Q y ⇔ x - y ∈ Q, for x, y ∈ R

11. Is the relation Q in #10 an equivalence relation?

Equivalence classes [2 pts]Let A = {-4, -3, -2, -1, 0, 1, 2, 3, 4}. R is the four-square relation, x R y ⇔ 4 | (x2 - y2).

12. Draw the directed for relation R.

13. How many equivalence classes are there for relation R?

Page 6: CS 30 Problem Set 2

2 Problem Set

2.3 Counting Learning outcomesA. Compute the probability of an event (where all outcomes are equally likely to happen)

B. Count the number of elements of a sequential list

C. Count the number of possible outcomes in a situation using multiplication rule and possibility trees

D. Count the number of elements in the union of two sets using addition rule

E. Count the number of elements in the difference of two sets using difference rule

Before you count your friends, make sure you can count on them.- Anonymous

IP Addresses [5 pts]In Version 4 of the Internet Protocol (IPv4), an address is a string of 32 bits. It begins with a network number, netid. The netid is followed by a host number, hostid, which identifies a computer as a member of a particular network. Three forms of addresses are used, with different numbers of bits used for netids and hostids.

Class A addresses are used for the largest networks. Class B addresses are used for medium-sized networks. Class C addresses are used for the smallest networks.

There are several restrictions on addresses because of special uses: 1111111 is not available as the netid of a Class A network, and the hostids consisting of all 0s and all 1s are not available for use in any network. A computer on the Internet has either a Class A, a Class B, or a Class C address. Besides Class A, B, and C addresses, there are also Class D addresses, reserved for use in multicasting when multiple computers are addressed at a single time, and Class E addresses, reserved for future use. Neither Class D nor Class E addresses are assigned as the IPv4 address of a computer on the Internet.

The figure below summarizes the number of bits for netids and hostids.

14-17. How many different IPv4 addresses are available for computers on the Internet?18. What’s the probability that a computer with Class A address is assigned with netid of all 0s?

Page 7: CS 30 Problem Set 2

2 Problem Set

2.3 Counting Learning outcomesF. Count the number of elements in the intersection of two sets using inclusion/exclusion rule

G. Apply the pigeonhole principle in solving a counting problem

H. Count the number of ordered subsets of objects using r-permutations

Before you count your friends, make sure you can count on them.- Anonymous

IP Addresses [5 pts]IPv4 addresses are usually written as 4 decimal numbers. For example, a Class B address that starts with 10, with netid 11 1111 1000 0000 and hostid 1111 1111 0000 0000, is written as 191.128.255.0. 19-21. How many Class B addresses either starts with 191 (191.X.X.X) or ends with 0 (X.X.X.0)?

Suppose an organization has acquired a certain Class C network address (netid). And suppose that the organization can use all the possible hostids under that network.

22. Can the organization host 255 computers, such that each computer will be given a unique hostid?

Suppose the organization decided to host 200 computers (out of the 255) at a time. Such that the first computer will get 100 hours of usage, the second will get 99 hours, and so on. Each computer user in the organization will file a request for hosting.

23. How many possible ways can the organization choose the 10 computers to be hosted, where the order of choice matters?

Page 8: CS 30 Problem Set 2

2 Problem Set

2.3 Counting Learning outcomesI. Apply the generalized pigeonhole principle in solving a counting problem

J. Count the number of unordered subsets of objects using r-combinations

Before you count your friends, make sure you can count on them.- Anonymous

Cards [3 pts]In the following questions, a standard deck of 52 cards will be used.

24. How many cards must be selected from the deck to guarantee that at least three cards of the same suit are chosen? Hint: Think of cards as pigeons and suits as pigeonholesAnother hint: What’s the worst possible case here (most number of cards before we get guaranteed)

25. How many must be selected to guarantee that at least three hearts are selected?Hint: Can you apply the generalized pigeonhole principle here?Another hint: Nope.

26. How many different ways can you get five cards from the deck, such that all cards have the same suit?Hint: Step 1 - choose a suit. Step 2 - choose the five cards given that suit.

Page 9: CS 30 Problem Set 2

2 Problem Set

2.3 Counting Learning outcomesK. Count the number of ordered subsets of indistinguishable objects using permutations

L. Compute the number of ordered subsets of repeating objects with r-permutations

M. Compute the number of unordered subsets of repeating objects with r-combinations

Before you count your friends, make sure you can count on them.- Anonymous

Cards [3 pts]In the following questions, a standard deck of 52 cards will be used.

27. How many ways are there to distribute hands of 5 cards to each of four players from the deck? Note: the order of distribution doesn’t matter

Suppose the suits and colors of the cards are removed. So there are four Ace cards, four Two cards, and so on. How many ways can we pick four cards out of the new deck of 52 cards, such that

28. The order matters?Meaning, picking Jack, Queen, King, King is not the same as Jack, King, Queen, King

29. The order doesn’t matter?Meaning, picking Jack, Queen, King, King is the same as Jack, King, Queen, King

Page 10: CS 30 Problem Set 2

2 Problem Set

2.4 Probability Learning outcomesA. Apply the probability axioms in solving probability problems

B. Compute the expected value of a given scenario

C. Explain the Gambler's fallacy

D. Explain the solution to the Monty Hall problem

The probability that we may fail in the struggle ought not to deter us from the support of a cause we believe to be just.- A. Lincoln

Cards [4 pts]Suppose a person offers to play a game with you. In this game, when you draw a card from a standard 52-card deck, if the card is a face card you win P100, and if the card is anything else you lose P50.

30. If you agree to play the game, what is your expected gain or loss?

Suppose you decided to play the game. Unfortunately, you picked a non-face card. After this, you decided to try your luck again, but too bad, from the reshuffled 52-card deck, you picked another non-face card. By this you have lost P100 already. The person now tells you that you should try once more since you’ve just picked two non-face cards in a row, which means your chances of getting a face card is higher this time.

31. Should you believe the person? Why or why not?Assume that before every round, the 52-card deck is randomly shuffled. Also, assume that the person does not do any trick, for e.g. in shuffling and in picking of card.

Suppose the person offers another game. In this game, you will be presented with three unknown cards. One is a face card, and two are non-face cards. You will choose one card. If the card you chose is a face card, you’ll win P100. Otherwise, you’ll lose P50. After you choose a card, the person, knowing which cards are face and non-face, will reveal a non-face card that you did not select. Then, the person will ask you whether you want to switch your choice or not.

32. What’s your probability of winning if you choose to stick with your original choice?

Now, suppose the person doesn’t know the values of the cards, and opens a card at random. This means that he may accidentally reveal a face card, which makes you lose automatically. But in the event that he reveals a non-face card, he will ask you whether to switch or not.

33. What’s your probability of winning if you choose to stick with your original choice?

Page 11: CS 30 Problem Set 2

2 Problem Set

2.4 Probability Learning outcomesE. Compute the conditional probability of an event given another event

F. Apply Bayes' theorem in solving conditional probability

G. Compute the probability of independent events

The probability that we may fail in the struggle ought not to deter us from the support of a cause we believe to be just.- A. Lincoln

Health [3 pts]Suppose that 4% of the patients tested in a clinic are infected with avian influenza. Furthermore, suppose that when a blood test for avian influenza is given, 97% of the patients infected with avian influenza test positive and that 2% of the patients not infected with avian influenza test positive.

What is the probability that34. A patient, who tested positive, is infected? 35. A patient, who tested negative, is not infected? 36. A patient will test positive, and will get a tail by flipping a fair coin?Assume that the results of the coin flip and the influenza test do not affect each other.