Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to CS Theory Lecture 2 – Discrete Math Revision Piotr Faliszewski

Similar presentations


Presentation on theme: "Introduction to CS Theory Lecture 2 – Discrete Math Revision Piotr Faliszewski"— Presentation transcript:

1 Introduction to CS Theory Lecture 2 – Discrete Math Revision Piotr Faliszewski

2 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

3 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 … + 2 n-1 = 2 n -1  Proof P(k) = [ … +2 k-1 = 2 k -1] Induction base 1 = Inductive step Hypothesis: There is a value k such that … +2 k-1 = 2 k -1 Step: Show that if the hypothesis holds then … +2 k = 2 k+1 -1

4 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

5 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.

6 Is Induction Really Correct?  Exercise: Prove that 2 n ≤ 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!

7 Is Induction Really Correct?  Exercise: Prove that 2 n ≤ 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!!!

8 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 Factorial 0! = 1 For 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.

9 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 that f(n) ≤ (5/3) n Show that 1 + ∑ 0 ≤ i ≤ n f i = f n+2

10 Recursive Definitions – Examples  Example Definition of |x| 1.|ε| = 0 2.|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. (x r ) Compute a reverse of a string based on this definition Prove that for every string x, |x| = |x r |

11 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.ε  L 2.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!

12 Recursive Definitions – Examples  Language L of all strings with as many 0s as 1s. (Σ = {0,1}) 1.ε  L 2.For any x in L it holds that each of: 0x1 1x0 01x 10x x01 x10 belongs to L. Is this definition correct?

13 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 c1c1 c2c2 c3c3 p

14 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 c1c1 c2c2 c3c3 p

15 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 c1c1 c2c2 c3c3 p

16 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 c1c1 c2c2 c3c3 p

17 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 c1c1 c2c2 c3c3 p

18 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! c1c1 c2c2 c3c3 p

19 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

20 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

21 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?


Download ppt "Introduction to CS Theory Lecture 2 – Discrete Math Revision Piotr Faliszewski"

Similar presentations


Ads by Google