CSE 326: Data Structures NP Completeness

CSE 326: Data Structures NP Completeness

Announcements • Benchmarking for project 3 due tonight CSE 326: Data Structures • Last homework due on Friday at beginning of class NP Completeness • Final next Thursday – Scheduled for 8:30, might be moved to 10:30 Brian Curless – Final will be closed book/notes Spring 2008 – Up to and including MSTs • Reading for this lecture: Weiss Chapter 9.7 2 Your First Task Try it with paper and pencil Your company has to inspect a set of roads between cities by driving over each of them. Driving over the roads costs money (fuel), and there are a lot of roads. Your boss wants you to figure out how to drive over each road exactly once. You get a bonus if, after inspecting the last Which of these can you draw without lifting your road, the car is back where it started. pencil, drawing each line only once? Can you start and end at the same point? 3 4 Historical Puzzle: Seven Bridges of Königsberg Graph Problem for the Bridges of Königsberg Pregel River Island of Kneiphof Want to cross all bridges but… Want to cross all bridges but… can cross each bridge only once. Can cross each bridge only once 5 6 eiπ = −1 Euler Circuits and Tours Finding Euler Circuits Given a connected, undirected graph G = (V,E), find an Euler circuit in G. • Euler tour: a path through a graph that visits each edge exactly once Euler Circuit Existence Algorithm: • Euler circuit: an Euler tour that starts and ends at the Check to see that all vertices have even degree same vertex Running time = • Named after Leonhard Euler (1707-1783), who cracked this problem and founded graph theory in Euler Circuit Algorithm: 1. Do an edge walk from a start vertex until you 1736 are back at the start vertex. Mark each edge you visit, and do not revisit marked edges. You • Some observations for undirected graphs: never get stuck because of the even degree – An Euler circuit exists iff the graph is connected and each property. vertex has even degree (= # of edges on the vertex) 2. The walk is removed leaving several components each with the even degree – An Euler tour exists iff the graph is connected and either all property. Recursively find Euler circuits for vertices have even degree or exactly two have odd degree these. 3. Splice all these circuits into an Euler circuit 7 Running time = 8 Euler Circuit Example Euler Circuit Example A A B C B C G G D E D E F F Euler(A) : Euler(A) : A B G E D G C A 9 10 Euler Circuit Example Euler Circuit Example A A B C B C B C B C G G D E D E D E D E F F F F Euler(A) : Euler(B) Euler(A) : Euler(B): A B G E D G C A A B G E D G C A B D F E C B 11 12 Euler Circuit Example Euler Tour For an Euler Tour, exactly two vertices are odd, the rest A even. Using a similar algorithm, you can find a path between the two odd vertices. B C B C A G D E D E B C D F F Euler(A) : Euler(B): A B G E D G C A B D F E C B Splice E F G A B D F E C B G E D G C A 13 14 W. R. Hamiltonian Circuits Hamilton Your Second Task (1805-1865) • Euler circuit: A cycle that goes through each edge exactly once Your boss is pleased…and assigns you a B C new task. • Hamiltonian circuit: A cycle that goes through each vertex exactly once G Your company has to send someone by car (except the first=last one) I to a set of cities. • Does graph I have: D E The primary cost is the exorbitant toll going – An Euler circuit? – A Hamiltonian circuit? into each city. B C • Does graph II have: Your boss wants you to figure out how to – An Euler circuit? G II drive to each city exactly once, returning in – A Hamiltonian circuit? the end to the city of origin. • Does the Hamiltonian circuit problem D E seem easier or harder? 15 16 Finding Hamiltonian Circuits Analysis of our Exhaustive Search Algorithm • Problem: Find a Hamiltonian circuit in a B C connected, undirected graph G. • Worst case Æ need to search G • One solution: Search through all paths to find all paths one that visits each vertex exactly once – How many paths? D E – Can use your favorite graph search algorithm • Can depict these paths as a (DFS!) to find various paths search tree • This is an exhaustive search (“brute force”) algorithm. B • Worst case Æ need to search all paths D G C – How many paths?? G E D E C G E 17 Etc. Search tree of paths from B 18 Analysis of our Exhaustive Exponential Time Search Algorithm • Let the average branching factor of 1E+60 each node in this tree be B 1E+55 B 1E+50 • |V| vertices, each with ≈ B branches 1E+45 • Total number of paths ≈ B·B·B … ·B 2^N PC, since Big Bang D G C 1E+40 = 1.2^N 1E+35 N^5 1E+30 • Worst case Æ Exponential time! G E D E C G E N^3 1E+25 Etc. 5N 1E+20 PC, 1 day 1E+15 1E+10 Search tree of paths from B 100000 1 1 10 100 1000 19 20 Polynomial vs. Exponential Time The Complexity Class P • The set P is defined as the set of all • Most of our algorithms so far have been problems that can be solved in 2 O(log N), O(N), O(N log N) or O(N ) running polynomial worst case time time for inputs of size N – Also known as the polynomial time – These are all polynomial time algorithms complexity class – Their running time is O(Nk) for some k > 0 – All problems that have some algorithm • Exponential time BN is asymptotically worse whose running time is O(Nk) for some k than any polynomial function Nk for any k • Examples of problems in P: sorting, shortest path, Euler circuit, etc. 21 22 Problem Spaces Saving your job Simplified view: if a problem is not Try as you might, every solution you come polynomial-time solvable (not in P), then it is an exponential-time problem. up with for the Hamiltonian Circuit problem runs in exponential time. Shorthand: EXPTIME – P solutions are fast You have to report back to your boss. – EXPTIME are slow • Sometimes viewed as “intractable” P 23 24 When is a problem easy? When is a problem hard? • We’ve seen some “easy” graph problems: • Almost everything we’ve seen in class has had a near linear time algorithm – Graph search • But of course, computers can’t solve every – Shortest-path problem quickly. – Minimum Spanning Tree • In fact, there are perfectly reasonable sounding • Not easy for us to come up with, but easy problems that no computer could ever solve in any reasonable amount of time (as far as we for the computer, once we know algorithm. know!). – The Hamiltonian Circuit problem is one of these (as far as we know). More later on just how hard it is… 25 26 When is a problem hopeless? A Glimmer of Hope • If the solution to a problem requires generating a result Suppose you have a problem that is at least that is exponential in size, then the algorithm must run in exponential time (even if just to print the solution!). decideable. (Many are!) • Some problems are “undecideable” – no algorithm can be given for solving them. – The Halting Problem: is it possible to specify any If the output can be checked for correctness algorithm, which, given an arbitrary program and input to that program, will always correctly determine in polynomial-time, then maybe a whether or not that program will enter an infinite loop? polynomial-time solution exists! – No! [Turing, 1936] Alan Turing • We’ll focus on problems that have (1912-1954) a glimmer of hope… 27 28 The Complexity Class NP Why NP? • Definition: NP is the set of all problems • NP stands for Nondeterministic Polynomial for which a given candidate solution can time be tested in polynomial time – Why “nondeterministic”? Corresponds to • Are the following in NP: algorithms that can guess a solution (if it – Hamiltonian circuit problem? exists) Æ the solution is then verified to be correct in polynomial time – Euler circuit problem? – Nondeterministic algorithms don’t exist – – All polynomial time algorithms? purely theoretical idea invented to understand how hard a problem could be 29 30 Your Chance to Win Problem Spaces (revisited) a Turing Award (and $$$) We can now augment our problem space to • It is generally believed that P ≠ NP, i.e. include NP as a superset of P. there are problems in NP that are not in P – But no one has been able to show even EXPTIME Whenever someone finds one such problem! a polynomial time solution – This is the fundamental open problem in NP to a problem currently theoretical computer science. believed to be in NP - P, – Nearly everyone has given up trying to it moves to P. P prove it. Instead, theoreticians prove theorems about what follows once we 31 assume P ≠ NP ! 32 P = NP? Your Third Task Perhaps instead P = NP, but that would seem to be even harder to prove… Your boss buys your story that others couldn’t solve the last problem.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    13 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us