• No results found

Lecture 36: Efficiency in computation

N/A
N/A
Protected

Academic year: 2022

Share "Lecture 36: Efficiency in computation"

Copied!
41
0
0

Loading.... (view fulltext now)

Full text

(1)

Lecture 36: Efficiency in computation

Instructor: S. Akshay

IITB, India

04-04-2019

(2)

Recap

Turing machines and computability 1. Turing machines

(i) Definition (ii) Variants

(iii) Decidable and Turing recognizable languages (iv) Church-Turing Hypothesis

(ii) Via reductions (iii) Rice’s theorem

3. Applications: showing (un)decidability of other problems (i) A string matching problem: Post’s Correspondance Problem (ii) A problem for compilers: Unambiguity of Context-free languages (iii) Between TM and PDA: Linear Bounded Automata

4. Efficiency in computation: run-time complexity.

(3)

Recap

Turing machines and computability 1. Turing machines

(i) Definition (ii) Variants

(iii) Decidable and Turing recognizable languages (iv) Church-Turing Hypothesis

2. Undecidability

(i) A proof technique by diagonalization (ii) Via reductions

(iii) Rice’s theorem

(ii) A problem for compilers: Unambiguity of Context-free languages (iii) Between TM and PDA: Linear Bounded Automata

4. Efficiency in computation: run-time complexity.

(4)

Recap

Turing machines and computability 1. Turing machines

(i) Definition (ii) Variants

(iii) Decidable and Turing recognizable languages (iv) Church-Turing Hypothesis

2. Undecidability

(i) A proof technique by diagonalization (ii) Via reductions

(iii) Rice’s theorem

3. Applications: showing (un)decidability of other problems (i) A string matching problem: Post’s Correspondance Problem (ii) A problem for compilers: Unambiguity of Context-free languages (iii) Between TM and PDA: Linear Bounded Automata

(5)

Turing machines and computability 1. Turing machines

(i) Definition (ii) Variants

(iii) Decidable and Turing recognizable languages (iv) Church-Turing Hypothesis

2. Undecidability

(i) A proof technique by diagonalization (ii) Via reductions

(iii) Rice’s theorem

3. Applications: showing (un)decidability of other problems (i) A string matching problem: Post’s Correspondance Problem (ii) A problem for compilers: Unambiguity of Context-free languages (iii) Between TM and PDA: Linear Bounded Automata

(6)

Given M a halting TM,running time of M is the function

f(n) :N→N, which counts the maximum number of steps that M uses on any input of length n.

(7)

Given M a halting TM,running time of M is the function

f(n) :N→N, which counts the maximum number of steps that M uses on any input of length n.

Is this the only notion possible? Any others?

(8)

Given M a halting TM,running time of M is the function

f(n) :N→N, which counts the maximum number of steps that M uses on any input of length n.

I Worst-case complexity - longest running time of all inputs of lengthn (in this course, we consider this)

I Average-case complexity - average running time over all inputs of length n.

(9)

Let t :N→R+. A language L⊆Σ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ of length n,M halts on x within time O(t(n)).

(10)

Let t :N→R+. A language L⊆Σ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ of length n,M halts on x within time O(t(n)).

TIME(t(n))is set of all languages decidable by a O(t(n)) TM

(11)

Let t :N→R+. A language L⊆Σ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ of length n,M halts on x within time O(t(n)).

TIME(t(n))is set of all languages decidable by a O(t(n)) TM

Exercise: Is A={0k1k |k ≥0}in O(n2)?

(12)

Let t :N→R+. A language L⊆Σ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ of length n,M halts on x within time O(t(n)).

TIME(t(n))is set of all languages decidable by a O(t(n)) TM

Exercise: Is A={0k1k |k ≥0}in O(n2)?

1. scan tape once to check if input is of form 01. else reject.

2. repeat until there are no 0’s:

3. scan tape to cross a single 0 and single 1 (if you cant find 1 to cross off, reject)

4. at end if there are 1’s remaining reject, otherwise, accept.

(13)

Let t :N→R+. A language L⊆Σ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ of length n,M halts on x within time O(t(n)).

