+ All Categories

CS322

Date post: 22-Mar-2016
Category:
Upload: lahela
View: 64 times
Download: 0 times
Share this document with a friend
Description:
Week 9 - Wednesday. CS322. Last time. What did we talk about last time? Exam 2 Before that: review Before that: relations. Questions?. Logical warmup. This is an old one, and not especially mathematical Still, it illustrates a useful point - PowerPoint PPT Presentation
Popular Tags:
31
CS322 Week 9 - Wednesday
Transcript
Page 1: CS322

CS322Week 9 - Wednesday

Page 2: CS322

Last time

What did we talk about last time? Exam 2 Before that: review Before that: relations

Page 3: CS322

Questions?

Page 4: CS322

Logical warmup This is an old one, and not especially mathematical Still, it illustrates a useful point A man and his son are driving in a car one day, when

they get into a terrible accident The man is killed instantly The boy is knocked unconscious, but he is still alive He is rushed to a hospital, and will need immediate

surgery The doctor enters the emergency room, looks at the

boy, and says, "I can't operate on this boy, he is my son."

How can this be? Please be quiet if you have heard this one before.

Page 5: CS322

Equivalence Relations

Page 6: CS322

Equivalence relation practice Let A = R × R. A relation F is defined on A

as follows: For all (x1, y1) and (x2, y2) in A, (x1, y1) F (x2, y2) ⇔

x1 = x2. Is F an equivalance relation?

Let A be the set of people living in the world today. A relation R is defined on A as follows: For all p, q ∈ A, p R q ⇔ p lives within 100 miles

of q. Is R an equivalence relation?

Page 7: CS322

Modular Arithmetic

Page 8: CS322

Modular arithmetic Modular arithmetic has many applications For those of you in Security, you know how

many of them apply to cryptography To help us, the following statements for integers

a, b, and n, with n > 1, are all equivalent1. n | (a – b)2. a b (mod n)3. a = b + kn for some integer k4. a and b have the same remainder when divided by

n5. a mod n = b mod n

Page 9: CS322

Rules of modular arithmetic Let a, b, c, d and n be integers with n > 1 Let a c (mod n) and b d (mod n), then:

1. (a + b) (c + d) (mod n)2. (a – b) (c – d) (mod n)3. ab cd (mod n)4. am cm (mod n), for all positive integers m

If a and n are relatively prime (share no common factors), then there is a multiplicative inverse a-1 such that a-1a 1 (mod n)

I'd love to have us learn how to find this, but there isn't time

Page 10: CS322

Partial orders A relation that is reflexive, antisymmetric,

and transitive is called a partial order The subset relation is a partial order

Show it's reflexive Show it's antisymmetric Show it's transitive

The less than or equal to relation is a partial order Show it's reflexive Show it's antisymmetric Show it's transitive

Page 11: CS322

Hasse Diagrams

Let set A = {1, 2, 3, 9, 18} Let R be the "divides" relation on A Draw A as a set of points and

connect each pair of points with arrows if they are related with R

Now, delete all loops and transitive arrows

This is a Hasse Diagram

Page 12: CS322

Total orders Let R be a partial order on set A Elements a,b R are comparable if either a R

b or b R a (or both) If all the elements in a partial order are

comparable, then the partial order is a total order

Let R be the "less than or equal to" relation on R Is it a total order?

Let S be the "divides" relation on positive integers Is it a total order?

Page 13: CS322

Probability

Page 14: CS322

Definitions

A sample space is the set of all possible outcomes

An event is a subset of the sample space Formula for equally likely probabilities:

Let S be a finite sample space in which all outcomes are equally likely and E is an event in S

Let N(X) be the number of elements in set X▪ Many people use the notation |X| instead

The probability of E is P(E) = N(E)/N(S)

Page 15: CS322

Card examples There are 52 cards in a normal Anglo-American

deck of cards Four suits: Spades, Hearts, Clubs, and Diamonds 13 denominations: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack,

Queen, King Imagine you draw a single card from a

