Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Amodb: N R N+R 1 R N+R 1 N 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

CS182: Final Cheat Sheet Counting:

Number Theory: Product rule- the # of ways to do the procedure is |A1| * |A2| (If
Notes: 3|12 = 12/3 => 4, 3 ∤ 7 bc 7/3 is not an int there are n ways of doing something, and m ways of doing
a|b if remainder = 0, if a|b => b = k*a, a != 0 another thing after that, then there are n * m ways to perform both
1) If a|b and a|c, then a|(b+c) actions.
2) If a|b and b|c, then a|c Ex) a “word” is any string of seven (7) letters of the English
3) If a|b, then a|b*c for all ints c alphabet, with repeated letters allowed, how many words are
Ex) p/disp: if a|b & c|d, then (ac)|(b+d) => FALSE=> 3|9 & 2|4 != there? Each word is of length 7 and each position may take one of
6 ∤13 the 26 letters in English alphabet. The choice for each position is
Ex2) p/disp: for all non-0 integers a, b, if a|b and b|a, then a= b. independent of other positions, thus we use the product rule; there
=>TRUE=> a|b => b = Some int k *a, b|a => a = k2 *b, b = k * are 267 = 26 × 26 × 26 × 26 × 26 × 26 × 26 total words.
(k2*b), => b= k*k2b=> 1=kk2=>k=k2=1, => k=1 => b = 1*a, a = Ex) bit strings of length 12: how many begin with 10? 29 words.
1*b => b=a, a=b => a=b Begin w/. 11 and end in 10? 28
Modulus: Sum rule- the # of ways to do the procedure is |A1| + |A2|
a mod b = the remainder of a | b => 12 mod 3 = 0, (13/5 = 2 If there are n choices for one action, and m choices for another
remainder 3=>> 13 mod 5 = 3), 12 mod 5 = 2, aka remainder of action and the two actions cannot be done at the same time, then
a/b there are n + m ways to choose one of these actions.)
mod (a, b) = r, if a = bk + r, aka remainder of a/b == a mod b Subtraction rule- |A1| + |A2| - |A1 ꓵ A2|
(a+b) mod m = ((a mod m) + (b mod m)) mod m Ex) bit strings of length 12: begin w/. 11 (210) OR end w/. 10
ab mod m = ((a mod m) (b mod m)) mod m (210)? Begin and end = 28 => 2*210 -28
Ex) Is mod (a, b) = mod (b,a) ? => NO => Let a= 10, b = 6, mod Division rule- Let S be a set of n items partitioned into cells of
(10, 6) = 4, mod (6, 10) = 6 => 4 != 6 size d. Then the number of cells in the partition is n d .
a ≡ b mod m, if m|a-b or m|b-a Ex) bit strings of length 12: exactly 4 ones? 12!/4!*8! (12 total/ 4
a ≡ b mod m iff mod(a,b) = mod(b,m) 1s * 8 0s)
a + c ≡ b + c mod m Ex) DNA bases contain 1 of 4 values : A, C, T, G. How many
a * c ≡ b * c mod m  no division!! length 8 sequences start w/. C and end w/. C? 46. Contain exactly
(a + b) mod m = [(a mod m) + (b mod m)] mod m 4 C’s? 8!/4! *4!4!4! Contain exactly 1 of the 4 bases? 4.
(a · b) mod m = [(a mod m) · (b mod m)] mod m Ex) pick cards 1 at a time w/.o replacement from 52 cards. Min #
Ex) if a ≡ b(mod m) and c ≡ d(mod m), then ac ≡ bd (mod m)? => of cards to pick to guarantee: a pair? 14 cards. 3 of a kind? 27.
TRUE => a ≡ b(mod m) => a-b = km, c ≡ d (mod m) => c-d = Ex) Let |A| = 4 and |B| = 10, find # of functions f: A->B. 104. # of
k2m, ac ≡ bd (mod m) => ac -bd = k3 m, ak ≡ bk (mod m), a = km 1-1 functions A->B? 10*9*8*7. |A| = 10, |B| = 4, # of 1-1
+b.. etc Eval. ac-bd => (km+b) (k2m+d) -bd…=> divisible by m, functions f: A->B? 0.
so ac ≡ bd (mod m) Ex) # of subsets of S = {1,2, 3... ,10} that contain 5? 29 That
Ex2) find ints such that a+b = ab(mod 5). => (a+b) -ab = k*5 => b contain neither 5 nor 6? 28. That contain 5 & 6? 28. That contain
– ab +a = 5k, -a(b-1) +a = 5k, a(1-b) +a => b- ab +a +1 -1 = 5k => no odd #s? 25.
-b(a-1)(b-1) -1 = 5k =>(a-1) (b-1) = 5k+1a = 4, b= 3, k = 1 Permutations: order MATTERS.
Ex3) Find all ints such that x ≡ 5 (mod 13). => x mod 13 = 5 mod Repetition: n!/(n-r)!, no rep: nr
13 => 5 mod 13 = 5 =>> x mod 13 = 5 => x = 5+- some multiple Comninations: order does NOT matter
of 13  −21 mod 13=5, 5 mod 13=5 , 31 mod 13=5 x = -21, 5,
31
Prime Numbers: divisible only by 1 and the # itself (>=2)
Rep: (nr ) = n!/ (r!(n-r)!), no rep: (n+ r−1
r )
= ( n+ r−1
n−1 )
Fundamental Thm of Arithmetic: every integer can be represented Ex) How many binary strings of len 14 contain @ most 3 ones?
uniquely as a product of primes:
Ex) 100 = 2*2*5*5 = 2252 (143 )+(142)+( 141)+(140 )
If n is composite int, it has a prime divisor <= √ n Ex) How many ways are there to select five players from a 10-
Ex) show 107 is a prime number. If 107 is composite, then it has a member tennis team to make a trip to a match at another school?
prime divisor smaller than √107 ≈ 10.34. Primes smaller than 10
are 2, 3, 5, and 7. None of it divides 107, thus 107 must prime (2P Non distinct Objects: n!/( n1!* n2!*…* nn!)
-1) Ex)How many different strings can be made by reordering the
letters of the word SUCCESS?
GCD: greatest common divisor, if = to 1, then #s are relatively Solution: There are seven possible positions for the three Ss,
prime two Cs, one U, and one E.
Ex) gcd(24, 36): prime factorization of 24 = 23 * 3, ‘ ‘ of 30 = 22 * The three Ss can be placed in C(7,3) different ways, leaving four
32 => gcd = 22 * 3 = 12 positions free.
gcd(a,0) = a(a/a & a/0) The two Cs can be placed in C(4,2) different ways, leaving two
gcd(a,a) = a(a/a & a/a) positions free.
gcd(a,b) = gcd(b,a) The U can be placed in C(2,1) different ways, leaving one
Euclidian Algorithm: if r(remainder of a/b)= a mod b, then position free. The E can be placed in C(1,1) way.
gcd(a,b) = gcd(b,r) By the product rule, the number of different strings is
Ex) gcd(1000, 625) => (375 = r of 1000/675) => 1000 = 625(1)
+375  gcd(625, 375) => 625 = 375(1) + 250  gcd(375, 250) Pigeon Hole: given n objects, place in k boxes, one box will
=> 375 = 250(1) +125  gcd(250, 125) => 250 = 125(2) + 0  contain @ least ⌈n/k⌉ objects
gcd = 125 Ex) Among 100 people there are at least ⌈100/12⌉ = 9 who were
born in the same month.

