lecture%2038%20 %20 the%20class%20p

52
The Class P Robb T. Koether Homework Review Introduction Comparison of Run Times Polynomial Time Exponential Time Factorial Time The Class P The PATH Problem The CFL Membership Problem Assignment The Class P Lecture 37 (38) Section 7.2 Robb T. Koether Hampden-Sydney College Fri, Nov 21, 2008 (Mon, Nov 24, 2008)

Upload: osam0

Post on 26-Jun-2015

254 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The Class PLecture 37 (38)

Section 7.2

Robb T. Koether

Hampden-Sydney College

Fri, Nov 21, 2008(Mon, Nov 24, 2008)

Page 2: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Outline

1 Homework Review

2 Introduction

3 Comparison of Run TimesPolynomial TimeExponential TimeFactorial Time

4 The Class PThe PATH ProblemThe CFL Membership Problem

5 Assignment

Page 3: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Homework Review

Exercise 7.1, page 294.

Answer each part TRUE or FALSE.(a) 2n = O(n).(b) n2 = O(n).(c) n2 = O(n log2 n).(d) n log n = O(n2).(e) 3n = 2O(n).(f) 22n

= O(22n).

Page 4: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Homework Review

Solution(a) TRUE.(b) FALSE.(c) FALSE.(d) TRUE.(e) TRUE.(f) TRUE.

Page 5: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Homework Review

SolutionThe only part that is not pretty clear is part (e).2O(n) means 2 raised to a function that is itself O(n).For example, 25n+3 is 2O(n).In part (e), use the fact that 3 = 2log2 3.It follows that 3n = 2(log2 3)n, so it is 2O(n).

Page 6: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Polynomial-Time Algorithms

Programs that run in polynomial time are consideredfeasible.For example, sorting long lists is feasible.Programs that run in exponential time are consideredinfeasible.For example, factoring large integers is infeasible.

Page 7: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Polynomial-Time Algorithms

Programs that run in polynomial time are consideredfeasible.For example, sorting long lists is feasible.Programs that run in exponential time are consideredinfeasible.For example, factoring large integers is infeasible.

Page 8: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Polynomial-Time Algorithms

Programs that run in polynomial time are consideredfeasible.For example, sorting long lists is feasible.Programs that run in exponential time are consideredinfeasible.For example, factoring large integers is infeasible.

Page 9: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Polynomial-Time Algorithms

Programs that run in polynomial time are consideredfeasible.For example, sorting long lists is feasible.Programs that run in exponential time are consideredinfeasible.For example, factoring large integers is infeasible.

Page 10: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Comparison of Run Times

Example (Polynomial Time)Suppose we have Turing machines M1, M2, and M3whose run times are O(n), O(n2), and O(n3),respectively.Suppose that each one takes 1 µs when the input sizeis n = 1000.

Page 11: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Comparison of Run Times

Example (Polynomial Time)

Input size M1 M2 M3

1000 1 µs 1 µs 1 µs104 10 µs 100 µs 1 ms105 100 µs 10 ms 1 s106 1 ms 1 s 1000 s107 10 ms 100 s 12 d108 100 ms 2.8 h 32 y109 1 s 12 d 32000 y

Page 12: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Comparison of Run Times

Example (Exponential Time)Suppose we have Turing machines M4 and M5 whoserun times are O(2n) and O(4n), respectively.Suppose that each one takes 1 µs when the input sizeis n = 1000.

Page 13: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Comparison of Run Times

Example (Exponential Time)

Input size M3 M4 M5

1000 1.03 µs 1 µs 1 µs1010 1.06 µs 1.02 ms 1.05 s1020 1.09 µs 1.05 s 13 d1030 1.12 µs 1073 s 37, 000 y1040 1.15 µs 13 d 38× 109 y1050 1.18 µs 36 y 40× 1015 y1060 1.21 µs 37, 000 y 42× 1021 y

Page 14: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Comparison of Run Times

Example (Factorial Time)Finally, suppose we have a Turing machine M6 whoserun time is O(n!) .Suppose that it takes 1 µs when the input size isn = 1000.

Page 15: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Comparison of Run Times

Example (Factorial Time)

Input size M5 M6

1000 1 µs 1 µs1001 4 µs 1.001 ms1002 16 µs 1.003 s1003 64 µs 16.8 m1004 256 µs 11.7 d1005 1.024 ms 32.2 y1006 4.096 ms 32, 381 y

Page 16: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The Class P

