Circuits CSE 373 Data Structures Lecture 22. 3/12/03Circuits - Lecture 222 Readings Reading ›Sections 9.6.3 and 9.7.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

NP-Hard Nattee Niparnan.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Polynomial-time reductions We have seen several reductions:
The Theory of NP-Completeness
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
CSE 326: Data Structures Lecture #20 Really, Really Hard Problems Henry Kautz Winter Quarter 2002.
CSE332: Data Abstractions Lecture 27: A Few Words on NP Dan Grossman Spring 2010.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 21 Instructor: Paul Beame.
An Euler Circuit is a cycle of an undirected graph, that traverses every edge of the graph exactly once, and ends at the same node from which it began.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 19 Instructor: Paul Beame.
CSE 326: Data Structures NP Completeness Ben Lerner Summer 2007.
Analysis of Algorithms CS 477/677
CSE 421 Algorithms Richard Anderson Lecture 27 NP Completeness.
Chapter 11: Limitations of Algorithmic Power
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Complexity Issues Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
Complexity ©D.Moshkovitz 1 Paths On the Reasonability of Finding Paths in Graphs.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
NP-Complete Problems CSC 331: Algorithm Analysis NP-Complete Problems.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial.
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
Complexity Classes (Ch. 34) The class P: class of problems that can be solved in time that is polynomial in the size of the input, n. if input size is.
Graph Theory Topics to be covered:
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
1 Joe Meehean.  Log: binary search in sorted array  Linear: traverse a tree  Log-Linear: insert into a heap  Quadratic (N 2 ): your sort from P1 
CSE 326: Data Structures NP Completeness Ben Lerner Summer 2007.
CSC 413/513: Intro to Algorithms NP Completeness.
CSC 172 P, NP, Etc. “Computer Science is a science of abstraction – creating the right model for thinking about a problem and devising the appropriate.
CSCI 2670 Introduction to Theory of Computing November 29, 2005.
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
CSE 024: Design & Analysis of Algorithms Chapter 9: NP Completeness Sedgewick Chp:40 David Luebke’s Course Notes / University of Virginia, Computer Science.
CSE332: Data Abstractions Lecture 24.5: Interlude on Intractability Dan Grossman Spring 2012.
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
Unit 9: Coping with NP-Completeness
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
NP-Complete problems.
Design and Analysis of Algorithms - Chapter 101 Our old list of problems b Sorting b Searching b Shortest paths in a graph b Minimum spanning tree b Primality.
Limits to Computation How do you analyze a new algorithm? –Put it in the form of existing algorithms that you know the analysis. –For example, given 2.
NP-Completeness (Nondeterministic Polynomial Completeness) Sushanth Sivaram Vallath & Z. Joseph.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
CSE 589 Part V One of the symptoms of an approaching nervous breakdown is the belief that one’s work is terribly important. Bertrand Russell.
Strings Basic data type in computational biology A string is an ordered succession of characters or symbols from a finite set called an alphabet Sequence.
Lecture 52 Section 11.2 Wed, Apr 26, 2006
Topological Sort: Definition
LIMITATIONS OF ALGORITHM POWER
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
Lecture 25 NP Class. P = ? NP = ? PSPACE They are central problems in computational complexity.
Solving the Logic Satisfiability problem Solving the Logic Satisfiability problem Jesus De Loera.
CSC 413/513: Intro to Algorithms
Young CS 331 D&A of Algo. NP-Completeness1 NP-Completeness Reference: Computers and Intractability: A Guide to the Theory of NP-Completeness by Garey and.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness Proofs.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
1 The Theory of NP-Completeness 2 Review: Finding lower bound by problem transformation Problem X reduces to problem Y (X  Y ) iff X can be solved by.
The NP class. NP-completeness Lecture2. The NP-class The NP class is a class that contains all the problems that can be decided by a Non-Deterministic.
Grade 11 AP Mathematics Graph Theory Definition: A graph, G, is a set of vertices v(G) = {v 1, v 2, v 3, …, v n } and edges e(G) = {v i v j where 1 ≤ i,
CSE 589 Applied Algorithms Spring 1999 Prim’s Algorithm for MST Load Balance Spanning Tree Hamiltonian Path.
1 CSE 326: Data Structures: Graphs Lecture 23: Wednesday, March 5 th, 2003.
CSE 332: NP Completeness, Part II Richard Anderson Spring 2016.
TU/e Algorithms (2IL15) – Lecture 10 1 NP-Completeness, II.
CSC 172 P, NP, Etc.
Richard Anderson Lecture 26 NP-Completeness
Hard Problems Introduction to NP
Richard Anderson Lecture 28 NP-Completeness
CSE 589 Applied Algorithms Spring 1999
Presentation transcript:

Circuits CSE 373 Data Structures Lecture 22

3/12/03Circuits - Lecture 222 Readings Reading ›Sections and 9.7

3/12/03Circuits - Lecture 223 Euler Euler ( ): might be the most prolific mathematician of all times (analysis, differential geometry, number theory etc.) ›For example, e, the natural base for logarithms, is named after him; he introduced the notation f(x), the notation for complex numbers (a + i b) …. ›Contributions in optics, mechanics, magnetism, electricity ›“Read Euler, read Euler, he is our master in everything” (Quote from Laplace a 19 th Century French mathematician)

3/12/03Circuits - Lecture 224 Euler and Graph Theory

3/12/03Circuits - Lecture 225 The Seven Bridges Problem Each “area” is a vertex Each bridge is an edge Find a path that traverses each edge exactly once

3/12/03Circuits - Lecture 226 Related Problems: Puzzles Two problems: 1) Can you draw these without lifting your pen, drawing each line only once 2) Can you start and end at the same point. A B C

