SlideShare a Scribd company logo
1 of 52
Download to read offline
The Class P

   Robb T.
   Koether

Homework
Review
                       The Class P
Introduction           Lecture 37 (38)
Comparison               Section 7.2
of Run Times
Polynomial Time
Exponential Time
Factorial Time


The Class P            Robb T. Koether
The PATH Problem
The CFL
Membership Problem   Hampden-Sydney College
Assignment

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

 The Class P

   Robb T.
   Koether
                     1   Homework Review
Homework
Review
                     2   Introduction
Introduction

Comparison
                     3   Comparison of Run Times
of Run Times               Polynomial Time
Polynomial Time
Exponential Time           Exponential Time
Factorial Time


The Class P
                           Factorial Time
The PATH Problem
The CFL
Membership Problem   4   The Class P
Assignment                 The PATH Problem
                           The CFL Membership Problem

                     5   Assignment
Homework Review

 The Class P

   Robb T.
   Koether

Homework             Exercise 7.1, page 294.
Review

Introduction
                     Answer each part TRUE or FALSE.
Comparison           (a) 2n = O(n).
of Run Times
Polynomial Time
Exponential Time
                     (b) n2 = O(n).
                     (c) n2 = O(n log2 n).
Factorial Time


The Class P
The PATH Problem
The CFL
                     (d) n log n = O(n2 ).
Membership Problem

Assignment
                     (e) 3n = 2O(n) .
                           n          n
                      (f) 22 = O(22 ).
Homework Review

 The Class P

   Robb T.
   Koether

Homework
Review               Solution
Introduction
                     (a) TRUE.
Comparison
of Run Times         (b) FALSE.
Polynomial Time
Exponential Time
Factorial Time
                     (c) FALSE.
The Class P          (d) TRUE.
The PATH Problem
The CFL
Membership Problem
                     (e) TRUE.
Assignment            (f) TRUE.
Homework Review

 The Class P

   Robb T.
   Koether

Homework
Review
                     Solution
Introduction

Comparison               The only part that is not pretty clear is part (e).
of Run Times
Polynomial Time          2O(n) means 2 raised to a function that is itself O(n).
Exponential Time
Factorial Time
                         For example, 25n+3 is 2O(n) .
The Class P
The PATH Problem         In part (e), use the fact that 3 = 2log2 3 .
The CFL
Membership Problem
                         It follows that 3n = 2(log2 3)n , so it is 2O(n) .
Assignment
Polynomial-Time Algorithms

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction
                         Programs that run in polynomial time are considered
Comparison               feasible.
of Run Times
Polynomial Time          For example, sorting long lists is feasible.
Exponential Time
Factorial Time
                         Programs that run in exponential time are considered
The Class P
The PATH Problem
                         infeasible.
The CFL
Membership Problem
                         For example, factoring large integers is infeasible.
Assignment
Polynomial-Time Algorithms

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction
                         Programs that run in polynomial time are considered
Comparison               feasible.
of Run Times
Polynomial Time          For example, sorting long lists is feasible.
Exponential Time
Factorial Time
                         Programs that run in exponential time are considered
The Class P
The PATH Problem
                         infeasible.
The CFL
Membership Problem
                         For example, factoring large integers is infeasible.
Assignment
Polynomial-Time Algorithms

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction
                         Programs that run in polynomial time are considered
Comparison               feasible.
of Run Times
Polynomial Time          For example, sorting long lists is feasible.
Exponential Time
Factorial Time
                         Programs that run in exponential time are considered
The Class P
The PATH Problem
                         infeasible.
The CFL
Membership Problem
                         For example, factoring large integers is infeasible.
Assignment
Polynomial-Time Algorithms

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction
                         Programs that run in polynomial time are considered
Comparison               feasible.
of Run Times
Polynomial Time          For example, sorting long lists is feasible.
Exponential Time
Factorial Time
                         Programs that run in exponential time are considered
The Class P
The PATH Problem
                         infeasible.
The CFL
Membership Problem
                         For example, factoring large integers is infeasible.
Assignment
Comparison of Run Times

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction         Example (Polynomial Time)
Comparison
of Run Times
                         Suppose we have Turing machines M1 , M2 , and M3
Polynomial Time
Exponential Time
                         whose run times are O(n), O(n2 ), and O(n3 ),
Factorial Time           respectively.
The Class P
The PATH Problem         Suppose that each one takes 1 Β΅s when the input size
The CFL
Membership Problem       is n = 1000.
Assignment
Comparison of Run Times

 The Class P

   Robb T.
   Koether

Homework             Example (Polynomial Time)
Review

Introduction                  Input size      M1      M2        M3
Comparison                       1000        1 Β΅s    1 Β΅s      1 Β΅s
of Run Times
Polynomial Time                   104       10 Β΅s   100 Β΅s     1 ms
Exponential Time
Factorial Time                    105      100 Β΅s   10 ms       1s
The Class P
The PATH Problem
                                  106       1 ms      1s      1000 s
The CFL
Membership Problem
                                  107      10 ms     100 s     12 d
Assignment                        108      100 ms    2.8 h     32 y
                                  109         1s     12 d    32000 y
Comparison of Run Times

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction
                     Example (Exponential Time)
Comparison
of Run Times             Suppose we have Turing machines M4 and M5 whose
Polynomial Time
Exponential Time         run times are O(2n ) and O(4n ), respectively.
Factorial Time


The Class P              Suppose that each one takes 1 Β΅s when the input size
The PATH Problem
The CFL
                         is n = 1000.
Membership Problem

Assignment
Comparison of Run Times

 The Class P

   Robb T.
   Koether

Homework             Example (Exponential Time)
Review

Introduction                Input size     M3         M4           M5
Comparison                     1000      1.03 Β΅s     1 Β΅s         1 Β΅s
of Run Times
Polynomial Time                1010      1.06 Β΅s   1.02 ms       1.05 s
Exponential Time
Factorial Time                 1020      1.09 Β΅s    1.05 s        13 d
The Class P
The PATH Problem
                               1030      1.12 Β΅s    1073 s      37, 000 y
The CFL
Membership Problem
                               1040      1.15 Β΅s     13 d      38 Γ— 109 y
Assignment                     1050      1.18 Β΅s     36 y      40 Γ— 1015 y
                               1060      1.21 Β΅s   37, 000 y   42 Γ— 1021 y
Comparison of Run Times

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction
                     Example (Factorial Time)
Comparison
of Run Times             Finally, suppose we have a Turing machine M6 whose
Polynomial Time
Exponential Time         run time is O(n!) .
Factorial Time


The Class P              Suppose that it takes 1 Β΅s when the input size is
The PATH Problem
The CFL
                         n = 1000.
Membership Problem

Assignment
Comparison of Run Times

 The Class P

   Robb T.
   Koether

Homework             Example (Factorial Time)
Review