Definition (Class P)The class P is the class of all languages (i.e., problems) thatare decidable in polynomial time by a deterministicsingle-tape Turing machine.

P =∞⋃

k=0

TIME(nk).

Page 17: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The Class P

We have seen (will see) that if a problem can bedecided by a multitape Turing machine in polynomialtime O(t(n)), then it can be decided by a single-tapeTuring machine in time O(t2(n)), which is stillpolynomial.However, we have also seen (will also see) that aproblem that can be solved nondeterministically inpolynomial time can be solved deterministically inexponential time, but not necessarily in polynomial time.Factoring an integer is an example (as far as we know).

Page 18: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Polynomial Time

LemmaIf p(x) and q(x) are polynomials, then p(q(x)) is a polynomial.

Thus, if a polynomial-number of steps can each beperformed in polynomial time, then the entire processcan be done in polynomial time.

Page 19: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The PATH Problem

The PATH ProblemGiven a directed graph G and two vertices s and t, doesthere exist a directed path in G from s to t?

Page 20: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The PATH Problem

Example (The PATH Problem)Let G be the graph.Let m be the number of vertices in G.Let e(i, j) be true if there is an edge from vertex i tovertex j and false otherwise.Let s and t be the starting and ending vertices.

Page 21: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The PATH Problem

Example (The PATH Problem)

Begin at s and let M = {s}.Add to M all vertices that are adjacent to s (one edgeaway).Next, add to M all vertices that are adjacent to thosevertices that are already in M.Repeat the previous step until no new vertices areadded to M.See whether t ∈ M.

Page 22: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The PATH Problem

Example (The PATH Problem)Is t ∈ M? No.

s t

Page 23: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The PATH Problem

Example (The PATH Problem)Is t ∈ M? No.

s t

Page 24: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The PATH Problem

Example (The PATH Problem)Is t ∈ M? No.

s t

Page 25: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The PATH Problem

Example (The PATH Problem)Is t ∈ M? No.

s t

Page 26: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The PATH Problem

Example (The PATH Problem)Is t ∈ M? Yes.

s t

Page 27: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The PATH Problem

Example (The PATH Problem)Is t ∈ M? No.

s t

Page 28: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The PATH Problem

Example (The PATH Problem)Is t ∈ M? No.

s t

Page 29: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The PATH Problem

Example (The PATH Problem)Is t ∈ M? No.

s t

Page 30: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The PATH Problem

Example (The PATH Problem)Is t ∈ M? No.

s t

Page 31: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The PATH Problem

Example (The PATH Problem)Is t ∈ M? No.

s t

Page 32: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

An Algorithm for PATH

Example (The PATH Problem)PATH(graph G, vertex s, vertex t){

M = {s};M_old = {};while (M != M_old){

M_old = M;for (i = 0; i < m; i++)

for (j = 0; j < m; j++)if (e(i, j) ∈ E && i ∈ M && j /∈ M)

M = M ∪ {j};}if (t ∈ M)

accept();else

reject();}

Page 33: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

An Algorithm for PATH

Example (The PATH Problem)We can analyze each step in the function PATH().Each step is done in polynomial time.Thus, PATH ∈ P.

Page 34: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The CFL Membership Problem

The CFL Membership ProblemGiven a context-free language L and a word w, is w in L?

We may assume that we have a grammar for L inChomsky Normal Form.Let m be the length of the word w.

Page 35: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The CFL Membership Problem

Example (The CFL Membership Problem)Earlier we saw an algorithm for testing whether a wordw is derivable from a CNF grammar G.The algorithm pursued every possible derivation oflength 2m− 1.There problem is, the number of such derivations maybe exponential in m. (Why?)We need a different algorithm.

Page 36: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The CFL Membership Problem

Example (The CFL Membership Problem)Our strategy will be to begin with all one-symbolsubstrings of w that are derivable from G.These come directly from the rules of the form A→ a.Then proceed inductively.

Page 37: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The CFL Membership Problem

Example (The CFL Membership Problem)Let w = x1x2x3 . . . xm.Set up a table of size m× m.For all i ≤ j, table entry (i, j) is the set of all variables Ain G from which the substring xi . . . xj is derivable.For example,

Table entry (1, 1) = {A ∈ V | A ∗=⇒ x1}.Table entry (3, 5) = {A ∈ V | A ∗=⇒ x3x4x5}.Table entry (1,m) = {A ∈ V | A ∗=⇒ w}.

