introduction to cs theory

21
Introduction to CS Theory Lecture 2 – Discrete Math Revision Piotr Faliszewski [email protected]

Upload: denton

Post on 30-Jan-2016

52 views

Category:

Documents


0 download

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 Presentation

TRANSCRIPT

Page 1: Introduction to CS Theory

Introduction to CS Theory

Lecture 2 – Discrete Math RevisionPiotr [email protected]

Page 2: Introduction to CS Theory

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

Page 3: Introduction to CS Theory

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

Page 4: Introduction to CS Theory

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

Page 5: Introduction to CS Theory

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.

Page 6: Introduction to CS Theory

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!

Page 7: Introduction to CS Theory

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!!!

Page 8: Introduction to CS Theory

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.

Page 9: Introduction to CS Theory

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

Page 10: Introduction to CS Theory

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|

Page 11: Introduction to CS Theory

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!

Page 12: Introduction to CS Theory

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?

Page 13: Introduction to CS Theory

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

Page 14: Introduction to CS Theory

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

Page 15: Introduction to CS Theory

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

Page 16: Introduction to CS Theory

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

Page 17: Introduction to CS Theory

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

Page 18: Introduction to CS Theory

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

Page 19: Introduction to CS Theory

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

Page 20: Introduction to CS Theory

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

Page 21: Introduction to CS Theory

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?