Introduction                      Input size        M5         M6
Comparison                           1000          1 Β΅s       1 Β΅s
of Run Times
Polynomial Time                      1001          4 Β΅s    1.001 ms
Exponential Time
Factorial Time                       1002         16 Β΅s     1.003 s
The Class P
The PATH Problem
                                     1003         64 Β΅s     16.8 m
The CFL
Membership Problem
                                     1004        256 Β΅s     11.7 d
Assignment                           1005       1.024 ms     32.2 y
                                     1006       4.096 ms   32, 381 y
The Class P

 The Class P

   Robb T.
   Koether

Homework
Review
                     Definition (Class P)
Introduction

Comparison
                     The class P is the class of all languages (i.e., problems) that
of Run Times
Polynomial Time
                     are decidable in polynomial time by a deterministic
Exponential Time
Factorial Time
                     single-tape Turing machine.
The Class P                                     ∞
The PATH Problem
The CFL
Membership Problem
                                           P=         TIME(nk ).
Assignment                                      k=0
The Class P

 The Class P

   Robb T.
   Koether

Homework
                        We have seen (will see) that if a problem can be
Review                  decided by a multitape Turing machine in polynomial
Introduction
                        time O(t(n)), then it can be decided by a single-tape
Comparison
of Run Times            Turing machine in time O(t2 (n)), which is still
Polynomial Time
Exponential Time
                        polynomial.
Factorial Time


The Class P
                        However, we have also seen (will also see) that a
The PATH Problem        problem that can be solved nondeterministically in
The CFL
Membership Problem
                        polynomial time can be solved deterministically in
Assignment
                        exponential time, but not necessarily in polynomial time.
                        Factoring an integer is an example (as far as we know).
Polynomial Time

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction         Lemma
Comparison
of Run Times
                     If p(x) and q(x) are polynomials, then p(q(x)) is a polynomial.
Polynomial Time
Exponential Time
Factorial Time
                         Thus, if a polynomial-number of steps can each be
The Class P
The PATH Problem
                         performed in polynomial time, then the entire process
The CFL
Membership Problem       can be done in polynomial time.
Assignment
The PATH Problem

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction

Comparison
of Run Times
                     The PATH Problem
Polynomial Time
Exponential Time
                     Given a directed graph G and two vertices s and t, does
Factorial Time
                     there exist a directed path in G from s to t?
The Class P
The PATH Problem
The CFL
Membership Problem

Assignment
The PATH Problem

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction
                     Example (The PATH Problem)
Comparison              Let G be the graph.
of Run Times
Polynomial Time         Let m be the number of vertices in G.
Exponential Time
Factorial Time
                        Let e(i, j) be true if there is an edge from vertex i to
The Class P
The PATH Problem        vertex j and false otherwise.
The CFL
Membership Problem
                        Let s and t be the starting and ending vertices.
Assignment
The PATH Problem

 The Class P

   Robb T.
   Koether

Homework             Example (The PATH Problem)
Review

Introduction
                        Begin at s and let M = {s}.
Comparison              Add to M all vertices that are adjacent to s (one edge
of Run Times
Polynomial Time         away).
Exponential Time
Factorial Time          Next, add to M all vertices that are adjacent to those
The Class P
The PATH Problem
                        vertices that are already in M.
The CFL
Membership Problem      Repeat the previous step until no new vertices are
Assignment              added to M.
                        See whether t ∈ M.
The PATH Problem

 The Class P

   Robb T.
   Koether

Homework
Review
                     Example (The PATH Problem)
Introduction            Is t ∈ M? No.
Comparison
of Run Times
Polynomial Time
Exponential Time
Factorial Time


The Class P
The PATH Problem
                               s                  t
The CFL
Membership Problem

Assignment
The PATH Problem

 The Class P

   Robb T.
   Koether

Homework
Review
                     Example (The PATH Problem)
Introduction            Is t ∈ M? No.
Comparison
of Run Times
Polynomial Time
Exponential Time
Factorial Time


The Class P
The PATH Problem
                               s                  t
The CFL
Membership Problem

Assignment
The PATH Problem

 The Class P

   Robb T.
   Koether

Homework
Review
                     Example (The PATH Problem)
Introduction            Is t ∈ M? No.
Comparison
of Run Times
Polynomial Time
Exponential Time
Factorial Time


The Class P
The PATH Problem
                               s                  t
The CFL
Membership Problem

Assignment
The PATH Problem

 The Class P

   Robb T.
   Koether

Homework
Review
                     Example (The PATH Problem)
Introduction            Is t ∈ M? No.
Comparison
of Run Times
Polynomial Time
Exponential Time
Factorial Time


The Class P
The PATH Problem
                               s                  t
The CFL
Membership Problem

Assignment
The PATH Problem

 The Class P

   Robb T.
   Koether

Homework
Review
                     Example (The PATH Problem)
Introduction            Is t ∈ M? Yes.
Comparison
of Run Times
Polynomial Time
Exponential Time
Factorial Time


The Class P
The PATH Problem
                               s                  t
The CFL
Membership Problem

Assignment
The PATH Problem

 The Class P

   Robb T.
   Koether

Homework
Review
                     Example (The PATH Problem)
Introduction            Is t ∈ M? No.
Comparison
of Run Times
Polynomial Time
Exponential Time
Factorial Time


The Class P
The PATH Problem
                               s                  t
The CFL
Membership Problem

Assignment
The PATH Problem

 The Class P

   Robb T.
   Koether

Homework
Review
                     Example (The PATH Problem)
Introduction            Is t ∈ M? No.
Comparison
of Run Times
Polynomial Time
Exponential Time
Factorial Time


The Class P
The PATH Problem
                               s                  t
The CFL
Membership Problem

Assignment
The PATH Problem

 The Class P

   Robb T.
   Koether

Homework
Review
                     Example (The PATH Problem)
Introduction            Is t ∈ M? No.
Comparison
of Run Times
Polynomial Time
Exponential Time
Factorial Time


The Class P
The PATH Problem
                               s                  t
The CFL
Membership Problem

Assignment
The PATH Problem

 The Class P

   Robb T.
   Koether

Homework
Review
                     Example (The PATH Problem)
Introduction            Is t ∈ M? No.
Comparison
of Run Times
Polynomial Time
Exponential Time
Factorial Time


The Class P
The PATH Problem
                               s                  t
The CFL
Membership Problem

Assignment
The PATH Problem

 The Class P

   Robb T.
   Koether

Homework
Review
                     Example (The PATH Problem)
Introduction            Is t ∈ M? No.
Comparison
of Run Times
Polynomial Time
Exponential Time
Factorial Time


The Class P
The PATH Problem
                               s                  t
The CFL
Membership Problem

Assignment
An Algorithm for PATH

 The Class P

   Robb T.
   Koether           Example (The PATH Problem)
                     PATH(graph G, vertex s, vertex t)