TIME(t(n))is set of all languages decidable by a O(t(n)) TM

Exercise: Is A={0k1k |k ≥0}in O(n2)?

1. scan tape once to check if input is of form 01. else reject.O(n) steps 2. repeat until there are no 0’s:

3. scan tape to cross a single 0 and single 1 (if you cant find 1 to cross off, reject)

4. at end if there are 1’s remaining reject, otherwise, accept.

(14)

Let t :N→R+. A language L⊆Σ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ of length n,M halts on x within time O(t(n)).

TIME(t(n))is set of all languages decidable by a O(t(n)) TM

Exercise: Is A={0k1k |k ≥0}in O(n2)?

1. scan tape once to check if input is of form 01. else reject.O(n) steps 2. repeat until there are no 0’s:

3. scan tape to cross a single 0 and single 1 (if you cant find 1 to cross off, reject)O(n) steps

4. at end if there are 1’s remaining reject, otherwise, accept.

(15)

Let t :N→R+. A language L⊆Σ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ of length n,M halts on x within time O(t(n)).

TIME(t(n))is set of all languages decidable by a O(t(n)) TM

Exercise: Is A={0k1k |k ≥0}in O(n2)?

1. scan tape once to check if input is of form 01. else reject.O(n) steps 2. repeat until there are no 0’s: n/2 repetitions

3. scan tape to cross a single 0 and single 1 (if you cant find 1 to cross off, reject)O(n) steps

4. at end if there are 1’s remaining reject, otherwise, accept.

(16)

Let t :N→R+. A language L⊆Σ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ of length n,M halts on x within time O(t(n)).

TIME(t(n))is set of all languages decidable by a O(t(n)) TM

Exercise: Is A={0k1k |k ≥0}in O(n2)?

1. scan tape once to check if input is of form 01. else reject.O(n) steps 2. repeat until there are no 0’s: n/2 repetitions

3. scan tape to cross a single 0 and single 1 (if you cant find 1 to cross off, reject)O(n) steps

4. at end if there are 1’s remaining reject, otherwise, accept. O(n) steps

(17)

Let t :N→R+. A language L⊆Σ is said to be in TIME(t(n))if there exists a deterministic (halting) Turing machine M such that ∀x ∈Σ of length n,M halts on x within time O(t(n)).

TIME(t(n))is set of all languages decidable by a O(t(n)) TM

Exercise: Is A={0k1k |k ≥0}in O(n2)?

1. scan tape once to check if input is of form 01. else reject.O(n) steps 2. repeat until there are no 0’s: n/2 repetitions

3. scan tape to cross a single 0 and single 1 (if you cant find 1 to cross off, reject)O(n) steps

4. at end if there are 1’s remaining reject, otherwise, accept. O(n) steps Overall: O(n) +nO(n) +O(n) =O(n2) steps

(18)

TIME(t(n))is set of all languages decidable by a O(t(n)) Turing machine

Questions

I Show that A={0k1k |k ≥0}in O(nlog(n))?

I IsA in O(n) No. why?

(19)

TIME(t(n))is set of all languages decidable by a O(t(n)) Turing machine

Questions

I Show that A={0k1k |k ≥0}in O(nlog(n))?

I IsA in O(n) No. why?

Does crossing two 0s and 1s on every scan instead of just one help?

(20)

TIME(t(n))is set of all languages decidable by a O(t(n)) Turing machine

Questions

I Show that A={0k1k |k ≥0}in O(nlog(n))?

I IsA in O(n) No. why?

I Scan tape and reject, if 0 is to right of 1.

I Scan the 0s and copy them to another tape, until first 1.

I Scan 1s in first tape together with 0s in second tape, if 0’s are crossed before 1s are read, reject

I if all 0s are crossed off at the end, accept, else reject.

(21)

TIME(t(n))is set of all languages decidable by a O(t(n)) Turing machine

Questions

I Show that A={0k1k |k ≥0}in O(nlog(n))?

I IsA in O(n) No. why?

I Scan tape and reject, if 0 is to right of 1.

I Scan the 0s and copy them to another tape, until first 1.