3/12/03Circuits - Lecture 227 Related Problems: Puzzles Puzzle A: 1) yes and 2) yes Puzzle B: 1) yes if you start at lowest right (or left) corner and 2) no Puzzle C: 1) no and 2) no

3/12/03Circuits - Lecture 228 Euler Paths and Circuits Given G(V,E), an Euler path is a path that contains each edge once (Problem 1) Given G(V,E) an Euler circuit is an Euler path that starts and ends at the same vertex (Problem 2)

3/12/03Circuits - Lecture 229 An Euler Circuit for Puzzle A

3/12/03Circuits - Lecture 2210 Euler Circuit Property A graph has an Euler circuit if and only if it is connected and all its vertices have even degrees (cf. Puzzle A) ›Necessary condition (only if): a vertex has to be entered and left, hence need an even number of edges at each vertex ›Sufficient condition: by construction (linear time algorithm)

3/12/03Circuits - Lecture 2211 Euler Path Property A graph has an Euler path if and only if it is connected and exactly two of its vertices have odd degrees (cf. Puzzle B) ›One of the vertices will be the start point and the other one will be the end point to construct it, add an edge (start,end). Now all vertices have even degrees. Build the Euler circuit starting from “start” and at the end delete the edge (start,end).

3/12/03Circuits - Lecture 2212 Back to Euler Seven Bridges Sorry, no Euler Circuit (not all vertices have even degrees) Sorry, no Euler path (more than 2 vertices have odd degrees)

3/12/03Circuits - Lecture 2213 Finding an Euler Circuit Check than one exists (all vertices have even degrees) Starting from a vertex v i (at random) While all edges have not been “marked” DFS(v i ) using unmarked edges (and marking them) until back to v i Pick a vertex v j on the (partial) circuit with a remaining unmarked edge and repeat the loop; Splice this new circuit in the old one and repeat.

3/12/03Circuits - Lecture 2214 Example A BC DE F G Pick vertex A DFS(A) yields circuit ABCA and edges (A,B),(B,C) and (C,A) are marked Pick a vertex in circuit with an unmarked edge, say B

3/12/03Circuits - Lecture 2215 Example (ct’d) A BC DE F G ABCA Picking B yields circuit BDECGB (note that when we reached C, we had to go to G since (C,B), (C,A) and (C,E) were marked Slice the green circuit in the blue one ABDECGBCA

3/12/03Circuits - Lecture 2216 Example (end) A BC DE F G ABDECGBCA Pick vertex with unmarked edge D DFS(D) yields DFEGD Splicing yields Euler circuit ABDFEGDECGBCA

3/12/03Circuits - Lecture 2217 Euler Circuit Complexity Find degrees of vertices: O(n) Mark each edge once (in each direction) thus traverse each edge once): O(m) ›This might require slightly improved adjacency list Splice the circuits:at most n cycles (use linked lists: O(n)) Linear time O(n+m)

