Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 2670 Introduction to Theory of Computing November 15, 2005.

Similar presentations


Presentation on theme: "CSCI 2670 Introduction to Theory of Computing November 15, 2005."— Presentation transcript:

1 CSCI 2670 Introduction to Theory of Computing November 15, 2005

2 Agenda Today –Comparing complexity of different computing models This week –Finish 7.1 and do 7.2

3 November 15, 2005 Announcement Office hours changed tomorrow –11:30 to 1:00 instead of 11:00 – 12:30

4 November 15, 2005 Analyzing algorithms We can examine an algorithm to determine how long it will take to halt on an input of length n The amount of time to complete is called the algorithms complexity class Definition: Let t:N → N be a function. The time complexity class, TIME(t(n)), is defined as follows. TIME(t(n))={L|L is a language decided by an O(t(n)) time TM}

5 November 15, 2005 Another example Finding minimum element in a set Amount of time depends on the structure of the input If set is a sorted array? –O(1) If set is an unsorted array? –O(n) If set is a balanced sorted tree? –O(log n)

6 November 15, 2005 Importance of model The complexity of our algorithms depends on assumptions about our data & other model assumptions The complexity of an algorithm can vary depending on the machine we use Recall we assume reasonable encoding of all numbers –Any integer of value v should take O(log v) space

7 November 15, 2005 Machine-dependent complexity Example, let L={w | w is a palindrome} How long will it take us to decide L on a standard TM? –Go back and forth crossing off matching symbols at beginning and end –O(n 2 ) How long will it take us to decide L on a 2- tape TM? –Copy string –Compare symbols reading forward on tape 1 and backward on tape 2 –O(n)

8 November 15, 2005 Complexity relationships Theorem: Let t(n) be a function, where t(n)  n. Then every t(n) time multitape TM has an equivalent O(t 2 (n)) time single-tape TM Proof idea: Consider structure of equivalent single-tape TM. Analyzing behavior shows each step on multi- tape machine takes O(t(n)) on single tape machine

9 November 15, 2005 Equivalent machines M 0 1 ~ ~ ~ ~ ~ ~ a a a ~ ~ ~ ~ ~ a b ~ ~ ~ ~ ~ ~ # 0 1 # a a a # a b # ~ ~ S

10 November 15, 2005 Simulating k-tape behavior Single tape start string is #w#~#...#~# Each move proceeds as follows: –Start at leftmost slot –Scan right to (k+1) st # to find symbol at each virtual tape head –Make second pass making updates indicated by k-tape transition function –When a virtual head moves onto a #, shift string to right

11 November 15, 2005 Proof of theorem Analyzing simulation of k-tape machine Each step on single-tape machine has two phases –Scan tape –Perform operations How long does first phase take? –Length of string on tape –Each portion has O(t(n)) length (this occurs if tape heads only move right)

12 November 15, 2005 Proof of theorem (cont.) How long does second phase take? –Perform k steps Each step may require a right shift –Each step takes O(t(n)) time –Total of k steps is O(t(n)) because k is a constant What’s the total time? –O(t(n)) steps each take O(t(n)) time –Total time is O(t 2 (n))

13 November 15, 2005 Determinism vs. non-determinism Definition: Let P be a non- deterministic Turing machine. The running time of P is the function f:N → N, where f(n) is the maximum number of steps that P uses on any branch of its computation in any input of length n.

14 November 15, 2005 Non-deterministic tree f(n) accept/ reject Deterministic … … reject accept Non-deterministic

15 November 15, 2005 Complexity relationship Theorem: Let t(n) be a function where t(n)  n. Then every t(n) time non- deterministic single-tape Turing machine has an equivalent 2 O(t(n)) time deterministic single-tape Turing machine.

16 November 15, 2005 Complexity relationship proof Proof: Given a non-deterministic TM, P, running in t(n) time, construct a 3-tape deterministic TM that simulates P. The height of the tree is at most t(n). Assume the maximum number of branches in the tree is b. Therefore, the number of leaves in the tree is O(b t(n) ).

17 November 15, 2005 How many nodes in the tree? Claim: The total number of nodes is less than twice the number of leaves – i.e. O(b t(n) ). (Σ 0≤k≤n b k )  b n = (1 – b n+1 )/(1-b)  b n < – b n+1 /(1-b)  b n = - b / (1-b) ≤ 2

18 November 15, 2005 Complexity relationship proof (cont.) Deterministic TM does a breadth- first search of the non-deterministic TM’s tree. Total time to search tree is O(t(n)) to travel from the root to a leaf × O(b t(n) ), the number of leaves. O(t(n)b t(n) ) = O(2 log_2 t(n) 2 (log_2 b)t(n) ) = O(2 O(t(n)) )

19 November 15, 2005 Complexity relationship proof (cont.) Are we done? No! We constructed a 3-tape TM with running time O(2 O(t(n)) ) Single-tape TM will take O((2 O(t(n)) ) 2 )=O(2 2O(t(n)) )=O(2 O(t(n)) ) Are we done? Yes!


Download ppt "CSCI 2670 Introduction to Theory of Computing November 15, 2005."

Similar presentations


Ads by Google