Homework
Review
                     {
                         M = {s};
Introduction
                         M_old = {};
Comparison               while (M != M_old)
of Run Times             {
Polynomial Time
Exponential Time              M_old = M;
Factorial Time                for (i = 0; i < m; i++)
The Class P                       for (j = 0; j < m; j++)
The PATH Problem                      if (e(i, j) ∈ E && i ∈ M && j ∈ M)
                                                                    /
The CFL
Membership Problem                        M = M βˆͺ {j};
                         }
Assignment
                         if (t ∈ M)
                              accept();
                         else
                              reject();
                     }
An Algorithm for PATH

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction

Comparison
                     Example (The PATH Problem)
of Run Times
Polynomial Time
                         We can analyze each step in the function PATH().
Exponential Time
Factorial Time           Each step is done in polynomial time.
The Class P
The PATH Problem
                         Thus, PATH ∈ P.
The CFL
Membership Problem

Assignment
The CFL Membership Problem

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction
                     The CFL Membership Problem
Comparison           Given a context-free language L and a word w, is w in L?
of Run Times
Polynomial Time
Exponential Time
Factorial Time
                         We may assume that we have a grammar for L in
The Class P
The PATH Problem
                         Chomsky Normal Form.
The CFL
Membership Problem       Let m be the length of the word w.
Assignment
The CFL Membership Problem

 The Class P

   Robb T.
   Koether

Homework
Review
                     Example (The CFL Membership Problem)
Introduction            Earlier we saw an algorithm for testing whether a word
Comparison
of Run Times
                        w is derivable from a CNF grammar G.
Polynomial Time
Exponential Time
                        The algorithm pursued every possible derivation of
Factorial Time
                        length 2m βˆ’ 1.
The Class P
The PATH Problem        There problem is, the number of such derivations may
The CFL
Membership Problem
                        be exponential in m. (Why?)
Assignment
                        We need a different algorithm.
The CFL Membership Problem

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction         Example (The CFL Membership Problem)
Comparison
of Run Times            Our strategy will be to begin with all one-symbol
Polynomial Time
Exponential Time        substrings of w that are derivable from G.
Factorial Time


The Class P
                        These come directly from the rules of the form A β†’ a.
The PATH Problem
The CFL                 Then proceed inductively.
Membership Problem

Assignment
The CFL Membership Problem

 The Class P

   Robb T.
   Koether

Homework             Example (The CFL Membership Problem)
Review

Introduction
                        Let w = x1 x2 x3 . . . xm .
Comparison              Set up a table of size m Γ— m.
of Run Times
Polynomial Time
Exponential Time
                        For all i ≀ j, table entry (i, j) is the set of all variables A
Factorial Time          in G from which the substring xi . . . xj is derivable.
The Class P
The PATH Problem
                        For example,
The CFL                                                        βˆ—
Membership Problem           Table entry (1, 1) = {A ∈ V | A = x1 }.
                                                             β‡’
                                                             βˆ—
Assignment                   Table entry (3, 5) = {A ∈ V | A = x3 x4 x5 }.
                                                             β‡’
                                                              βˆ—
                             Table entry (1, m) = {A ∈ V | A = w}.
                                                             β‡’
The CFL Membership Problem

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction

Comparison           Example (The CFL Membership Problem)
of Run Times
Polynomial Time         Basic step:
Exponential Time
Factorial Time              Initialize table entries (i, i) to the set of all variables A for
The Class P                 which there is a rule A β†’ xi .
The PATH Problem
The CFL
Membership Problem

Assignment
Example

 The Class P

   Robb T.
                     Example (The CFL Membership Problem)
   Koether
                        Let the grammar be
Homework
Review
                                           S β†’ SS | aSb | bSa | Ξ΅
Introduction

Comparison
of Run Times            In CNF it is
Polynomial Time
Exponential Time
Factorial Time                         S0 β†’ SS | AX | YA | AB | BA | Ξ΅
The Class P
The PATH Problem                       S β†’ SS | AX | YA | AB | BA
The CFL
Membership Problem
                                       X β†’ SB
Assignment
                                       Y β†’ BS
                                       A β†’ a
                                       B β†’ b
Example

 The Class P

   Robb T.
   Koether
                     Example (The CFL Membership Problem)
Homework
                        For the word w = abbaba,
Review

Introduction

Comparison                     A
of Run Times
Polynomial Time
Exponential Time                     B
Factorial Time


The Class P                                B
The PATH Problem
The CFL
Membership Problem
                                                   A
Assignment
                                                       B

                                                            A
The CFL Membership Problem

 The Class P

   Robb T.
   Koether

Homework
Review
                     Example (The CFL Membership Problem)
Introduction            Inductive step:
Comparison                   For each j β‰₯ 1, for each i < m, for each rule A β†’ BC,
of Run Times
Polynomial Time
                             and for each k from i to i + j βˆ’ 1,
Exponential Time
                                  See whether B is in table entry (i, k) and C is in table
Factorial Time
                                  entry (k + 1, i + j).
The Class P
The PATH Problem             If so, then add A to table entry (i, i + j).
The CFL
Membership Problem                              βˆ—                     βˆ—
                                              β‡’                   β‡’
                        The idea is that if B = xi . . . xk and C = xk+1 . . . xi+j ,
Assignment                            βˆ—
                        then A β‡’ BC = xi . . . xi+j .
                                      β‡’
Example

 The Class P

   Robb T.
   Koether

Homework             Example (The CFL Membership Problem)
Review

Introduction            For example, when j = 1, consider the case where
Comparison              i = 1.
of Run Times
Polynomial Time         In this case, i + j = 2, so k must equal 1.
Exponential Time
Factorial Time
                        Table entry (1, 1) = {A} and table entry (2, 2) = {B}.
The Class P
The PATH Problem
The CFL
                        There are rules S0 β†’ AB and S β†’ AB.
Membership Problem
                        So table entry (1, 2) = {S0 , S}.
Assignment
                                    βˆ—             βˆ—
                                    β‡’          β‡’
                        That is, S0 = ab and S = ab.
Example

 The Class P

   Robb T.
   Koether
                     Example (The CFL Membership Problem)
Homework
                        For j = 1,
Review

Introduction

Comparison                     A     S0, S
of Run Times
Polynomial Time
Exponential Time                       B     βˆ…
Factorial Time


The Class P
The PATH Problem
                                             B   S0, S
The CFL
Membership Problem
                                                  A      S0, S
Assignment

                                                          B      S0, S

                                                                  A
Example

 The Class P

   Robb T.
   Koether
                     Example (The CFL Membership Problem)
Homework
Review
                        When j = 2, consider the case where i = 1.
Introduction            In this case, i + j = 3, so k may equal 1 or 2.
Comparison
of Run Times
                        Case k = 1:
Polynomial Time
Exponential Time
                            Table entry (1, 1) = {A} and table entry (2, 3) = βˆ….
Factorial Time              This produces nothing.
The Class P
The PATH Problem
                        Case k = 2:
The CFL
Membership Problem          Table entry (1, 2) = {S0 , S} and table entry (3, 3) = {B}.
Assignment                  There is the rule X β†’ SB.
                        So table entry (1, 3) = {X}.
                                   2
                                   β‡’
                        That is, X = abb.
Example

 The Class P

   Robb T.
   Koether
                     Example (The CFL Membership Problem)
Homework
                        For j = 2,
Review

Introduction

Comparison                     A     S0, S   X
of Run Times
Polynomial Time
Exponential Time                      B      βˆ…    Y
Factorial Time


The Class P
The PATH Problem
                                             B   S0, S   X, Y
The CFL
Membership Problem
                                                  A      S0, S    βˆ…
Assignment

                                                          B      S0, S

                                                                  A
Example

 The Class P

   Robb T.
   Koether
                     Example (The CFL Membership Problem)
Homework
                        For j = 3,
Review

Introduction

Comparison                     A     S0, S   X   S0, S
of Run Times
Polynomial Time
Exponential Time                      B      βˆ…    Y       βˆ…
Factorial Time


The Class P
The PATH Problem
                                             B   S0, S   X, Y    S0, S
The CFL
Membership Problem
                                                  A      S0, S    βˆ…
Assignment

                                                          B      S0, S

                                                                  A
Example

 The Class P

   Robb T.
   Koether
                     Example (The CFL Membership Problem)
Homework
                        For j = 4,
Review

Introduction

Comparison                     A     S0, S   X   S0, S    X
of Run Times
Polynomial Time
Exponential Time                       B     βˆ…    Y       βˆ…       Y
Factorial Time


The Class P
The PATH Problem
                                             B   S0, S   X, Y    S0, S
The CFL
Membership Problem
                                                  A      S0, S    βˆ…
Assignment

                                                          B      S0, S

                                                                  A
Example

 The Class P

   Robb T.
   Koether
                     Example (The CFL Membership Problem)
Homework
                        For j = 5,
Review

Introduction

Comparison                     A     S0, S   X   S0, S    X      S0, S
of Run Times
Polynomial Time
Exponential Time                       B     βˆ…    Y       βˆ…       Y
Factorial Time


The Class P
The PATH Problem
                                             B   S0, S   X, Y    S0, S
The CFL
Membership Problem
                                                  A      S0, S    βˆ…
Assignment

                                                          B      S0, S

                                                                  A
The CFL Membership Problem

 The Class P

   Robb T.
   Koether

Homework
Review               Example (The CFL Membership Problem)
Introduction
                        Finally, see whether the start symbol is in table entry
Comparison
of Run Times            (1, m).
Polynomial Time
Exponential Time
Factorial Time
                        If it is, then accept w.
The Class P             If it is not, the reject w.
The PATH Problem
The CFL
Membership Problem
                        In the example, the start symbol S0 is in table entry
Assignment              (1, 6).
An Algorithm for CFL

 The Class P

   Robb T.           Example (The CFL Membership Problem)
   Koether
                     CFLMember(graph G, string w)
Homework
                     {
Review                   for (int i = 1; i <= m; i++)
                              if ((A β†’ w[i]) ∈ R)
Introduction
                                  Add A to table[i, i];
Comparison               for (int len = 2; len <= m; len++)
of Run Times
Polynomial Time
                              for (int i = 1; i <= m - len + 1; i++)
Exponential Time              {
Factorial Time
                                  int j = i + len - 1;
The Class P                       for (int k = i; k <= j - 1; k++)
The PATH Problem
                                      for each ((A β†’ BC) ∈ R)
The CFL
Membership Problem                        if (B ∈ table[i, k] && C ∈ table[k+1, j])
Assignment                                    Add A to table[i, j];
                              }
                         if (S ∈ table[1, m])
                              accept();
                         else
                              reject();
                     }
The CFL Membership Problem

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction         Example (The CFL Membership Problem)
Comparison
of Run Times            We can analyze each step in the function
Polynomial Time
Exponential Time        CFLMember().
Factorial Time


The Class P
                        Each step is done in polynomial time.
The PATH Problem
The CFL                 Thus, CFL ∈ P.
Membership Problem

Assignment
Assignment

 The Class P

   Robb T.
   Koether

Homework
Review

Introduction
                     Homework
Comparison
of Run Times
Polynomial Time
                        Read Section 7.2, page256 - 263.
Exponential Time
Factorial Time           Exercises 1, 2, 3, 4, 9, pages 294 - 295.
The Class P
The PATH Problem
                         Problem 12, page 295.
The CFL
Membership Problem

Assignment

More Related Content

Viewers also liked

Outline Res Meth 2010 Spring Feb01
Outline Res Meth 2010 Spring Feb01Outline Res Meth 2010 Spring Feb01
Outline Res Meth 2010 Spring Feb01Yender McLee
Β 
Ijpar 13 506 sujatha
Ijpar 13 506 sujathaIjpar 13 506 sujatha
Ijpar 13 506 sujathapharmaindexing
Β 
Application of toolbox so far… how to benefit from tool box in education
Application of toolbox so far… how to benefit from tool box in educationApplication of toolbox so far… how to benefit from tool box in education
Application of toolbox so far… how to benefit from tool box in educationGlobal Water Partnership
Β 
Scott findlay critical habitat and recovery
Scott findlay critical habitat and recoveryScott findlay critical habitat and recovery
Scott findlay critical habitat and recoverySustainable Prosperity
Β 
Chris morgan presenting - 2011
Chris morgan   presenting - 2011Chris morgan   presenting - 2011
Chris morgan presenting - 2011Ray Poynter
Β 
Modern Jago Session One UX
Modern Jago Session One UXModern Jago Session One UX
Modern Jago Session One UXModernJago
Β 
Humber trends presentation
Humber trends presentationHumber trends presentation
Humber trends presentationRon Nurwisah
Β 
JavaOne 2007 BOF Session
JavaOne 2007 BOF SessionJavaOne 2007 BOF Session
JavaOne 2007 BOF SessionJeff Hoffman
Β 
κΉ€μˆ˜μ§€
κΉ€μˆ˜μ§€κΉ€μˆ˜μ§€
κΉ€μˆ˜μ§€Suzie Kim
Β 
Life sutra
Life sutraLife sutra
Life sutrajanesha123
Β 
Analgesia And Anesthesia For The Breastfeeding Mother
Analgesia And Anesthesia For The Breastfeeding MotherAnalgesia And Anesthesia For The Breastfeeding Mother
Analgesia And Anesthesia For The Breastfeeding MotherBiblioteca Virtual
Β 
Txt2calm
Txt2calmTxt2calm
Txt2calmtimpj
Β 

Viewers also liked (16)