I Scan 1s in first tape together with 0s in second tape, if 0’s are crossed before 1s are read, reject

I if all 0s are crossed off at the end, accept, else reject.

(22)

TIME(t(n))is set of all languages decidable by a O(t(n))1-tapeTuring machine

Questions

I (HW)Show that A={0k1k |k ≥0} in O(nlog(n))?

I IsA in O(n) No. why?

I Scan tape and reject, if 0 is to right of 1.

I Scan the 0s and copy them to another tape, until first 1.

I Scan 1s in first tape together with 0s in second tape, if 0’s are crossed before 1s are read, reject

I if all 0s are crossed off at the end, accept, else reject.

(23)

TIME(t(n))is set of all languages decidable by a O(t(n))1-tapeTuring machine

Questions

I (HW)Show that A={0k1k |k ≥0} in O(nlog(n))?

I (Challenge)IsA in O(n) No. why?

So, with 2-tape can improve “complexity”.

(24)

TIME(t(n))is set of all languages decidable by a O(t(n))1-tapeTuring machine

Questions

I (HW)Show that A={0k1k |k ≥0} in O(nlog(n))?

I (Challenge)IsA in O(n) No. why?

So, with 2-tape can improve “complexity”.

Conclusions: change of model can change complexity, even if it does not change computability.

(25)

Computability vs Complexity

I Computability: (Church Turing Hypothesis) All reasonable models of computation are equivalent, i.e., they decide the same class of languages.

I Complexity: Choice of model affects running time.

(26)

Computability vs Complexity

I Computability: (Church Turing Hypothesis) All reasonable models of computation are equivalent, i.e., they decide the same class of languages.

I Complexity: Choice of model affects running time.

Our goal

(27)

Computability vs Complexity

I Computability: (Church Turing Hypothesis) All reasonable models of computation are equivalent, i.e., they decide the same class of languages.

I Complexity: Choice of model affects running time.

Our goal

I to measure or classify problems by their (running) time complexity

(28)

Computability vs Complexity

I Computability: (Church Turing Hypothesis) All reasonable models of computation are equivalent, i.e., they decide the same class of languages.

I Complexity: Choice of model affects running time.

Our goal

I to measure or classify problems by their (running) time complexity I But if change of model changes complexity, then how can we measure or

classify them?

(29)

Computability vs Complexity

I Computability: (Church Turing Hypothesis) All reasonable models of computation are equivalent, i.e., they decide the same class of languages.

I Complexity: Choice of model affects running time.

Our goal

I to measure or classify problems by their (running) time complexity I But if change of model changes complexity, then how can we measure or

classify them?

I Fortunately, it doesn’t change by much, at least for deterministic models!

(30)

Computability vs Complexity

I Computability: (Church Turing Hypothesis) All reasonable models of computation are equivalent, i.e., they decide the same class of languages.

I Complexity: Choice of model affects running time.

Our goal

I to measure or classify problems by their (running) time complexity I But if change of model changes complexity, then how can we measure or

classify them?

I Fortunately, it doesn’t change by much, at least for deterministic models!

Theorem

(31)

Theorem

Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.

(32)

Theorem

Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.

Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS:

(33)

Theorem

Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.

Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS: I Storek-tapes ofM in 1-tape of S, with head positions marked.

I To simulate one-step of M,

(34)

Theorem

Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.

Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS: I Storek-tapes ofM in 1-tape of S, with head positions marked.

I To simulate one-step of M,

I S scans all info on its tape to check all head positions

I then makes another pass over tape to update tape contents and head positions.

I If some head moves rightward into previously unread portion of tape inM, then inS, space allocated for that tape is increased by a right-shift of all content to right.

(35)

Theorem

Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.

Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS: I Storek-tapes ofM in 1-tape of S, with head positions marked.O(n) I To simulate one-step of M,

I S scans all info on its tape to check all head positions O(t(n))steps I then makes another pass over tape to update tape contents and head

positions. O(t(n))steps

I If some head moves rightward into previously unread portion of tape inM, then inS, space allocated for that tape is increased by a right-shift of all content to right.

(36)

