introduction to cs theory
DESCRIPTION
Introduction to CS Theory. Lecture 2 – Discrete Math Revision Piotr Faliszewski [email protected]. The course Logistics Problems we study What is computation? What problems do we solve? Languages Alphabet String Operations on strings Operations on languages. Mathematical background - PowerPoint PPT PresentationTRANSCRIPT
Introduction to CS Theory
Lecture 2 – Discrete Math RevisionPiotr [email protected]
Previous Class
The course Logistics Problems we study
What is computation? What problems do we
solve?
Languages Alphabet String Operations on strings Operations on
languages
Mathematical background Discrete mathematics Inductive proofs
Inductive Proofs
Theorem statement P(k) – some predicate
about an integer k Theorem: P(k) holds for
every integer k
Induction base P(0) holds
Inductive step Hypothesis: There is a
value k such that P(k) holds
Step: P(k+1) holds.
Example: Prove that 1 + 2 + 4 + … + 2n-1 = 2n-1
ProofP(k) = [1 + 2 + … +2k-1 = 2k-1]
Induction base1 = 21-1
Inductive stepHypothesis: There is a
value k such that 1 + 2 + … +2k-1 = 2k-1
Step: Show that if the hypothesis holds then1 + 2 + … +2k = 2k+1-1
Strong Mathematical Induciton
Inductive step: We were showing that
P[k] => P[k+1] Often this is limiting
Strong mathematical induction We can use a stronger inductive step (P[0] and P[1] and … and P[k]) => P[k+1] This way we can rely on all “previous” results
Strong Mathematical Induciton
Strong mathematical induction (P[0] and P[1] and … and P[k]) => P[k+1]
Theorem. Every positive natural number n ≥ 2 is either prime or is a multiplication of several primes
Proof. By induction on n.Base: n = 2. 2 is a prime, so theorem holds.
Inductive step:Hypothesis: There is number k such that each number k’ ≤ k is either prime or can be factored into several primesStep: k+1 is either prime or a multiplication of several primes
Consider casesa) k + 1 is prime then we are doneb) k + 1 is not a prime, thus k+1 = ab, where a and b
are two positive integers. Our hypothesis applies to both a and b. Thus, the theorem holds for k+1.
Is Induction Really Correct?
Exercise: Prove that 2n ≤ n!
Exercise: Prove that all horses are
af the same color! A proof by induction.
Base step holds Inductive step holds Eh…?!
Math is always right, so if you ever saw two
horses of different colors then you are
inconsistent with mathematics!
Is Induction Really Correct?
Exercise: Prove that 2n ≤ n!
Exercise: Prove that all horses are af
the same color! A proof by induction.
Base step holds Inductive step holds NOT
Oops!
Be Very Careful with Induction!!!
Recursive Definitions
Recursive definition Define a small set of
basic entities Show how to obtain
larger ones from those already constructed
A bit like induction!
Examples
Factorial0! = 1For each natural n, (n+1)! = (n+1)*n!
Recursive definition of Σ*:1. ε Σ*
2. If x Σ* and a Σ then xa Σ*
3. Nothing is in Σ* unless it is obtained by the two previous rules.
Recursive Definitions – Fibonacci Sequence
Fibonacci sequence f(0) = 0 f(1) = 1 For every n > 1:
f(n+1) = f(n) + f(n-1)
Computing Fibonacci numbers Bottom-up Top-down
Exercise Show that for each
natural n it holds thatf(n) ≤ (5/3)n
Show that 1 + ∑0 ≤ i ≤ n fi = fn+2
Recursive Definitions – Examples
Example Definition of |x|
1. |ε| = 02. |xa| = |x| + 1, for each x
Σ* and a Σ.
What is |aab|?
Prove that for each two strings it holds that |xy| = |x| + |y|
An exercise Give a recursive
definition of a reverse of a string. (xr)
Compute a reverse of a string based on this definition
Prove that for every string x, |x| = |xr|
Language of Palindromes
Palindromes A string is a palindrome if
it reads the same backward and forward
Let’s define a language of palindromes!
Language L of palindromes, Σ = {a, b}.1. ε L2. If x L then both axa and
bxb belong to L.3. Nothing belongs to L
unless it is obtained by rules 1 and 2.
Hmm… This looks wrong to
me!
Recursive Definitions – Examples
Language L of all strings with as many 0s as 1s. (Σ = {0,1})1. ε L2. For any x in L it holds
that each of: 0x1 1x0 01x 10x x01 x10belongs to L.
Is this definition correct?
Bribery Problem
Consider the following setting C – set of candidates V – set of voters Each voter votes for one
candidate Candidates with most
points win
Bribery For a unit price you can
buy a voter We want to make our
preferred candidate p win
How to do this most cheaply?
Example
c1 c2 c3 p
Bribery Problem
Consider the following setting C – set of candidates V – set of voters Each voter votes for one
candidate Candidates with most
points win
Bribery For a unit price you can
buy a voter We want to make our
preferred candidate p win
How to do this most cheaply?
Example
c1 c2 c3 p
Bribery Problem
Consider the following setting C – set of candidates V – set of voters Each voter votes for one
candidate Candidates with most
points win
Bribery For a unit price you can
buy a voter We want to make our
preferred candidate p win
How to do this most cheaply?
Example
c1 c2 c3 p
Bribery Problem
Consider the following setting C – set of candidates V – set of voters Each voter votes for one
candidate Candidates with most
points win
Bribery For a unit price you can
buy a voter We want to make our
preferred candidate p win
How to do this most cheaply?
Example
c1 c2 c3 p
Bribery Problem
Consider the following setting C – set of candidates V – set of voters Each voter votes for one
candidate Candidates with most
points win
Bribery For a unit price you can
buy a voter We want to make our
preferred candidate p win
How to do this most cheaply?
Example
c1 c2 c3 p
Bribery Problem
Consider the following setting C – set of candidates V – set of voters Each voter votes for one
candidate Candidates with most
points win
Bribery For a unit price you can
buy a voter We want to make our
preferred candidate p win
How to do this most cheaply?
Example
Proof of correctness? Induction! On what?
On the cost of the optimal solution!
c1 c2 c3 p
Tournament Problem
Tournament A directed graph There is a single edge
between any two vertices
Vertices – players Edges – results of
games (arrow points to the loser)
Example
Tournament Problem
Tournament Vertices – players Edges – results of
games (arrow points to the loser)
Problem: We want to pick a team of players, who jointly defeat everyone How can we pick such a
set? How large a set do we
need?
Example
Tournament Problem
Algorithm Input: Tournament T Pick player u who
defeats most players Form tournament T’ via
removing T and all the players he/she defeats.
If T’ is an empty graph the finish. Else, loop back using T’ instead of T
Questions Does this algorithm
work? How large a set does it
find? How to prove this?