Outline Res Meth 2010 Spring Feb01
Outline Res Meth 2010 Spring Feb01Outline Res Meth 2010 Spring Feb01
Outline Res Meth 2010 Spring Feb01
Β 
Ijpar 13 506 sujatha
Ijpar 13 506 sujathaIjpar 13 506 sujatha
Ijpar 13 506 sujatha
Β 
Application of toolbox so far… how to benefit from tool box in education
Application of toolbox so far… how to benefit from tool box in educationApplication of toolbox so far… how to benefit from tool box in education
Application of toolbox so far… how to benefit from tool box in education
Β 
Polynomial
PolynomialPolynomial
Polynomial
Β 
Scott findlay critical habitat and recovery
Scott findlay critical habitat and recoveryScott findlay critical habitat and recovery
Scott findlay critical habitat and recovery
Β 
EEX 504 TRANSITION CHAP. 1
EEX 504 TRANSITION CHAP. 1EEX 504 TRANSITION CHAP. 1
EEX 504 TRANSITION CHAP. 1
Β 
Risk Management Summit
Risk Management SummitRisk Management Summit
Risk Management Summit
Β 
Chris morgan presenting - 2011
Chris morgan   presenting - 2011Chris morgan   presenting - 2011
Chris morgan presenting - 2011
Β 
Modern Jago Session One UX
Modern Jago Session One UXModern Jago Session One UX
Modern Jago Session One UX
Β 
Humber trends presentation
Humber trends presentationHumber trends presentation
Humber trends presentation
Β 
JavaOne 2007 BOF Session
JavaOne 2007 BOF SessionJavaOne 2007 BOF Session
JavaOne 2007 BOF Session
Β 
κΉ€μˆ˜μ§€
κΉ€μˆ˜μ§€κΉ€μˆ˜μ§€
κΉ€μˆ˜μ§€
Β 
Physical fitnes
Physical fitnesPhysical fitnes
Physical fitnes
Β 
Life sutra
Life sutraLife sutra
Life sutra
Β 
Analgesia And Anesthesia For The Breastfeeding Mother
Analgesia And Anesthesia For The Breastfeeding MotherAnalgesia And Anesthesia For The Breastfeeding Mother
Analgesia And Anesthesia For The Breastfeeding Mother
Β 
Txt2calm
Txt2calmTxt2calm
Txt2calm
Β 

Similar to Lecture%2038%20 %20 the%20class%20p

Time_Complexity.pptx
Time_Complexity.pptxTime_Complexity.pptx
Time_Complexity.pptxvivekcommon
Β 
Intro to modelling_wur
Intro to modelling_wurIntro to modelling_wur
Intro to modelling_wuriGEMWageningenUR
Β 
Np completeness
Np completenessNp completeness
Np completenessRajendran
Β 
7._Representing_Real_Life_Situations_Using_Rational_Functions.pptx.pdf
7._Representing_Real_Life_Situations_Using_Rational_Functions.pptx.pdf7._Representing_Real_Life_Situations_Using_Rational_Functions.pptx.pdf
7._Representing_Real_Life_Situations_Using_Rational_Functions.pptx.pdfCharlesBuale1
Β 
Computational Complexity: Oracles and the Polynomial Hierarchy
Computational Complexity: Oracles and the Polynomial HierarchyComputational Complexity: Oracles and the Polynomial Hierarchy
Computational Complexity: Oracles and the Polynomial HierarchyAntonis Antonopoulos
Β 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexityAnkit Katiyar
Β 
Me330 lecture3
Me330 lecture3Me330 lecture3
Me330 lecture3Andy Norris
Β 
Complexity analysis - The Big O Notation
Complexity analysis - The Big O NotationComplexity analysis - The Big O Notation
Complexity analysis - The Big O NotationJawad Khan
Β 

Similar to Lecture%2038%20 %20 the%20class%20p (10)

AA ppt9107
AA ppt9107AA ppt9107
AA ppt9107
Β 
Time_Complexity.pptx
Time_Complexity.pptxTime_Complexity.pptx
Time_Complexity.pptx
Β 
Intro to modelling_wur
Intro to modelling_wurIntro to modelling_wur
Intro to modelling_wur
Β 
Np completeness
Np completenessNp completeness
Np completeness
Β 
7._Representing_Real_Life_Situations_Using_Rational_Functions.pptx.pdf
7._Representing_Real_Life_Situations_Using_Rational_Functions.pptx.pdf7._Representing_Real_Life_Situations_Using_Rational_Functions.pptx.pdf
7._Representing_Real_Life_Situations_Using_Rational_Functions.pptx.pdf
Β 
Computational Complexity: Oracles and the Polynomial Hierarchy
Computational Complexity: Oracles and the Polynomial HierarchyComputational Complexity: Oracles and the Polynomial Hierarchy
Computational Complexity: Oracles and the Polynomial Hierarchy
Β 
class23.ppt
class23.pptclass23.ppt
class23.ppt
Β 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
Β 
Me330 lecture3
Me330 lecture3Me330 lecture3
Me330 lecture3
Β 
Complexity analysis - The Big O Notation
Complexity analysis - The Big O NotationComplexity analysis - The Big O Notation
Complexity analysis - The Big O Notation
Β 

Recently uploaded

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
Β 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
Β 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
Β 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
Β 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
Β 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
Β 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
Β 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
Β 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
Β 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
Β 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
Β 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
Β 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
Β 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
Β 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
Β 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
Β 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
Β 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
Β 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
Β 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
Β 

