Professional Documents
Culture Documents
Final Review
Zeph Grunschlag
Review
Agenda
List of sections covered
Review major concepts with formulae
Review
Sections Covered
1.1 Logic
1.2 Tautologies/Equivalence
1.3 Predicates/Quantifiers
1.4 Sets
1.5 Set Theory Operations
1.6 Functions
1.7 Sequences/Sums
1.8 Big-O, Big-, Big-
2.1 Algorithms
2.2 Complexity
2.3 Basic Number Theory
2.4 Number Theory Algorithms
2.5 RSA
(2.6 Matrices)
Review
3.1 Proofs
3.2 Induction
3.3 Recursive Definitions
3.4 Recursion
(3.5 Program Correctness)
4.1 Counting Basics
4.2 Pigeonhole Principle
4.3 Permutations and Combinations
4.4 Discrete Probability
4.5 Probability Theory
4.6 Generalizations
5.1 Recurrence Relations
5.2 Solving Linear Recurrences
5.5 Inclusion-Exclusion
5.6 More Inclusion-Exclusion
3
Sections Covered
6.1
6.2
6.3
7.1
7.2
7.3
7.4
7.5
7.7
7.8
Relation Basics
n-ary Relation
Representing Relations
Graph Basics
Graph Terminology
Graph Representations
Connectedness
Euler and Hamilton
Planar Graphs
Coloring
Review
Sections Skipped
2.6
3.5
4.7
5.3, 5.4
6.4, 6.5, 6.6
7.6
Logic
A proposition is a statement that is true
or false. Atomic propositions p,q,r
are combined to form compound
propositions using the following
logical connectives :
Review
Logical Connectives
Operator
Negation
Conjunction
Disjunction
Exclusive or
Conditional
Biconditional
Review
Symbol Usage
Java
not
and
&&
or
||
xor
(p||q)&&(!p||!q)
if,then
p?q:true
iff
(p&&q)||(!p&&!q)
6
Truth Tables
Logical operators/connectives are defined by
truth tables:
p
p
Negation truth table (unary):
F
T
T
F
Binary truth tables:
p
q
pq pq p q p q p q
T
T
F
F
T
F
T
F
T
F
F
F
T
T
T
F
F
T
T
F
T
F
T
T
T
F
F
T
Bit Strings
Can define logical operators on bit
strings. This is done bit by bit. No
carry-over is taken.
EG:
01 1011 0010 1001
Review
Tautologies
Logical Equivalence
A compound proposition is a tautology if it
is always true, regardless of the its
atomic propositions (e.g. p p ). If its
always false, its a contradiction (e.g.
pp ). If neither, its a contingency
(e.g. p p ).
Two compound propositions p, q are
logically equivalent if p q is a
tautology. Notation: p q .
Review
Review
10
Logical Proofs
There are two basic techniques for proving
tautologies and logical equivalences:
1) Build a truth table. Verify that
last column is all TRUE for tautology
relevant columns equal for equivalence
11
Domination laws
Like multiplying by 0
Idempotent laws
Delete redundancies
Double negation
I dont like you, not
Commutativity
Like x+y = y+x
Associativity
Like (x+y)+z = y+(x+z)
Distributivity
Like (x+y)z = xz+yz
Review
De Morgan
12
Excluded middle
Negating creates opposite
Definition of implication in
Review
13
Quantifiers
Existential Quantifier
reads there exists
Universal Quantifier
reads for all
Order matters:
y x R (x,y ) and x y R (x,y ) may
not be logically equivalent to.
Review
14
DeMorgan Identities
Not all true iff one is false.
Conjunctional version:
(p1p2pn) (p1p2pn)
Universal quantifier version:
x P(x ) x P(x )
Review
Disjunctional version:
(p1p2pn) (p1p2pn)
Existential quantifier version:
x P(x ) x P(x )
15
Logical English
Logical Puzzles
Precise English statements can be expressed in
terms of logical constructs. In cases of English
puzzles, this can be useful for solving.
EG: Can there be a man that shaves exactly all
the people that dont shave themselves.
Let S(x,y) = x shaves y. Asking if following
statement satisfiable:
x y S(y,y ) S(x,y)
Not satisfiable (trying plugging in y = x )1
Review
16
Review
17
Set Notation
element : 3 S
not an element : 3 S
subset : S T
strict subset : S T
empty (or null) set : {} or
cardinality : |{1, -13, 4, -13, 1}| = 3
Review
18
Cartesian product :
A B = { (a, b) | a A and b B }
|A1A2An| = |A1||A2| |An|
complement :
A={x|xA}
union :
A B = { x | x A x B }
intersection : A B = { x | x A x B }
difference :
A-B={x|xA xB}
symmetric difference:AB={ x | xA xB }
Review
19
Venn Diagrams
Complement
Intersection
Union
Review
Disjoint Union
AB
A
AB
A B
20
Venn Diagrams
Difference
Symmetric Difference
AB
U
AB
U
B
Review
21
Sets as Bit-Strings
If elements ordered, each set can be viewed as
bit-string s. Operators act on bit-strings:
complement A 1s complement -s
union A B disjunction s t
intersection A B conjunction s t
difference A - B s (-t )
symmetric difference AB s t
EG: If U = {1,2,3,4}, A = {2}=0100,
B = {1,2,4}=1101 then:
22
Functions
One-to-One
NO:
NO:
YES:
NO:
Reverse
YES:
Onto
NO:
reverse:
YES:
reverse:
Review
23
Function Notation
Composition : f g (a) = g ( f (a) )
n
Exponentiation :
f n (x ) = f f f f f (x )
Floor and Ceiling : x , x
f : A B --function from A to B
domain
codomain
Range : f (A )
Review
24
25
Summations
Sum of first n
numbers: n
n(n + 1)
i=
2
i =1
Sum of first n k th
powers: n
k +1
k
i
=
(
n
)
Sum of a sequence
n from 0 to n :
a
i =0
= a0 + a1 + a2 + ... + an
x
xS
i =1
Double sum:
2
i=0
Review
j =1
Geometric sum:
ar n +1 a
ar = a + ar + ar + ... + ar =
r 1
i =0
n
ij
26
i + 1
ai = (1)
Review
27
Uncountability of R
Cantors Diabolical Diagonal
If R were countable could list all numbers in
(0,1) by a sequence:
r1 , r2 , r3 , r4 , r5 , r6 , r7,
Cantors diabolical diagonalization creates a
number revil between 0 and 1 which is not
on the list, contradicting countability
assumption. Let ri,j be the j th decimal digit
in the fractional part of i th number ri .
Define digits of revil by the following rule:
The j th digit of revil is 5 if rj,j 5. Otherwise
the j th digit is 4.
revil is an anti-diagonal of the seqencs {rn }
Review
28
Cantor's Diagonalization
Example
Decimal expansions of ri
r1
r2
r3
r4
r5
r6
r7
:
r
evil
Review
0.
0.
0.
0.
0.
0.
0.
1
1
2
7
0
5
7
2
5
5
8
1
5
6
3
1
4
9
1
5
7
4
1
2
0
0
5
9
5
1
0
6
1
5
5
6
1
9
2
0
5
4
7
1
0
3
1
5
4
0.
29
if and only if f (x ) = O ( g (x ) )
and positive, then f (x ) = (g (x ))
30
Asymptotically Incomparable
Functions
Some functions are incomparable.
EG: |x 2 sin(x)| vs. 5x 1.5 :
y = x2
y = 5x 1.5
y = |x 2 sin(x)|
Review
31
Review
32
lcm(x,y) = xy / gcd(x,y)
Review
33
INPUT : integers m, n
(m > 0, n 0 )
OUTPUT : s, t such that
sm+tn = gcd(m,n)
(int.,int.) ext_euclid(m,n)
r = m mod n
//remainder
q = m/n
//quotient
(s,t ) = ext_euclid(n,r)
return ( t , s-tq )
34
Modular Congruence
Often confused with mod function.
a a (mod b) is a relation on Z, not a function!
DEF: a a (mod b) ) iff b | (a a ).
a mod b a (mod b)
Suppose a a (mod b) and c c (mod b). Then:
Modular Inverse:
3.
Review
Number Systems
A base-b number is a string
u = ak ak-1 ak-2 a2 a1 a0
with the ai taken from
{0,1,2,3,,b-2,b-1}.
u represents the number
(u )b = akbk+ak-1bk-1++a1b + a0
When b > 10, use capital letters:
A=10, B=11, C=12, etc.
Standard bases:
Binary (base-2)
Octal (base-8)
Decimal (base-10)
Hexadecimal (base-16)
Review
36
Arithmetical Algorithms
Addition and Multiplication
Addition in any base b :
Binary multiplication:
string add(xk xk-1x1x0,
bitstring multiply(xk xk-1x1x0,
yk yk-1y1y0)
yk yk-1y1y0 , int b)
x = xk xk-1x1x0
carry = 0, xk+1 = yk+1 = 0
p=0
for(i = 0 to k+1)
for(i = 0 to k+1)
digitSum=carry+xi
+yi
if(yi == 1)
p = add(p , x << i )
zi =digitSum mod b
carry =digitSum /b return p
return zk+1zk zk-1z1z0
Review
37
1s and 2s Complement
1s Complement
Fix k bits.
Represent numbers |x | < 2k-1
Most significant bit tells the
sign
0 positive
1 negative
Review
Add as usual.
If there was carryover, add 1
2s Complement
Fix k bits.
Represent no.s in [-2(k-1),2(k-1))
Most significant bit tells the
sign
0 positive
1 negative
Add as usual.
Drop any carryover!
38
Review
a n a n mod p-1(mod p)
EG: 923 mod 23
= 9(23 mod 22) mod 23
= 91 mod 23 = 9
39
41
Useful Tricks
Try to use algebraic
Assume P true, show Q true
form of definition and
Indirect Proof
reduce algebraically
Assume Q false, show P false
Write rational numbers
Reductio Ad Absurdum1
(in Q) p/q with p,q
Assume P Q true,
show P Q true
relatively prime
Disrefutation of x P (x):
Just find a counterexample
Review
42
Mathematical Induction
Well Ordering Property: Non-empty subsets S of
N have a smallest element.
Simple Induction:
If the following hold:
1)
[basis] P (0) is true
2)
[induction] n P(n)P(n+1) is true
Then n P(n) is true
Strong Induction:
If the following hold:
Review
43
Recursive Definitions
Factorial
Fibonacci sequence
Binomial Coefficients
n-choose-k
Addition of nonnegative integers
1, if n = 0
n! =
n ( n 1)! , if n 1
n , if k = 0 or 1
f (n) =
f ( n 2 ) + f ( n 1), if k 2
0, if k < 0 or k > n
C (n, k ) = 1, if k = n = 0
C (n 1, k 1) + C (n 1, k ), otherwise
m, if n = 0
m + n = m + 1, if n = 1
( m + (n 1)) + 1, if n > 1
0, if n = 0
n 1
=
a
i
i =1
ai + an , if n > 0
i =1
1, if n = 0
n
n 1
a
=
i
a
i =1
i an , if n > 0
i =1
n
Summation Notation
Product Notation
Review
44
More Recursion:
Sets, Relations, Graphs
Can define sets and relations recursively as well.
Set of quantities payable with dimes and quarters:
BASE: 0 S
RECURSE: u + 10, u + 25 pal if u pal
Set of palindromes :
BASE:
, 0, 1 pal
RECURSE: 0u 0, 1u 1 pal if u pal
Review
BASE:
RECURSE:
connected
connected
45
Set theoretic:
|A B| = |A||B|
Combinatorial: If have n
stages, where i th stage
allows ai different situation,
total number of combinations
is a1a2a3an
EG: No. of ways to order 5
Review
Combinatorial: If over-counting
by a factor of d for each case of
interest, divide by d
EG: No. of 5 cards hands.
46
Inclusion-Exclusion
2 sets:
|A B | = |A|+|B |- |A B |
3 sets:
| A1 A2 An |
| A1 | + | A2 | + + | An |
| A1 A2 | | A1 A3 |
+ | A1 A2 A3 | + | A1 A2 A4 | +
+ ( 1) n 1 | A1 A2 An |
Review
47
Pigeonhole Principle
Simple pigeonhole:
If N+1 objects are placed into N boxes,
there is at least one box containing 2
objects.
Generalized pigeonhole:
If N objects are placed into k boxes, there is
at least one box containing N/k objects.
Review
48
r-permutations
r-combinations
r-permutations P (n,r )
r-combinations C (n,r )
L18
Counting Formulas
Perms and Combos
Anagrams : with n letters with repetition
numbers a1, a2 , a3 , . , ak number of
anagrams is n ! / (a1! a2 ! a3 ! ak !)
Functions : Domain size m, codomain size n
General :
Bijections (m =n ):
One-to-one (m n ):
Onto (m n):
nm
n!
P (n,m )
50
Counting Formulas
Stars and Bars
Number of solutions in N of x1+x2++xk+1=n
C (n+k,k)
Also the number of different arrangement of n s
and k |s in a string
Further constraints
Review
Cards
52 cards per deck (not including Jokers)
4 suits :
Hearts
Diamonds Spades
Clubs
13 ranks :
L18
52
Straight
Any five cards in sequence but
not all of the same suit.
Three of a kind
Three of the same rank with
two unmatched cards.
Two pairs
Two cards of one rank with two
cards of a different rank with
one dissimilar card. When
matching pairs occurs between
players, the one with the
higher fifth card wins.
One pair
Any two cards of the same
rank.
53
Probability
If all outcomes equally likely the probability of
event E in sample space S is the ratio
p (E ) = |E | / |S |
If each outcome s has probability p (s )
probability of event E is
p( E ) = p( s )
sE
Conditional Probability
Independence
If E and F are events and p (F ) > 0 then
the conditional probability of E given F
is defined by: p (E |F ) = p (EF ) / p (F )
Independent events : p(EF )=p(E )p(F )
Review
55
Relations
n -ary relation on sets (A1,A2, ,An) is a
subset of A1A2 An.
binary relations : n = 2
Review
(3,2)
< <(3,2) = 0 (3 < 2) = 0
Relations
Relations on A
Representations
Adjacency matrix
Digraph
Properties
Reflexive : every element self-related
Symmetric : (a,b) R (b,a) R
Transitive :(a,b),(b,c) R (a,c) R
Exponentiation : R n = L
R OM
R m
R
O
ON
O
n times
Review
57
Jn (R,S )
Each element in R whose last n coordinates match
with first n coordinates of S, create an element of join
EG, 2-join: (0,1,1)
2-join (0,1,1,1)
(1,1,1)
Projection of R to sub-coordinates
Review
Pi1,i2,, ik (R )
Keep only the indexed coordinates
EG: (0,1,1)
1,3 projection
(0,1)
58
Graphs
Undirected graphs
Directed graphs
Graph families
Complete graphs Kn
Cycles Cn
Wheels Wn
Cubes Qn
2 eE
Directed graphs:
in-degree deg-: the number of edges that stick in
out-degree deg+:the number of edges that stick out
Handshaking Theorem: | E | =
deg
( e) =
eE
deg
( e)
eE
F R
60
K4,5
61
Graph Isomorphism
Isomorphism from G1=(V1,E1) to G2=(V2,E2). A
function on vertices satisfying:
1)
2)
f is bijective
number of edges bet. u,v in G1 is same as bet. f
(u), f (v ) in G2
To prove isomorphism, describe f explicitly
To prove non-isomorphism, show that a graph
invariant differs for G1 vs. G2
Review
Connectedness
Undirected graph
Review
Hamilton path
Review
64
Planar Graphs
Planar if can be drawn in
plane without any crossing
edges.
text)
Euler formula method (see
next column)
Review
1
| E | rg
2