1 / 37

CS20a: NP problems

CS20a: NP problems. The SAT problem Graph theory. Time-bounded TMs. All tapes are 2-way infinite M is DTIME(T(n)) if M is deterministic For any input of length n, M takes at most T(n) steps M is NTIME(T(n)) Nondeterministic case. NP problems.

arleen
Download Presentation

CS20a: NP problems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS20a: NP problems • The SAT problem • Graph theory Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  2. Time-bounded TMs • All tapes are 2-way infinite • M is DTIME(T(n)) if • M is deterministic • For any input of length n, M takes at most T(n) steps • M is NTIME(T(n)) • Nondeterministic case Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  3. NP problems • A problem is in NP if it can be decided yes/no by a nondeterministic TM in O(nc) steps • n is the length of the input • c is a constant • How long does it take to decide a problem in NP? • It takes O(nc) time to explore each possible nondeterministic choice • There are an exponential number of choices • So it takes O(2n) time worst case • How long does it take to verify an NP execution? • There are O(nc) steps of size O(nc) • So it takes O(n2c) time Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  4. CNF satisfiability Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  5. Satisfiability algorithm • CNF should make the decision problem easier, since there is only conjunction, disjunction, negation • An algorithm in NP • Guess a truth assignment • Verify the assignment • An algorithm in P • Must be deterministic (no “guessing”) • Just figure out if the formula is true Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  6. Building an algorithm for 2SAT Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  7. 2SAT graph Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  8. Graph theory • A graph is a set of points (vertices) that are interconnected by a set of lines (edges) Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  9. Some common graphs Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  10. Formal definition of graphs Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  11. Graph definitions Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  12. A simple theorem Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  13. Path definitions Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  14. Path example Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  15. Connected components Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  16. Graph components Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  17. Trees • A tree is a connected graph with no cycles • A forest is a set of trees Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  18. Directed graphs • A directed graph assigns a direction to the edges Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  19. Paths, cycles Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  20. Connected components Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  21. Graph algorithms: Depth-First-Search (DFS) • DFS does the following: • Assigns a unique number to each vertex • Forms a spanning tree (called the DFS spanning tree) • Basic algorithm • We need a stack of edges (initially empty) • A counter c (initially 1) Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  22. DFS algorithm Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  23. DFS: Initial search Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  24. DFS: Backtracking Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  25. DFS: Finalize Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  26. Biconnected components Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  27. Biconnected components Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  28. Transitive case (part 1) Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  29. Transitive case (part 2) Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  30. Articulation points Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  31. Articulation points Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  32. Using DFS to get biconnected components Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  33. DFS backedges Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  34. DFS biconnected components Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  35. Solving 2SAT • We can define DFS for directed graphs • Follow edges only in the forward direction • Use DFS to determine strongly-connected components • Strongly-connected component • For each u, v, there is a path from u to v, and from v to u Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  36. 2SAT graph Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

  37. 2SAT solution • The formula is satisfiable iff there is a strongly-connected component that contains A and not A for some letter A • If it does, then A implies not A and not A implies A (contradiction) • If not, we have to define a satisfying assignment (next time) Computation, Computers, and Programs Recursive functions http://www.cs.caltech.edu/courses/cs20/a/ March 10, 2014

More Related