Recently uploaded (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Β 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
Β 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Β 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Β 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
Β 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
Β 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
Β 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Β 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
Β 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Β 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
Β 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
Β 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Β 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
Β 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
Β 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
Β 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
Β 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
Β 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Β 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
Β 

Lecture%2038%20 %20 the%20class%20p

  • 1. The Class P Robb T. Koether Homework Review The Class P Introduction Lecture 37 (38) Comparison Section 7.2 of Run Times Polynomial Time Exponential Time Factorial Time The Class P Robb T. Koether The PATH Problem The CFL Membership Problem Hampden-Sydney College Assignment Fri, Nov 21, 2008 (Mon, Nov 24, 2008)
  • 2. Outline The Class P Robb T. Koether 1 Homework Review Homework Review 2 Introduction Introduction Comparison 3 Comparison of Run Times of Run Times Polynomial Time Polynomial Time Exponential Time Exponential Time Factorial Time The Class P Factorial Time The PATH Problem The CFL Membership Problem 4 The Class P Assignment The PATH Problem The CFL Membership Problem 5 Assignment
  • 3. Homework Review The Class P Robb T. Koether Homework Exercise 7.1, page 294. Review Introduction Answer each part TRUE or FALSE. Comparison (a) 2n = O(n). of Run Times Polynomial Time Exponential Time (b) n2 = O(n). (c) n2 = O(n log2 n). Factorial Time The Class P The PATH Problem The CFL (d) n log n = O(n2 ). Membership Problem Assignment (e) 3n = 2O(n) . n n (f) 22 = O(22 ).
  • 4. Homework Review The Class P Robb T. Koether Homework Review Solution Introduction (a) TRUE. Comparison of Run Times (b) FALSE. Polynomial Time Exponential Time Factorial Time (c) FALSE. The Class P (d) TRUE. The PATH Problem The CFL Membership Problem (e) TRUE. Assignment (f) TRUE.
  • 5. Homework Review The Class P Robb T. Koether Homework Review Solution Introduction Comparison The only part that is not pretty clear is part (e). of Run Times Polynomial Time 2O(n) means 2 raised to a function that is itself O(n). Exponential Time Factorial Time For example, 25n+3 is 2O(n) . The Class P The PATH Problem In part (e), use the fact that 3 = 2log2 3 . The CFL Membership Problem It follows that 3n = 2(log2 3)n , so it is 2O(n) . Assignment
  • 6. Polynomial-Time Algorithms The Class P Robb T. Koether Homework Review Introduction Programs that run in polynomial time are considered Comparison feasible. of Run Times Polynomial Time For example, sorting long lists is feasible. Exponential Time Factorial Time Programs that run in exponential time are considered The Class P The PATH Problem infeasible. The CFL Membership Problem For example, factoring large integers is infeasible. Assignment
  • 7. Polynomial-Time Algorithms The Class P Robb T. Koether Homework Review Introduction Programs that run in polynomial time are considered Comparison feasible. of Run Times Polynomial Time For example, sorting long lists is feasible. Exponential Time Factorial Time Programs that run in exponential time are considered The Class P The PATH Problem infeasible. The CFL Membership Problem For example, factoring large integers is infeasible. Assignment
  • 8. Polynomial-Time Algorithms The Class P Robb T. Koether Homework Review Introduction Programs that run in polynomial time are considered Comparison feasible. of Run Times Polynomial Time For example, sorting long lists is feasible. Exponential Time Factorial Time Programs that run in exponential time are considered The Class P The PATH Problem infeasible. The CFL Membership Problem For example, factoring large integers is infeasible. Assignment
  • 9. Polynomial-Time Algorithms The Class P Robb T. Koether Homework Review Introduction Programs that run in polynomial time are considered Comparison feasible. of Run Times Polynomial Time For example, sorting long lists is feasible. Exponential Time Factorial Time Programs that run in exponential time are considered The Class P The PATH Problem infeasible. The CFL Membership Problem For example, factoring large integers is infeasible. Assignment
  • 10. Comparison of Run Times The Class P Robb T. Koether Homework Review Introduction Example (Polynomial Time) Comparison of Run Times Suppose we have Turing machines M1 , M2 , and M3 Polynomial Time Exponential Time whose run times are O(n), O(n2 ), and O(n3 ), Factorial Time respectively. The Class P The PATH Problem Suppose that each one takes 1 Β΅s when the input size The CFL Membership Problem is n = 1000. Assignment
  • 11. Comparison of Run Times The Class P Robb T. Koether Homework Example (Polynomial Time) Review Introduction Input size M1 M2 M3 Comparison 1000 1 Β΅s 1 Β΅s 1 Β΅s of Run Times Polynomial Time 104 10 Β΅s 100 Β΅s 1 ms Exponential Time Factorial Time 105 100 Β΅s 10 ms 1s The Class P The PATH Problem 106 1 ms 1s 1000 s The CFL Membership Problem 107 10 ms 100 s 12 d Assignment 108 100 ms 2.8 h 32 y 109 1s 12 d 32000 y
  • 12. Comparison of Run Times The Class P Robb T. Koether Homework Review Introduction Example (Exponential Time) Comparison of Run Times Suppose we have Turing machines M4 and M5 whose Polynomial Time Exponential Time run times are O(2n ) and O(4n ), respectively. Factorial Time The Class P Suppose that each one takes 1 Β΅s when the input size The PATH Problem The CFL is n = 1000. Membership Problem Assignment
  • 13. Comparison of Run Times The Class P Robb T. Koether Homework Example (Exponential Time) Review Introduction Input size M3 M4 M5 Comparison 1000 1.03 Β΅s 1 Β΅s 1 Β΅s of Run Times Polynomial Time 1010 1.06 Β΅s 1.02 ms 1.05 s Exponential Time Factorial Time 1020 1.09 Β΅s 1.05 s 13 d The Class P The PATH Problem 1030 1.12 Β΅s 1073 s 37, 000 y The CFL Membership Problem 1040 1.15 Β΅s 13 d 38 Γ— 109 y Assignment 1050 1.18 Β΅s 36 y 40 Γ— 1015 y 1060 1.21 Β΅s 37, 000 y 42 Γ— 1021 y
  • 14. Comparison of Run Times The Class P Robb T. Koether Homework Review Introduction Example (Factorial Time) Comparison of Run Times Finally, suppose we have a Turing machine M6 whose Polynomial Time Exponential Time run time is O(n!) . Factorial Time The Class P Suppose that it takes 1 Β΅s when the input size is The PATH Problem The CFL n = 1000. Membership Problem Assignment
  • 15. Comparison of Run Times The Class P Robb T. Koether Homework Example (Factorial Time) Review Introduction Input size M5 M6 Comparison 1000 1 Β΅s 1 Β΅s of Run Times Polynomial Time 1001 4 Β΅s 1.001 ms Exponential Time Factorial Time 1002 16 Β΅s 1.003 s The Class P The PATH Problem 1003 64 Β΅s 16.8 m The CFL Membership Problem 1004 256 Β΅s 11.7 d Assignment 1005 1.024 ms 32.2 y 1006 4.096 ms 32, 381 y
  • 16. The Class P The Class P Robb T. Koether Homework Review Definition (Class P) Introduction Comparison The class P is the class of all languages (i.e., problems) that of Run Times Polynomial Time are decidable in polynomial time by a deterministic Exponential Time Factorial Time single-tape Turing machine. The Class P ∞ The PATH Problem The CFL Membership Problem P= TIME(nk ). Assignment k=0
  • 17. The Class P The Class P Robb T. Koether Homework We have seen (will see) that if a problem can be Review decided by a multitape Turing machine in polynomial Introduction time O(t(n)), then it can be decided by a single-tape Comparison of Run Times Turing machine in time O(t2 (n)), which is still Polynomial Time Exponential Time polynomial. Factorial Time The Class P However, we have also seen (will also see) that a The PATH Problem problem that can be solved nondeterministically in The CFL Membership Problem polynomial time can be solved deterministically in Assignment exponential time, but not necessarily in polynomial time. Factoring an integer is an example (as far as we know).
  • 18. Polynomial Time The Class P Robb T. Koether Homework Review Introduction Lemma Comparison of Run Times If p(x) and q(x) are polynomials, then p(q(x)) is a polynomial. Polynomial Time Exponential Time Factorial Time Thus, if a polynomial-number of steps can each be The Class P The PATH Problem performed in polynomial time, then the entire process The CFL Membership Problem can be done in polynomial time. Assignment
  • 19. The PATH Problem The Class P Robb T. Koether Homework Review Introduction Comparison of Run Times The PATH Problem Polynomial Time Exponential Time Given a directed graph G and two vertices s and t, does Factorial Time there exist a directed path in G from s to t? The Class P The PATH Problem The CFL Membership Problem Assignment
  • 20. The PATH Problem The Class P Robb T. Koether Homework Review Introduction Example (The PATH Problem) Comparison Let G be the graph. of Run Times Polynomial Time Let m be the number of vertices in G. Exponential Time Factorial Time Let e(i, j) be true if there is an edge from vertex i to The Class P The PATH Problem vertex j and false otherwise. The CFL Membership Problem Let s and t be the starting and ending vertices. Assignment
  • 21. The PATH Problem The Class P Robb T. Koether Homework Example (The PATH Problem) Review Introduction Begin at s and let M = {s}. Comparison Add to M all vertices that are adjacent to s (one edge of Run Times Polynomial Time away). Exponential Time Factorial Time Next, add to M all vertices that are adjacent to those The Class P The PATH Problem vertices that are already in M. The CFL Membership Problem Repeat the previous step until no new vertices are Assignment added to M. See whether t ∈ M.
  • 22. The PATH Problem The Class P Robb T. Koether Homework Review Example (The PATH Problem) Introduction Is t ∈ M? No. Comparison of Run Times Polynomial Time Exponential Time Factorial Time The Class P The PATH Problem s t The CFL Membership Problem Assignment
  • 23. The PATH Problem The Class P Robb T. Koether Homework Review Example (The PATH Problem) Introduction Is t ∈ M? No. Comparison of Run Times Polynomial Time Exponential Time Factorial Time The Class P The PATH Problem s t The CFL Membership Problem Assignment
  • 24. The PATH Problem The Class P Robb T. Koether Homework Review Example (The PATH Problem) Introduction Is t ∈ M? No. Comparison of Run Times Polynomial Time Exponential Time Factorial Time The Class P The PATH Problem s t The CFL Membership Problem Assignment
  • 25. The PATH Problem The Class P Robb T. Koether Homework Review Example (The PATH Problem) Introduction Is t ∈ M? No. Comparison of Run Times Polynomial Time Exponential Time Factorial Time The Class P The PATH Problem s t The CFL Membership Problem Assignment
  • 26. The PATH Problem The Class P Robb T. Koether Homework Review Example (The PATH Problem) Introduction Is t ∈ M? Yes. Comparison of Run Times Polynomial Time Exponential Time Factorial Time The Class P The PATH Problem s t The CFL Membership Problem Assignment
  • 27. The PATH Problem The Class P Robb T. Koether Homework Review Example (The PATH Problem) Introduction Is t ∈ M? No. Comparison of Run Times Polynomial Time Exponential Time Factorial Time The Class P The PATH Problem s t The CFL Membership Problem Assignment
  • 28. The PATH Problem The Class P Robb T. Koether Homework Review Example (The PATH Problem) Introduction Is t ∈ M? No. Comparison of Run Times Polynomial Time Exponential Time Factorial Time The Class P The PATH Problem s t The CFL Membership Problem Assignment
  • 29. The PATH Problem The Class P Robb T. Koether Homework Review Example (The PATH Problem) Introduction Is t ∈ M? No. Comparison of Run Times Polynomial Time Exponential Time Factorial Time The Class P The PATH Problem s t The CFL Membership Problem Assignment
  • 30. The PATH Problem The Class P Robb T. Koether Homework Review Example (The PATH Problem) Introduction Is t ∈ M? No. Comparison of Run Times Polynomial Time Exponential Time Factorial Time The Class P The PATH Problem s t The CFL Membership Problem Assignment
  • 31. The PATH Problem The Class P Robb T. Koether Homework Review Example (The PATH Problem) Introduction Is t ∈ M? No. Comparison of Run Times Polynomial Time Exponential Time Factorial Time The Class P The PATH Problem s t The CFL Membership Problem Assignment
  • 32. An Algorithm for PATH The Class P Robb T. Koether Example (The PATH Problem) PATH(graph G, vertex s, vertex t) Homework Review { M = {s}; Introduction M_old = {}; Comparison while (M != M_old) of Run Times { Polynomial Time Exponential Time M_old = M; Factorial Time for (i = 0; i < m; i++) The Class P for (j = 0; j < m; j++) The PATH Problem if (e(i, j) ∈ E && i ∈ M && j ∈ M) / The CFL Membership Problem M = M βˆͺ {j}; } Assignment if (t ∈ M) accept(); else reject(); }
  • 33. An Algorithm for PATH The Class P Robb T. Koether Homework Review Introduction Comparison Example (The PATH Problem) of Run Times Polynomial Time We can analyze each step in the function PATH(). Exponential Time Factorial Time Each step is done in polynomial time. The Class P The PATH Problem Thus, PATH ∈ P. The CFL Membership Problem Assignment
  • 34. The CFL Membership Problem The Class P Robb T. Koether Homework Review Introduction The CFL Membership Problem Comparison Given a context-free language L and a word w, is w in L? of Run Times Polynomial Time Exponential Time Factorial Time We may assume that we have a grammar for L in The Class P The PATH Problem Chomsky Normal Form. The CFL Membership Problem Let m be the length of the word w. Assignment
  • 35. The CFL Membership Problem The Class P Robb T. Koether Homework Review Example (The CFL Membership Problem) Introduction Earlier we saw an algorithm for testing whether a word Comparison of Run Times w is derivable from a CNF grammar G. Polynomial Time Exponential Time The algorithm pursued every possible derivation of Factorial Time length 2m βˆ’ 1. The Class P The PATH Problem There problem is, the number of such derivations may The CFL Membership Problem be exponential in m. (Why?) Assignment We need a different algorithm.
  • 36. The CFL Membership Problem The Class P Robb T. Koether Homework Review Introduction Example (The CFL Membership Problem) Comparison of Run Times Our strategy will be to begin with all one-symbol Polynomial Time Exponential Time substrings of w that are derivable from G. Factorial Time The Class P These come directly from the rules of the form A β†’ a. The PATH Problem The CFL Then proceed inductively. Membership Problem Assignment
  • 37. The CFL Membership Problem The Class P Robb T. Koether Homework Example (The CFL Membership Problem) Review Introduction Let w = x1 x2 x3 . . . xm . Comparison Set up a table of size m Γ— m. of Run Times Polynomial Time Exponential Time For all i ≀ j, table entry (i, j) is the set of all variables A Factorial Time in G from which the substring xi . . . xj is derivable. The Class P The PATH Problem For example, The CFL βˆ— Membership Problem Table entry (1, 1) = {A ∈ V | A = x1 }. β‡’ βˆ— Assignment Table entry (3, 5) = {A ∈ V | A = x3 x4 x5 }. β‡’ βˆ— Table entry (1, m) = {A ∈ V | A = w}. β‡’
  • 38. The CFL Membership Problem The Class P Robb T. Koether Homework Review Introduction Comparison Example (The CFL Membership Problem) of Run Times Polynomial Time Basic step: Exponential Time Factorial Time Initialize table entries (i, i) to the set of all variables A for The Class P which there is a rule A β†’ xi . The PATH Problem The CFL Membership Problem Assignment
  • 39. Example The Class P Robb T. Example (The CFL Membership Problem) Koether Let the grammar be Homework Review S β†’ SS | aSb | bSa | Ξ΅ Introduction Comparison of Run Times In CNF it is Polynomial Time Exponential Time Factorial Time S0 β†’ SS | AX | YA | AB | BA | Ξ΅ The Class P The PATH Problem S β†’ SS | AX | YA | AB | BA The CFL Membership Problem X β†’ SB Assignment Y β†’ BS A β†’ a B β†’ b
  • 40. Example The Class P Robb T. Koether Example (The CFL Membership Problem) Homework For the word w = abbaba, Review Introduction Comparison A of Run Times Polynomial Time Exponential Time B Factorial Time The Class P B The PATH Problem The CFL Membership Problem A Assignment B A
  • 41. The CFL Membership Problem The Class P Robb T. Koether Homework Review Example (The CFL Membership Problem) Introduction Inductive step: Comparison For each j β‰₯ 1, for each i < m, for each rule A β†’ BC, of Run Times Polynomial Time and for each k from i to i + j βˆ’ 1, Exponential Time See whether B is in table entry (i, k) and C is in table Factorial Time entry (k + 1, i + j). The Class P The PATH Problem If so, then add A to table entry (i, i + j). The CFL Membership Problem βˆ— βˆ— β‡’ β‡’ The idea is that if B = xi . . . xk and C = xk+1 . . . xi+j , Assignment βˆ— then A β‡’ BC = xi . . . xi+j . β‡’
  • 42. Example The Class P Robb T. Koether Homework Example (The CFL Membership Problem) Review Introduction For example, when j = 1, consider the case where Comparison i = 1. of Run Times Polynomial Time In this case, i + j = 2, so k must equal 1. Exponential Time Factorial Time Table entry (1, 1) = {A} and table entry (2, 2) = {B}. The Class P The PATH Problem The CFL There are rules S0 β†’ AB and S β†’ AB. Membership Problem So table entry (1, 2) = {S0 , S}. Assignment βˆ— βˆ— β‡’ β‡’ That is, S0 = ab and S = ab.
  • 43. Example The Class P Robb T. Koether Example (The CFL Membership Problem) Homework For j = 1, Review Introduction Comparison A S0, S of Run Times Polynomial Time Exponential Time B βˆ… Factorial Time The Class P The PATH Problem B S0, S The CFL Membership Problem A S0, S Assignment B S0, S A
  • 44. Example The Class P Robb T. Koether Example (The CFL Membership Problem) Homework Review When j = 2, consider the case where i = 1. Introduction In this case, i + j = 3, so k may equal 1 or 2. Comparison of Run Times Case k = 1: Polynomial Time Exponential Time Table entry (1, 1) = {A} and table entry (2, 3) = βˆ…. Factorial Time This produces nothing. The Class P The PATH Problem Case k = 2: The CFL Membership Problem Table entry (1, 2) = {S0 , S} and table entry (3, 3) = {B}. Assignment There is the rule X β†’ SB. So table entry (1, 3) = {X}. 2 β‡’ That is, X = abb.
  • 45. Example The Class P Robb T. Koether Example (The CFL Membership Problem) Homework For j = 2, Review Introduction Comparison A S0, S X of Run Times Polynomial Time Exponential Time B βˆ… Y Factorial Time The Class P The PATH Problem B S0, S X, Y The CFL Membership Problem A S0, S βˆ… Assignment B S0, S A
  • 46. Example The Class P Robb T. Koether Example (The CFL Membership Problem) Homework For j = 3, Review Introduction Comparison A S0, S X S0, S of Run Times Polynomial Time Exponential Time B βˆ… Y βˆ… Factorial Time The Class P The PATH Problem B S0, S X, Y S0, S The CFL Membership Problem A S0, S βˆ… Assignment B S0, S A
  • 47. Example The Class P Robb T. Koether Example (The CFL Membership Problem) Homework For j = 4, Review Introduction Comparison A S0, S X S0, S X of Run Times Polynomial Time Exponential Time B βˆ… Y βˆ… Y Factorial Time The Class P The PATH Problem B S0, S X, Y S0, S The CFL Membership Problem A S0, S βˆ… Assignment B S0, S A
  • 48. Example The Class P Robb T. Koether Example (The CFL Membership Problem) Homework For j = 5, Review Introduction Comparison A S0, S X S0, S X S0, S of Run Times Polynomial Time Exponential Time B βˆ… Y βˆ… Y Factorial Time The Class P The PATH Problem B S0, S X, Y S0, S The CFL Membership Problem A S0, S βˆ… Assignment B S0, S A
  • 49. The CFL Membership Problem The Class P Robb T. Koether Homework Review Example (The CFL Membership Problem) Introduction Finally, see whether the start symbol is in table entry Comparison of Run Times (1, m). Polynomial Time Exponential Time Factorial Time If it is, then accept w. The Class P If it is not, the reject w. The PATH Problem The CFL Membership Problem In the example, the start symbol S0 is in table entry Assignment (1, 6).
  • 50. An Algorithm for CFL The Class P Robb T. Example (The CFL Membership Problem) Koether CFLMember(graph G, string w) Homework { Review for (int i = 1; i <= m; i++) if ((A β†’ w[i]) ∈ R) Introduction Add A to table[i, i]; Comparison for (int len = 2; len <= m; len++) of Run Times Polynomial Time for (int i = 1; i <= m - len + 1; i++) Exponential Time { Factorial Time int j = i + len - 1; The Class P for (int k = i; k <= j - 1; k++) The PATH Problem for each ((A β†’ BC) ∈ R) The CFL Membership Problem if (B ∈ table[i, k] && C ∈ table[k+1, j]) Assignment Add A to table[i, j]; } if (S ∈ table[1, m]) accept(); else reject(); }
  • 51. The CFL Membership Problem The Class P Robb T. Koether Homework Review Introduction Example (The CFL Membership Problem) Comparison of Run Times We can analyze each step in the function Polynomial Time Exponential Time CFLMember(). Factorial Time The Class P Each step is done in polynomial time. The PATH Problem The CFL Thus, CFL ∈ P. Membership Problem Assignment
  • 52. Assignment The Class P Robb T. Koether Homework Review Introduction Homework Comparison of Run Times Polynomial Time Read Section 7.2, page256 - 263. Exponential Time Factorial Time Exercises 1, 2, 3, 4, 9, pages 294 - 295. The Class P The PATH Problem Problem 12, page 295. The CFL Membership Problem Assignment