thoroughly shuffled deck What is the sample space? What is the event of drawing a black face card? What is the probability of drawing a black face card?

Page 16: CS322

Dice example

Six-sided dice have, uh, six sides, numbered 1 through 6

If you roll two dice What is the sample space of outcomes? What is the event that the two dice add

up to 7? What is the probability that the two dice

add up to 7? What about all the other possible

values?

Page 17: CS322

Monty Hall Imagine you are playing a game show with 3 doors There is a prize behind one and nothing behind the other

two As the contestant, you pick a door, but it isn't opened yet The host Monty Hall opens one of the other two doors,

revealing nothing Then, you get a chance to switch Should you stay or switch or does it matter?

? ? ?

Page 18: CS322

Counting the elements in a list As a computer scientist, you have

almost certainly figured this out But, just to formalize it, if you have a list

numbered m through n, with no elements missing, the total number of elements are n – m + 1

For example, there are 50 elements in an array indexed from 0 to 49

Likewise, there are 39 elements in a list numbered from 67 to 105

Page 19: CS322

Multiplication Rule

Page 20: CS322

Possibility trees We can use a tree to represent all the possibilities in a situation Example:

Teams A and B are playing a best of 3 tournament The first team to win 2 games wins

How likely is it that 3 games are needed to decide the tournament, assuming that all ways of playing the tournament are equally likely?

A

AA

AA

B

B

B

B

B

Page 21: CS322

Multiplication rule If an operation has k steps such that

Step 1 can be performed in n1 ways Step 2 can be performed in n2 ways

… Step k can be performed in nk ways

Then, the entire operation can be performed in n1n2 … nk ways

This rule only applies when each step always takes the same number of ways (unlike the previous possibility tree example)

Page 22: CS322

Coin example

If you flip a coin k times, how many total possibilities are there for the outcomes?

Page 23: CS322

Personal Identification Numbers If a PIN is a 4 digit sequence, where

each digit is 0-9 or A-Z, how many PINs are possible?

How many PINs are possible if no digits are repeated?

Assuming that all PINs are equally likely, what's the probability that a PIN chosen at random has no repetitions?

Page 24: CS322

Permutations A permutation of a set of objects is an ordering of

the objects in a row Consider set { a, b, c } Its permutations are:

abc acb cba bac bca cab

If a set has n 1 elements, it has n! permutations

Page 25: CS322

Permutations of letters in a word How many different ways can the letters in

the word "WOMBAT" be permuted? How many different ways can "WOMBAT" be

permuted such that "BA" remains together? What is the probability that, given a random

permutation of "WOMBAT", the "BA" is together?

How many different ways can the letters in "MISSISSIPPI" be permuted?

How many would it be if we don't distinguish between copies of letters?

Page 26: CS322

Permuting around a circle What if you want to seat 6 people

around a circular table? If you only care about who sits next

to whom (rather than who is actually in Seat 1, Seat 2, etc.) how many circular permutations are there?

What about for n people?

Page 27: CS322

Permutations of selected elements An r-permutation of a set of n element is an

ordered selection of r elements from the set Example: A 2-permutation of {a, b, c} includes:

ab ac ba bc ca cb

The number of r-permutations of a set of n elements is P(n,r) = n!/(n – r)!

Page 28: CS322

r-permutation examples

What is P(5,2)? How many 4-permutations are there

in a set of 7 objects? How many different ways can three

of the letters in "BYTES" be written in a row?

Page 29: CS322

Upcoming

Page 30: CS322

Next time…

Read Chapter 9

Page 31: CS322

Reminders Work on

Assignment 7 Due on Friday

Security presentation today: A Day in the Life of

a Bad Guy Catcher Scott Roberts from

GitHub 3:30pm in E270

Looking for an internship or full-time job?

Bring your resume to the Masters Center Mineral Gallery this Wednesday, March 16 from 11am – 2pm

Attending companies: Tyco Electronics Computer Aid Inc. Clark Assoc. Deloitte - Camp Hill Sentinel Technology Group WebpageFX


Recommended