Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 2670 Introduction to Theory of Computing

Similar presentations


Presentation on theme: "CSCI 2670 Introduction to Theory of Computing"— Presentation transcript:

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

2 Announcement Homework due next Tuesday (11/22)
7.3 a, 7.4, 7.6 (union only), 7.9, 7.12 1st edition 7.3a, 7.4, 7.6 (union only), 7.10, 7.12 November 16, 2005

3 Last class Relationship of time complexity for different TM models
If a problem can be solved in O(t(n)) time on a multi-tape TM, it can be solved in O(t2(n)) time on a single-tape TM If a problem can be solved in O(t(n)) time on a nondeterministic TM, it can be solved in 2O(t(n)) time on a deterministic TM November 16, 2005

4 Polynomial vs. exponential time
We distinguish between algorithms that have polynomial running time and those that have exponential running time Assume a single tape deterministic TM Polynomial functions – even ones with large exponents – grow less quickly than exponential functions We can only process large data sets with polynomial running time algorithms November 16, 2005

5 Polynomial equivalence
Two algorithms A1 and A2 are polynomially equivalent if we can simulate A2 using A1 with only a polynomial increase in running time November 16, 2005

6 The class P P is the class of languages that are decidable in polynomial time on a single-tape Turing machine P = k TIME(nk) P “roughly corresponds” to the problems that are realistically solvable on a computer November 16, 2005

7 Size of input: Important consideration
The running time is measured in terms of the size of the input If we increase the input size can that make the problem seem more efficient E.g., if we represent integers in unary instead of binary We consider only reasonable encodings November 16, 2005

8 A problem in class P Binary tree query
Given a binary search tree T and a key k, find the node in T with key(node) = k How do we show this problem is in class P? Write an algorithm and show that the algorithm has running time O(nk) for some k November 16, 2005

9 Binary search M = “On input <G,k> Let node = root(G)
Do while key(node) <> k If key(node) < k If right(node) == NIL return NIL Else node = right(node) If left(node) == NIL node = left(node) Return node November 16, 2005

10 Execution time Worst case running time? O(|nodes|)
Occurs if tree is unbalanced Is this O(n)? Yes … any reasonable encoding will have an entry for each node November 16, 2005

11 Path problem PATH = {<G,s,t> | G is a directed graph that has a path from s to t>} PATH  P How would we show this? Mark all nodes that can be reached from s If t gets marked, accept If t doesn’t get marked, reject November 16, 2005

12 Solution to path problem
M = “On input <G,s,t>, where G is a digraph with nodes s and t: Place a mark on node s Repeat the following until no additional nodes are marked Scan all edges of G If an edge (a,b) is found where a is marked and b is unmarked, mark b If t is marked accept Else reject” November 16, 2005

13 Verify solution is in P Is M a decider?
Yes How long will it take M to run? Loop takes O(|edges|) to execute each time Loop is executed O(|nodes|) times Total time is O(|edges|x|nodes|) Is this polynomial in the length of the input? This is o(n2) where n = lentgh of input November 16, 2005


Download ppt "CSCI 2670 Introduction to Theory of Computing"

Similar presentations


Ads by Google