Theorem

Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.

Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS: I Storek-tapes ofM in 1-tape of S, with head positions marked.O(n) I To simulate one-step of M,

I S scans all info on its tape to check all head positions O(t(n))steps I then makes another pass over tape to update tape contents and head

positions. O(t(n))steps

I If some head moves rightward into previously unread portion of tape inM, then inS, space allocated for that tape is increased by a right-shift of all content to right. k tapes =k heads=k×O(t(n))steps

(37)

Theorem

Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.

Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS: I Storek-tapes ofM in 1-tape of S, with head positions marked.O(n) I To simulate one-step of M,O(t(n))

I S scans all info on its tape to check all head positions O(t(n))steps I then makes another pass over tape to update tape contents and head

positions. O(t(n))steps

I If some head moves rightward into previously unread portion of tape inM, then inS, space allocated for that tape is increased by a right-shift of all content to right. k tapes =k heads=k×O(t(n))steps

(38)

Theorem

Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.

Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS: I Storek-tapes ofM in 1-tape of S, with head positions marked.O(n) I To simulate one-step of M,O(t(n))

I S scans all info on its tape to check all head positions O(t(n))steps I then makes another pass over tape to update tape contents and head

positions. O(t(n))steps

I If some head moves rightward into previously unread portion of tape inM, then inS, space allocated for that tape is increased by a right-shift of all content to right. k tapes =k heads=k×O(t(n))steps

I t(n) steps ofM impliest(n)×O(t(n)) =O(t2(n)) steps

(39)

Theorem

Let t(n) be a function such that t(n)≥n. Then everyt(n) time multitape det TM has an equivalent O(t2(n)) time 1-tape det TM.

Proof: Given k-tape TM M running in t(n) time, define 1-tape TMS: I Storek-tapes ofM in 1-tape of S, with head positions marked.O(n) I To simulate one-step of M,O(t(n))

I S scans all info on its tape to check all head positions O(t(n))steps I then makes another pass over tape to update tape contents and head

positions. O(t(n))steps

I If some head moves rightward into previously unread portion of tape inM, then inS, space allocated for that tape is increased by a right-shift of all content to right. k tapes =k heads=k×O(t(n))steps

I t(n) steps ofM impliest(n)×O(t(n)) =O(t2(n)) steps I Overall: O(n) +O(t2(n)) =O(t2(n)) (since t(n)≥n)

(40)

What about non-determinism?

Running time of a non-det halting TM

The running time of a non-det halting TM N is the function f(n:N→N), where f(n) is the max number of steps that N uses on any branch of its computation on any input of length n.

1-tape TMN has an equivalent 2O(t(n)) time det 1-tape TMD.

(41)

Running time of a non-det halting TM

The running time of a non-det halting TM N is the function f(n:N→N), where f(n) is the max number of steps that N uses on any branch of its computation on any input of length n.

Theorem

Let t(n) be a function such that t(n)≥n. Then everyt(n) time non-det 1-tape TM N has an equivalent 2O(t(n)) time det 1-tape TMD.

References

Related documents

This sort of budgeting is normally adopted to ensure objectivity. In formula budgeting, the resources are allocated according to some pre- determined standard. The basis of

Apart from moral rights, performers shall enjoy the economic rights of performers in their unfixed performances (Article 6), right of reproduction (Article 7), right

If one takes into account that the content of mineral matter is very high in all coals (see the ash content in table 2), but especially in B–O, and that the contents of functional

If there are n nodes in network and m (m<n) are selected as cluster head & energy associated with each node is E(i) then those m cluster heads will send data to base station

Read and Reflect According to, CEDAW gender discrimination i s , "Any distinction, exclusion, or restriction m a d e o n t h e b a s i s of sex that has

In the present work, we have calculated ot for positron impact on all the alkali metals using an optical potential method. The effect of Ps formation is not taken

Research Centre Imarat, Hyderabad-500 069, Andhra Pradesh Department of Electronics and Telecommunication Engineering, Jadavpur University, Kolkata-700 032. Space

In photocatalytic process, titania catalyst absorb light energy and create photo excited species such as holes and electrons in valence band and conduction band respectively.