Binomial Thm.: (x+y)n = ∑ x n− j y j
j=0

Probability: Sample Space: set of possible outcomes, usually


denoted S, Experiment: a procedure where you get one outcome
out of the sample space
Event: a subset of the sample space, usually denoted E,
Probability: If E is an event of S, then p(E)=|E||S|
Ex) prob a hand of 5 cards in poker contains 4 of a kind: (13

*48)/ (525 )
Ex) prob that a random k-digit decimal is also a valid octal #(digit
betwn 0 & 8) =>base8/base10 => (7*8k-1) / (9*10k-1)

Ex) prob 5 of a kind of 52 cards, pick 5 =>(13 * ( 43)(482 ) (525 )


)/

Ex) pick two cards @ random form 52 cards: prob both are
diamonds? ¼ * 4/17 prob cards form a pair? 1* 3/51
Conditional: Probability of A given B P(A|B) = P(A ꓵ B)
/P(B)== P(B ꓵ A)/P(B)
Ex) What is the probability that when two dice are rolled, the sum
of the numbers on the two dice is 7 ? By the product rule there are
62 = 36 possible outcomes. Six of these sum to 7. So, the
probability of obtaining a 7 is 6/36 = 1/6.

Independent Events: P(A|B) = P(A) & P(B|A) =P(B), P(A ꓵ B)