Page 38: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The CFL Membership Problem

Example (The CFL Membership Problem)Basic step:

Initialize table entries (i, i) to the set of all variables A forwhich there is a rule A→ xi.

Page 39: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Example

Example (The CFL Membership Problem)Let the grammar be

S → SS | aSb | bSa | ε

In CNF it is

S0 → SS | AX | YA | AB | BA | εS → SS | AX | YA | AB | BA

X → SB

Y → BS

A → aB → b

Page 40: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Example

Example (The CFL Membership Problem)For the word w = abbaba,

A

B

A

B

B

A

Page 41: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The CFL Membership Problem

Example (The CFL Membership Problem)Inductive step:

For each j ≥ 1, for each i < m, for each rule A→ BC,and for each k from i to i + j− 1,

See whether B is in table entry (i, k) and C is in tableentry (k + 1, i + j).

If so, then add A to table entry (i, i + j).

The idea is that if B ∗=⇒ xi . . . xk and C ∗=⇒ xk+1 . . . xi+j,then A⇒ BC ∗=⇒ xi . . . xi+j.

Page 42: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Example

Example (The CFL Membership Problem)For example, when j = 1, consider the case wherei = 1.In this case, i + j = 2, so k must equal 1.Table entry (1, 1) = {A} and table entry (2, 2) = {B}.There are rules S0 → AB and S→ AB.So table entry (1, 2) = {S0, S}.That is, S0

∗=⇒ ab and S ∗=⇒ ab.

Page 43: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Example

Example (The CFL Membership Problem)For j = 1,

A

B

A

B

B

A S0, S

S0, S

S0, S

S0, S

Page 44: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Example

Example (The CFL Membership Problem)When j = 2, consider the case where i = 1.In this case, i + j = 3, so k may equal 1 or 2.Case k = 1:

Table entry (1, 1) = {A} and table entry (2, 3) = ∅.This produces nothing.

Case k = 2:Table entry (1, 2) = {S0, S} and table entry (3, 3) = {B}.There is the rule X → SB.

So table entry (1, 3) = {X}.

That is, X 2=⇒ abb.

Page 45: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Example

Example (The CFL Membership Problem)For j = 2,

A S0, S

X, Y

S0, S

S0, S

S0, S

X

Y∅

A

A

B

B

B

Page 46: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Example

Example (The CFL Membership Problem)For j = 3,

A S0, S

X, Y

S0, S

S0, S

S0, S S0, S

S0, S

A

A

B

X

B

B

Y

Page 47: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Example

Example (The CFL Membership Problem)For j = 4,

A

B

A

B

B

A S0, S

X, Y

S0, S

S0, S

S0, S

X

Y

S0, S

S0, S X

Y∅

Page 48: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Example

Example (The CFL Membership Problem)For j = 5,

A

B

A

B

B

A S0, S

X, Y

S0, S

S0, S

S0, S

X

Y

S0, S

S0, S X

Y

S0, S

Page 49: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The CFL Membership Problem

Example (The CFL Membership Problem)Finally, see whether the start symbol is in table entry(1,m).If it is, then accept w.If it is not, the reject w.In the example, the start symbol S0 is in table entry(1, 6).

Page 50: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

An Algorithm for CFL

Example (The CFL Membership Problem)CFLMember(graph G, string w){

for (int i = 1; i <= m; i++)if ((A → w[i]) ∈ R)

Add A to table[i, i];for (int len = 2; len <= m; len++)

for (int i = 1; i <= m - len + 1; i++){

int j = i + len - 1;for (int k = i; k <= j - 1; k++)

for each ((A → BC) ∈ R)if (B ∈ table[i, k] && C ∈ table[k+1, j])

Add A to table[i, j];}

if (S ∈ table[1, m])accept();

elsereject();

}

Page 51: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

The CFL Membership Problem

Example (The CFL Membership Problem)We can analyze each step in the functionCFLMember().Each step is done in polynomial time.Thus, CFL ∈ P.

Page 52: Lecture%2038%20 %20 the%20class%20p

The Class P

Robb T.Koether

HomeworkReview

Introduction

Comparisonof Run TimesPolynomial Time

Exponential Time

Factorial Time

The Class PThe PATH Problem

The CFLMembership Problem

Assignment

Assignment

HomeworkRead Section 7.2, page256 - 263.Exercises 1, 2, 3, 4, 9, pages 294 - 295.Problem 12, page 295.