3/12/03Circuits - Lecture 2218 Hamiltoniam Circuit A Graph G(V,E) has an hamiltonian circuit if there exists a path which goes through each vertex exactly once Seems closely related to Euler circuit It is NOT! Euler circuit can be solved in linear time Hamiltonian circuit requires exhaustive search (exponential time) in the worse case

3/12/03Circuits - Lecture 2219 Examples Does Graph I have an Euler circuit? an Hamiltonian circuit? Does Graph II have an Euler circuit? an Hamiltonian circuit?

3/12/03Circuits - Lecture 2220 Finding Hamiltonian Circuits Apparently easier “Yes” or “No” question: “Does G contain an Hamiltonian circuit?” ›NO known “easy” algorithm, i.e., no algorithm that runs in O(n p ), or polynomial time in the number of vertices ›Requires exhaustive search (brute force)

3/12/03Circuits - Lecture 2221 Example of Exhaustive Search How many paths? Let B be the average branching factor at each node for DFS Total number of paths to be examined B.B.B….B = O(B n ) Exponential time!

3/12/03Circuits - Lecture 2222 Orders of Magnitude

3/12/03Circuits - Lecture 2223 Time Complexity of Algorithms If one has to process n elements, can’t have algorithms running (worse case) in less than O(n) But what about binary search, deletemin in a heap, insert in an AVL tree etc.? ›The input has been preprocessed ›Array sorted for binary search, buildheap for the heap, AVL tree already has AVL property etc. all ops that took at least O(n)

3/12/03Circuits - Lecture 2224 The Complexity Class P Most of the algorithms we have seen have been polynomial time O(n p ) ›Searching (build the search structure and search it), sorting, many graph algorithms such as topological sort, shortest-path, Euler circuit ›They form the class P of algorithms that can be solved (worse case) in polynomial time

3/12/03Circuits - Lecture 2225 Are There Problems not in P? For some problems, there are no known algorithms that run (worse case) in polynomial time ›Hamiltonian circuit ›Circuit satisfiability Given a Boolean formula find an assignment of variables such that the formula is true (even if only 3 variables) ›Traveling Salesman problem Given a complete weighted graph G and an integer K, is there a circuit that visits all vertices of cost less than K ›Etc.

3/12/03Circuits - Lecture 2226 Undecidability There are problems that cannot be solved algorithmically: they are undecidable The most well-known one is the Turing Halting Problem ›Related to Gödels Theorem ›Turing proved that it is impossible to write a “computer program” that can read another computer program, and, if that program will run forever without stopping, tell us, after some finite (but unbounded) time this fact.

3/12/03Circuits - Lecture 2227 The Class NP NP : Non-deterministic Polynomial Time The class NP is the set of all problems for which a given solution can be checked in polynomial time Check via a non-deterministic algorithm i.e., one that is free to choose the correct path to the solution ›Don’t exist in practice but good for theoretical purposes ›In some sense check all possible paths in parallel in polynomial time Not all problems not in P are in NP ›E.g., undecidable problems

3/12/03Circuits - Lecture 2228 NP-complete Problems A subset of the NP class forms the NP- complete class A problem is NP-complete is any problem in NP can be polynomially reduced to it P1 can be reduced to P2 as follows ›Provide a mapping so that any instance of P1 can be transformed into an instance of P2 and map the answer back to the original ›polynomially reduced if all the work in transformations is done in polynomial time

3/12/03Circuits - Lecture 2229 Yes but… For the NP-complete problem to be defined, there must be an “original” NP- complete problem The satisfiability problem was proven (Cook 1971) to be NP-complete ›It is in NP (easy to check a solution) ›All problems in NP can be transformed to it (difficult proof involving simulating a Turing machine by a polynomial Boolean formula)

3/12/03Circuits - Lecture 2230 Does P  NP The $64,000 question in theoretical computer science If P = NP, then strive to find better algorithms for Hamiltonian path etc. If P  NP, then concentrate on better heuristics Strong suspicion that P  NP