220 likes | 406 Views
Introduction to CS Theory. Lecture 2 – Discrete Math Revision Piotr Faliszewski pf@cs.rit.edu. 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
E N D
Introduction to CS Theory Lecture 2 – Discrete Math Revision Piotr Faliszewski pf@cs.rit.edu
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 Previous Class
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 Proof P(k) = [1 + 2 + … +2k-1 = 2k-1] Induction base 1 = 21-1 Inductive step Hypothesis: There is a value k such that 1 + 2 + … +2k-1 = 2k-1 Step: Show that if the hypothesis holds then 1 + 2 + … +2k = 2k+1-1 Inductive Proofs
Strong Mathematical Induciton • Inductive step: • We were showing thatP[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 primes Step: k+1 is either prime or a multiplication of several primes Consider cases a) k + 1 is prime then we are done b) 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.
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…?! Is Induction Really Correct? Math is always right, so if you ever saw two horses of different colors then you are inconsistent with mathematics!
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 Is Induction Really Correct? Oops! Be Very Careful with Induction!!!
Recursive definition Define a small set of basic entities Show how to obtain larger ones from those already constructed A bit like induction! Examples Factorial 0! = 1 For each natural n, (n+1)! = (n+1)*n! Recursive definition of Σ*: εΣ* If x Σ* and a Σ then xa Σ* Nothing is in Σ* unless it is obtained by the two previous rules. Recursive Definitions
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 that f(n) ≤ (5/3)n Show that 1 + ∑0 ≤ i ≤ n fi = fn+2 Recursive Definitions – Fibonacci Sequence
Example Definition of |x| |ε| = 0 |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| Recursive Definitions – Examples
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}. • ε L • If x L then both axa and bxb belong to L. • Nothing belongs to L unless it is obtained by rules 1 and 2. Hmm… This looks wrong to me!
Language L of all strings with as many 0s as 1s. (Σ = {0,1}) ε L For any x in L it holds that each of: 0x1 1x0 01x 10x x01 x10 belongs to L. Is this definition correct? Recursive Definitions – Examples
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 Bribery Problem c1 c2 c3 p
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 Bribery Problem c1 c2 c3 p
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 Bribery Problem c1 c2 c3 p
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 Bribery Problem c1 c2 c3 p
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 Bribery Problem c1 c2 c3 p
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! Bribery Problem c1 c2 c3 p
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? Tournament Problem