Algorithm Analysis.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

NP-Complete Problems CIT 596, Spring Problems that Cross the Line What if a problem has: o An exponential upper bound o A polynomial lower bound.
Introduction to Algorithms NP-Complete
1 P, NP, and NP-Complete Dr. Ying Lu RAIK 283 Data Structures & Algorithms.
Complexity Classes: P and NP
NP-Hard Nattee Niparnan.
JAYASRI JETTI CHINMAYA KRISHNA SURYADEVARA
Computability & Complexity. Scenario I can’t write this program because I’m too dumb.
Copyright © Cengage Learning. All rights reserved.
1 The Limits of Computation Intractable and Non-computable functions.
NP-complete and NP-hard problems Transitivity of polynomial-time many-one reductions Concept of Completeness and hardness for a complexity class Definition.
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 
Complexity 15-1 Complexity Andrei Bulatov Hierarchy Theorem.
Complexity 11-1 Complexity Andrei Bulatov Space Complexity.
Computability and Complexity 13-1 Computability and Complexity Andrei Bulatov The Class NP.
1 Introduction to Computability Theory Lecture15: Reductions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 21 Instructor: Paul Beame.
NP-Complete Problems Reading Material: Chapter 10 Sections 1, 2, 3, and 4 only.
The Theory of NP-Completeness
NP-Complete Problems Problems in Computer Science are classified into
Analysis of Algorithms CS 477/677
Chapter 11: Limitations of Algorithmic Power
Toward NP-Completeness: Introduction Almost all the algorithms we studies so far were bounded by some polynomial in the size of the input, so we call them.
Complexity Issues Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
Halting Problem. Background - Halting Problem Common error: Program goes into an infinite loop. Wouldn’t it be nice to have a tool that would warn us.
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.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
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.
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.
CSCI 3160 Design and Analysis of Algorithms Tutorial 10 Chengyu Lin.
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
1 Chapter 34: NP-Completeness. 2 About this Tutorial What is NP ? How to check if a problem is in NP ? Cook-Levin Theorem Showing one of the most difficult.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
NP-Complete problems.
NP-Complete Problems Algorithm : Design & Analysis [23]
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.
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.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
Chapter 11 Introduction to Computational Complexity Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
NPC.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 8: Crash Course in Computational Complexity.
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.
1 Ch 10 - NP-completeness Tractable and intractable problems Decision/Optimization problems Deterministic/NonDeterministic algorithms Classes P and NP.
1 Computability Tractable, Intractable and Non-computable functions.
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.
CS 154 Formal Languages and Computability May 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
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.
CSC 172 P, NP, Etc.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
More NP-Complete and NP-hard Problems
P & NP.
Richard Anderson Lecture 26 NP-Completeness
Hard Problems Introduction to NP
ICS 353: Design and Analysis of Algorithms
How Hard Can It Be?.
Halting Problem.
Chapter 11 Limitations of Algorithm Power
NP-Complete Problems.
CSC 380: Design and Analysis of Algorithms
P, NP and NP-Complete Problems
P, NP and NP-Complete Problems
RAIK 283 Data Structures & Algorithms
Presentation transcript:

Algorithm Analysis

Assignment #8 Submit in PDF format ONLY !!! Assignment will NOT be accepted in format other than pdf. See email and blackboard announcements for places to find software for pdf conversion. engineering (ECJ) labs undergraduate library. There are also websites that let you do this for free e.g.- http://www.pdfonline.com/ http://createpdf.adobe.com/ Word doc files get corrupted in the submission system so they will not be accepted for this assignment.

Final Exam Course:E E 312 INTRODUCTION TO PROGRAMMING Instructor:BARBER, K WEDNESDAY, MAY 10, 9-12 N Exam Room:      JES A121A  

Algorithm Analysis Estimating the time required for a program Determining a relative computation time among programs Understanding the limits of computation The Halting Problem Classifying particularly hard problems NP-Complete problems

Understanding the limits of computation

Computability As we have seen, typical algorithms run the gamut from O(log n) to O(n3), where problems solved using O(n) or O(log n) are considered relatively easy On the other end of the spectrum are truly hard problems: Impossible ("undecidable") problems Very hard (NP-Complete) problems

