Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computability Heap exercise. The class P. The class NP. Verifiers. Homework: Review RELPRIME proof. Find examples of problems in NP.

Similar presentations


Presentation on theme: "Computability Heap exercise. The class P. The class NP. Verifiers. Homework: Review RELPRIME proof. Find examples of problems in NP."— Presentation transcript:

1 Computability Heap exercise. The class P. The class NP. Verifiers. Homework: Review RELPRIME proof. Find examples of problems in NP.

2 Heap sort Heap sort: –make whole set into a heap, starting at the top –Loop: remove root: swap with last member. Remove (don't think about this position any more). Then restore heap property by possibly pushing value down. We only need to fix up one of the two subtrees at each stage. http://nova.umuc.edu/~jarc/idsv/lesson3.ht mlhttp://nova.umuc.edu/~jarc/idsv/lesson3.ht ml

3 Formalities The Sipser text does everything in terms of Turing machines. We may talk more on some general model, such as encoding in a programming language

4 Multiple tape TM Let M be a multiple tape TM that takes t(n) time, t(n)>=n. Then M can be simulated by a single tape TM N taking at most O(t 2 (n)). Informal proof: Material on all the tapes must be bounded by t(n). 1) Use O(n) to set up single tape and put in markers for the k tapes. 2) Simulation of each step bounded by t(n) 3) So c* t(n) * t(n) is the bound.

5 Class P All languages that are decidable in polynomial time on a single tape, deterministic Turing machine.

6 Alternative definition Consider a standard programming language, an algorithm is in the class P if the running time for an input (size of input is n) is bounded by a polynomial p(n). All the sorts, searches, shuffles discussed so far are in P.

7 Practicality In practical terms, there is a big difference between algorithms O(log(n)),O(n), O(nlog(n)), O(n 2 ), etc. Say n = 1000, then what is ?? –O(log(n)) use 10 as the base –O(n) –O(nlog(n)) –O(n 2 ) –O(n 3 )

8 Answers O(log(n)) 3 O(n) 1000 O(nlog(n))3000 O(n 2 ) 1000000 O(n 3 )1000000000

9 Terminology BUT bigger difference between polynomial and exponential –1000 versus 1000 3 (1 billion) versus 2 1000 (more than the number of atoms in the universe…) So polynomial time algorithms are called easy, tractable, practical and the exponential algorithms called hard, intractable, impractical. Note: these are all solvable. That is, there are deciders for the language accepting programs or programs that halt with an answer for the functions.

10 RELPRIME For two natural numbers, x and y, x and y are relatively prime if 1 is the largest number that is a factor of both. Neither may be prime, but relatively prime means they don't share any factors. Note: if each is prime, then they are relatively prime.

11 Examples 2 and 3 Yes! easy, each is prime 4 and 9 Yes, try the factors 2 and 3. 20 and 64 No! 2 is a factor. Two even number are not relatively prime. 75 and 14 Yes, factors 3 & 5 versus 2 & 7 Now, each of you supply 1 pair that is relatively prime and 1 that is not.

12 How to determine Relprime? Brute force (which is what I did): –determine factors of each and compare. –this is exponential… Alternative: –Use Euclidean Algorithm for greatest common divisor of x & y. –If gcd is 1, return yes (true) else return false.

13 function gcd(x,y) { do { w = x % y; // x mod y x = y; y = w; // swap x and y } until (y == 0) return x; }

14 Example x = 9, y = 4 –w = 9 % 4 ; // w = 1 –x = 9, y = 1; –w = 9 % 1; // w = 0 –x = 1, y = 0 –return 1 relatively prime!

15 Example x = 6, y = 9 w = 6 % 9; //w = 6 x = 9; y = 6 w = 9 % 6; // w = 3 x = 6; y = 3; w = 6 % 3; // w = 0 x = 3; y = 0 return 3 NOT relatively prime

16 Analysis After possibly the first stage, each stage cuts the value of x in half. Since values are swapped, each of x and y are halved every two times. So number of stages is proportional log(x) plus log(y). This is polynomial…Actually O(n) LOOK UP AND GIVE IMPROVED PROOF.

17 Non-deterministic algorithm Think of TM with multiple possibilities OR Using the programming language model, think of making guesses from a finite set of choices.

18 Example: Composites Composites = {x | x = pq where p, q >1} –is x not a prime? Factoring is difficult (more on this later) but given a number X, if you can produce a candidate set p and q, then it is easy to check if x = p * q.

19 Hamiltonian circuit Let G be a directed graph. A Hamiltonian circuit is a path using the edges of G that goes through each vertex exactly once. HAMPATH = { | there is a Hamiltonian path from s to t} –language definition. No good way (so far) to determine if there is such as path for any, that is, is in the language.

20 Verifier / checker Some problems have the feature that finding a solution may be difficult, but checking it may be easy / easier. That is, one way to do the problem may involve guessing (the algorithm may be exponential) …. but checking can be done relatively easily (polynomial).

21 Formal definition: verifier Given a language A, a verifier V is an algorithm such that A = {w | V accepts for some string c} The string c is the answer or certificate or proof that w is in A.

22 Verifiers A verifier for Composites multiplies the factors. A verifier for HAMPATH checks out the candidate path.

23 NP is the class of languages that have polynomial time verifiers. This would include all the languages that are decided in polynomial time plus some others.

24 Theorem A language is in NP if and only if it can be decided by a polynomial time Turing Machine –or, using a program model, a program that makes choices among a finite number of options at certain stages.

25 P = NP??? It is not known, and one of, if not the most important problems in theoretical computer science, whether or not P = NP. If true, this means that for each NP problem, there is a P algorithm. If false, this means that for some NP problems (more on this later), there is no P algorithm.

26 Homework Review RELPRIME algorithm and analysis and give [more] formal proof that it is polynomial. Find another problem that is NP. Read about P and NP.


Download ppt "Computability Heap exercise. The class P. The class NP. Verifiers. Homework: Review RELPRIME proof. Find examples of problems in NP."

Similar presentations


Ads by Google