= P(A) * P(B)
expected value: (also known as the mean value) of a random HW 1 - 1. Prove or disprove: For all integers a, b, c, d, if a|b and
variable X(s) over s ∈ S taking values in t ∈ X(s) is defined as c|d, then (ac)|(b+d).
E[X] = X s∈S P(s)X(s) = X t∈X(S) tP(X = t). Solution. The statement is false. Here is a counter example: 3|9 &
Ex) probability of a head or a tail is 0.5 : P(X = 0) = 1 /8 , P(X = 2|4 ; 6 - 13
1) = 3 /8 , P(X = 2) = 3/ 8 , P(X = 3) = 1/ 8 , since, for example, 2. Prove or disprove: For all integers a, b, c, if a|bc, then a|b or a|c.
{X = 1} = {HHT, T HH, HT H}, thus we have three out of 2 3 = 8 Solution. The statement is false. Here is a counter example: 9|6 ×
outcomes satisfying X = 1 (i.e., the number of tails is equal to 15 However 9 - 4 & 9 - 15
one). Therefore, E[X] = 0 · 1/8 + 1 · 3 /8 + 2 · 3 /8 + 3 · 1/ 8 = 3. Find the prime factorization of 45617.
12 /8 , that is, on average we have 1.5 tails per three throws Solution. 45617 = 29 × 13 × 112
random variable: a function from the sample space of an 4. List all positive integers less than 30 that are relatively prime
experiment to the set of real numbers to 20.
String Operators: reverse (wR), length(|w|), empty( ) (| | = 0), Solution. {1, 3, 7, 9, 11, 13, 17, 19, 21, 23, 27, 29}
5. Prove or disprove: The sum of two primes is a prime.
exp (concat str times itself) (w0 =  ), * = (sigma * = set of all
Solution. The statement is false. Let P denote the set of all prime
possible strings from alphabet sigma)
numbers. Counter Example: p1 = 3 ∈ P and p2 = 5 ∈ P. However,
Finite Automata:
p1 + p2 = 3 + 5 = 8 ∈/ P.
6. Prove or disprove: If p and q are primes (both > 2), then pq + 1
is never prime.
Solution. The statement is correct. Let P denote the set of all
prime numbers. Since, p, q ∈ P and a, b > 2, hence a, b are odd
integers. Hence, pq > 2 is odd, and pq + 1 is an even integer larger
than 2 which cannot be a prime.
7. Find the smallest integer a > 1 such that a + 1 ≡ 2a (mod 11).
Solution. a + 1 ≡ 2a ⇔ 1 ≡ a ⇔ 12 ≡ a (mod 11) 1
2) 7. How many words begin with A or B or end with A or B?
Solution. Let p = event that the words begin with A or B Let q =
event that the words end with A or B See question 5 for the
equation of |p ∪ q|. |p| = 2 × 26 × 26 × 26 × 26 × 26 × 26 = 2 ×
266 |q| = 26 × 26 × 26 × 26 × 26 × 26 × 2 = 2 × 266 |p ∩ q| = 2 ×
26 × 26 × 26 × 26 × 26 × 2 = 4 × 265 |p ∪ q| = 2 × 266 + 2 × 266
− 4 × 265 = 4 × 266 − 4 × 265 = 100 × 265
8. How many words begin with AAB in some order? Solution.
The first 3 letters in the words are 2 As and 1 B, so we choose 1
positions in the first 3 positions to put letter B, then the left
positions out of first three will have letter A. So there are 3 ways
to arrange the first 3 letters (AAB, ABA, BAA), and each of the
remaining four positions could be one of the 26 letters. Thus there
are 3 1 ∗264 = 3∗264 total words beginning with AAB in some
order. 9. How many words have no vowels? Solution. There are 6
vowel letters in our version of alphabet: A, E, I, O, U, and Y (we
treat Y as a vowel). The rest 20 letters of the alphabet are
consonants: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W,
X, and Z Since we want words without vowels, we have 20
choices for any of the 7 positions. Hence, 207 = 20 × 20 × 20 × 20
× 20 × 20 × 20 total words without any vowels exist. 10. How
many words have exactly one vowel? Solution. There are 6 vowel
letters in our version of alphabet: A, E, I, O, U, and Y (we treat Y
as a vowel). The rest 20 letters of the alphabet are consonants: B,
C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, and Z We
first choose one position out of the 7 positions in a word for the
vowel, which could take one of the 6 values above. Then each of
the remaining 6 position could be one of the 20 consonants. Thus
in all there are 7 1 × 6 × 206 = 42 × 206 words have exactly one
vowel.
club with 20 women and 17 men needs to form a committee of
size six. • How many committees are possible? Solution. There
are no restrictions. The committee can consist of any subset of
women and men. The total number of people in the club is 20 +

17. The number of possible committees is: (20+17


6 ) ( 37
6)
= =

37!/(6!(37 − 6)!) = 2, 324, 784

You might also like