Undecidable Problems [http://www.cgl.uwaterloo.ca/~csk/halt/] An algorithm is a solution to a problem if it correctly provides the appropriate answer to the problem and is guaranteed to always run in a finite amount of time. A problem is decidable if it has a solution. If there is no algorithm that solves the problem in a finite amount of time, the problem is undecidable.

Generally stated Halting Problem [wikipedia] In computability theory the halting problem is a decision problem which can be informally stated as follows: Given a description of a program and its initial input, determine whether the program, when executed on this input, ever halts (completes). The alternative is that it runs forever without halting. Alan Turing proved in 1936 that a general algorithm to solve the halting problem for all possible inputs cannot exist. We say that the halting problem is undecidable.

Impossible "Undecidable" Problems The Halting Problem Probably the most commonly cited "undecidable" problem Problem: Is it possible for your C compiler to have an extra feature that checks not only syntax errors but also checks for infinite loops? Answer: NO! Intuitive Reason: Such a program might have a hard time checking itself. Suggests the term "recursively undecidable"

Informal Proof of the Halting Problem If an infinite loop-checking program could be written, it should be able to check itself. Assume a program called Loop(P) Loop takes as input a program P, which takes itself as input (i.e., P(P) ) Loop returns "Yes" if P loops when run on itself Loop goes into an infinite loop if P terminates when run on itself (instead of returning "No")

Informal Proof of the Halting Problem (cont'd) What if P = Loop (i.e., input to Loop is Loop itself) ? By definition, Loop either halts or does not halt However, both these possibilities lead to contradictions.

Informal Proof of the Halting Problem (cont'd) Suppose P = Loop and we were to run Loop(Loop) Case 1: If P(P) terminates then Loop(P) should go into an infinite loop However, then we would have a contradiction: Loop(Loop) would both terminate and go into an infinite loop at the same time Case 2: If P(P) goes into an infinite loop then Loop(P) should terminate Once again, Loop(Loop) would go into an infinite loop and terminate at the same time Therefore, Loop cannot exist. Assume a program called Loop(P) Loop takes as input a program P, which takes itself as input (i.e., P(P) ) Loop returns "Yes" if P loops when run on itself Loop goes into an infinite loop if P terminates when run on itself (instead of returning "No")

Another informal proof for the Halting problem Now suppose that someone claims to have found an algorithm halt(p, i) that returns true if p describes the name of a program that halts when given as input the string I false otherwise. Construct another program trouble(s) that uses halt as a subroutine: function trouble(string s) if halt(s, s) == false return true else loop forever

Another informal proof for the Halting problem function trouble(string s) if halt(s, s) == false return true else loop forever All programs can be represented by strings, there is a string t that represents the program trouble. Does trouble(t) halt? Consider both cases: If trouble(t) halts, it must be because halt(t, t) returned false, but that would mean that trouble(t) should not have halted. If trouble(t) runs forever, it is either because halt itself runs forever, or because it returned true. This would mean either that halt does not work for every valid input, or that trouble(t) should have halted. Either case concludes that halt did not give a correct answer, contrary to the original claim. Since the same reasoning applies to any program that someone might offer as a solution to the halting problem, there can be no solution.

Pitfalls in Understanding [wikipedia] Would you ask, “Is there an algorithm that can return a third option for some programs, such as "undecidable" or "would lead to a contradiction." ? This reflects a misunderstanding of decidability. It is easy to construct one algorithm that always answers "halts" and another that always answers "doesn't halt." For any specific program and input, one of these two algorithms answers correctly, even though nobody may know which one. The difficulty of the halting problem lies not in particular programs, but in the requirement that a solution must work for all programs.

Other Reference for the Halting Problem http://plus.maths.org.uk/issue5/turing/

Classifying particularly hard problems

NP problems Computational complexity theory is part of the theory of computation dealing with the resources required during computation to solve a given problem. time (how many steps it takes to solve a problem) space (how much memory it takes to solve a problem). the class P consists of all those decision problems that can be solved on a deterministic sequential machine in an amount of time that is polynomial in the size of the input; the class NP consists of all those decision problems whose positive solutions can be verified in polynomial time given the right information, or equivalently, whose solution can be found in polynomial time on a non-deterministic machine.

Polynomial Time polynomial time refers to the computation time of a problem where the time, m(n), is no greater than a polynomial function of the problem size, n. Written mathematically, m(n) = O(nk) where k is a constant (which may depend on the problem). Polynomial time is the smallest time-complexity class on a deterministic machine which is robust in terms of machine model changes, and is the smallest class closed under composition of subproblems. Subclasses of polynomial time Linear time: O(n) Quadratic time: O(n2) Cubic time: O(n3)

Very hard (NP-Complete) problems Problems in class NP (nondeterministic polynomial-time) Not impossible, but still very hard A "Nondeterministic computer" is a theoretical construct A deterministic machine executes an instruction and goes to the next instruction, which is unique A nondeterministic machine is free to "guess" the next instruction (and guess very well) Can't build a nondeterministic computer, but still a useful theoretical construct

Problems in the Class NP Phrase the problem as a yes/no question. The problem is in NP if, in polynomial time, we can prove that any "yes" instance is correct. We don't have to worry about "no" instances because the program always makes the "right" choice. Includes all problems that have polynomial-time solutions.

NP-complete problems [wikipedia] In complexity theory, the NP-complete problems are the most difficult problems in NP ("non-deterministic polynomial time") in the sense that they are the ones most likely not to be in P. The complexity class consisting of all NP-complete problems is sometimes referred to as NP-C. One example of an NP-complete problem is the subset sum problem which is: given a finite set of integers, determine whether any non-empty subset of them sums to zero. A supposed answer is very easy to verify for correctness, but no one knows a significantly faster way to solve the problem than to try every single possible subset, which is very slow.

NP-Complete NP-complete problems are a subset of all problems known to be in NP that are the hardest. An NP-complete problem has the property that any problem in NP can be reduced to it. Reducing a problem P1 to P2 Provide a mapping to transform an instance of P1 to P2 Solve P2 Map the P2 answer back to a P1 answer Therefore, an NP-complete problem can be used as a "subroutine" to solve any problem in NP If any NP-complete problem can be solved in polynomial time, then every problem in NP must have a polynomial time solution

Example NP-Complete Problems Hamiltonian Cycle problem Find an ordering of the vertices in an undirected graph such that each vertex is visited exactly once.

Example NP-Complete Problems (cont'd) Traveling Salesman Given a complete graph with edge costs, and an integer K, is there a simple cycle that visits all vertices and has total cost ≤ K?

Example NP-Complete Problems [wikipedia] The Boolean satisfiability problem (SAT) is a decision problem considered in complexity theory. An instance of the problem is a Boolean expression written using only AND, OR, NOT, variables, and parentheses. The question is: given the expression, is there some assignment of TRUE and FALSE values to the variables that will make the entire expression true? In mathematics, a formula of propositional logic is said to be satisfiable if truth-values can be assigned to its variables in a way that makes the formula true. The class of satisfiable propositional formulas is NP-complete.

Example NP-Complete Problems Satisfiability Takes as input a boolean expression and asks whether the expression has an assignment to the variable that gives a value of 1.

Transforming Hamiltonian Cycle into Traveling Salesman Construct a new graph GTS which has same vertices as GH. For GTS, each edge has weight of 1 if it was in GH, and 2 otherwise. Choose K = |V|. If GH has a Hamiltonian cycle if and only if GTS has a traveling salesman tour of total weight |V|.

Conclusion As an engineer developing software, you must… Know the limits of computation when attacking a problem. Is the problem decidable? Is your algorithm decidable? Be able to analyze the efficiency of your algorithms. What is the algorithm's Big-Oh growth with respect to input? Understand the relative difficulty of the problem you're trying to solve by comparing to problems with known difficulty. Can the problem be related to an NP-Complete problem?

References "The Stony Brook Algorithm Repository," <http://www.cs.sunysb.edu/~algorith/> Data Structures and Algorithm Analysis in C, Weiss