Analysis and design of algorithm

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

Problems and Their Classes
NP-Hard Nattee Niparnan.
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
The Theory of NP-Completeness
CPE702 Complexity Classes Pruet Boonma Department of Computer Engineering Chiang Mai University Based on Material by Jenny Walter.
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
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
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
1.1 Chapter 1: Introduction What is the course all about? Problems, instances and algorithms Running time v.s. computational complexity General description.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
1 CSC 421: Algorithm Design & Analysis Spring 2013 Complexity & Computability  lower bounds on problems brute force, decision trees, adversary arguments,
Chapter 11 Limitations of Algorithm Power. Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples:
CSCE350 Algorithms and Data Structure
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 11 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Computational Complexity Polynomial time O(n k ) input size n, k constant Tractable problems solvable in polynomial time(Opposite Intractable) Ex: sorting,
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.
P and NP.
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.
1 Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: b number of comparisons needed to find the.
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.
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.
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.
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.
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.
1 CSC 421: Algorithm Design & Analysis Spring 2014 Complexity & lower bounds  brute force  decision trees  adversary arguments  problem reduction.
NP Completeness Piyush Kumar. Today Reductions Proving Lower Bounds revisited Decision and Optimization Problems SAT and 3-SAT P Vs NP Dealing with NP-Complete.
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.
Lecture. Today Problem set 9 out (due next Thursday) Topics: –Complexity Theory –Optimization versus Decision Problems –P and NP –Efficient Verification.
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 P and NP. 2 Introduction The Traveling Salesperson problem and thousands of other problems are equally hard in the sense that if we had an efficient.
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.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
The Theory of NP-Completeness
Limitation of Computation Power – P, NP, and NP-complete
The NP class. NP-completeness
Chapter 10 NP-Complete Problems.
Hard Problems Introduction to NP
CSC 421: Algorithm Design & Analysis
NP-Completeness Yin Tat Lee
Lower Bound Theory.
ICS 353: Design and Analysis of Algorithms
CS 583 Fall 2006 Analysis of Algorithms
Chapter 11 Limitations of Algorithm Power
NP-Complete Problems.
CSC 380: Design and Analysis of Algorithms
NP-Completeness Yin Tat Lee
NP-Completeness Reference: Computers and Intractability: A Guide to the Theory of NP-Completeness by Garey and Johnson, W.H. Freeman and Company, 1979.
P, NP and NP-Complete Problems
The Theory of NP-Completeness
CSE 589 Applied Algorithms Spring 1999
P, NP and NP-Complete Problems
Algorithms CSCI 235, Spring 2019 Lecture 36 P vs
Our old list of problems
RAIK 283 Data Structures & Algorithms
Complexity Theory: Foundations
Presentation transcript:

Analysis and design of algorithm Sub code:10CS43 Analysis and design of algorithm Unit-6 Engineered for Tomorrow Presented by Shruthi N Asst.Professor CSE, MVJCE 12/8/13

Problems Some problems cannot be solved by any algorithms 2 Engineered for Tomorrow Problems Some problems cannot be solved by any algorithms Other problems can be solved algorithmically but not in polynomial time This topic deals with the question of intractability: which problems can and cannot be solved in polynomial time. This well-developed area of theoretical computer science is called computational complexity.

3 Engineered for Tomorrow Problems In the study of the computational complexity of problems, the first concern of both computer scientists and computing professionals is whether a given problem can be solved in polynomial time by some algorithm.

Polynomial time Definition: 4 Engineered for Tomorrow Polynomial time Definition: We say that an algorithm solves a problem in polynomial time if its worst-case time efficiency belongs to O(p(n)) where p(n) is a polynomial of the problem’s input size n. Problems that can be solved in polynomial time are called tractable and ones that can not be solved in polynomial time are all intractable.

5 Engineered for Tomorrow Intractability we can not solve arbitrary instances of intractable problems in a reasonable amount of time unless such instances are very small. Although there might be a huge difference between the running time in O(p(n)) for polynomials of drastically different degree, there are very few useful algorithms with degree of polynomial higher than three.

6 Engineered for Tomorrow P and NP Problems Most problems discussed in this subject can be solved in polynomial time by some algorithms We can think about problems that can be solved in polynomial time as a set that is called P.

7 Engineered for Tomorrow Class NP NP (Nondeterministic Polynomial): class of decision problems whose proposed solutions can be verified in polynomial time = solvable by a nondeterministic polynomial algorithm

Nondeterministic polynomial algorithm 8 Engineered for Tomorrow Nondeterministic polynomial algorithm A Nondeterministic polynomial algorithm is an abstract two- stage procedure that: Generates a random string purported to solve the problem Checks whether this solution is correct in polynomial time By definition, it solves the problem if it’s capable of generating and verifying a solution on one of its tries

What problems are in NP? Hamiltonian circuit existence 9 9 Engineered for Tomorrow What problems are in NP? Hamiltonian circuit existence Traveling salesman problem Knapsack problem Partition problem: Is it possible to partition a set of n integers into two disjoint subsets with the same sum?

1010 Engineered for Tomorrow Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: number of comparisons needed to find the largest element in a set of n numbers number of comparisons needed to sort an array of size n number of comparisons necessary for searching in a sorted array number of multiplications needed to multiply two n-by-n matrices

Lower Bounds (cont.) 1111 Lower bound can be an exact count Engineered for Tomorrow Lower Bounds (cont.) Lower bound can be an exact count an efficiency class Tight lower bound: there exists an algorithm with the same efficiency as the lower bound Problem Lower bound Tightness sorting (comparison-based) (nlog n) yes searching in a sorted array (log n) yes element uniqueness (nlog n) yes n-digit integer multiplication (n) unknown multiplication of n-by-n matrices (n2) unknown

Methods for Establishing Lower Bounds 1212 Engineered for Tomorrow Methods for Establishing Lower Bounds trivial lower bounds information-theoretic arguments (decision trees) adversary arguments problem reduction

1313 Engineered for Tomorrow Trivial Lower Bounds Trivial lower bounds: based on counting the number of items that must be processed in input and generated as output Examples finding max element -- n steps or n/2 comparisons polynomial evaluation sorting element uniqueness Hamiltonian circuit existence Conclusions may and may not be useful be careful in deciding how many elements must be processed

1414 Engineered for Tomorrow Decision Trees Decision tree — a convenient model of algorithms involving comparisons in which: internal nodes represent comparisons leaves represent outcomes (or input cases) Decision tree for 3-element insertion sort

Decision Trees and Sorting Algorithms 1515 Engineered for Tomorrow Decision Trees and Sorting Algorithms Any comparison-based sorting algorithm can be represented by a decision tree (for each fixed n) Number of leaves (outcomes)  n! Height of binary tree with n! leaves  log2n! Minimum number of comparisons in the worst case  log2n! for any comparison-based sorting algorithm, since the longest path represents the worst case and its length is the height log2n!  n log2n (by Sterling approximation) This lower bound is tight (mergesort or heapsort)

1616 Engineered for Tomorrow Adversary Arguments Adversary argument: It’s a game between the adversary and the (unknown) algorithm. The adversary has the input and the algorithm asks questions to the adversary about the input. The adversary tries to make the algorithm work the hardest by adjusting the input (consistently). It wins the “game” after the lower bound time (lower bound proven) if it is able to come up with two different inputs. Example 1: “Guessing” a number between 1 and n using yes/no questions (Is it larger than x?) Adversary: Puts the number in a larger of the two subsets generated by last question

Contd.. Example 2: Merging two sorted lists of size n Engineered for Tomorrow Contd.. Example 2: Merging two sorted lists of size n a1 < a2 < … < an and b1 < b2 < … < bn Adversary: Keep the ordering b1 < a1 < b2 < a2 < … < bn < an in mind and answer comparisons consistently Claim: Any algorithm requires at least 2n-1 comparisons to output the above ordering (because it has to compare each pair of adjacent elements in the ordering) 12/8/13

Lower Bounds by Problem Reduction 1818 Engineered for Tomorrow Lower Bounds by Problem Reduction Fact: If problem Q can be “reduced” to problem P, then Q is at least as easy as P, or equivalent, P is at least as hard as Q. Reduction from Q to P: Design an algorithm for Q using an algorithm for P as a subroutine. Idea: If problem P is at least as hard as problem Q, then a lower bound for Q is also a lower bound for P. Hence, find problem Q with a known lower bound that can be reduced to problem P in question. Example: P is finding MST for n points in Cartesian plane, and Q is element uniqueness problem (known to be in (nlogn))

Problem Types: Optimization and Decision 1919 Engineered for Tomorrow Problem Types: Optimization and Decision Optimization problem: find a solution that maximizes or minimizes some objective function Decision problem: answer yes/no to a question Many problems have decision and optimization versions. E.g.: traveling salesman problem optimization: find Hamiltonian cycle of minimum length decision: find Hamiltonian cycle of length = L Decision problems are more convenient for formal investigation of their complexity.

2020 Engineered for Tomorrow Class P P: the class of decision problems that are solvable in O(p(n)) time, where p(n) is a polynomial of problem’s input size n Examples: searching element uniqueness graph connectivity graph acyclicity primality testing (finally proved in 2002)

2121 Engineered for Tomorrow Class NP NP (nondeterministic polynomial): class of decision problems whose proposed solutions can be verified in polynomial time = solvable by a nondeterministic polynomial algorithm A nondeterministic polynomial algorithm is an abstract two- stage procedure that: generates a solution of the problem (on some input) by guessing checks whether this solution is correct in polynomial time

Engineered for Tomorrow Contd.. By definition, it solves the problem if it’s capable of generating and verifying a solution on one of its tries Why this definition? led to development of the rich theory called “computational complexity” 12/8/13

What other problems are in NP? 2323 Engineered for Tomorrow What other problems are in NP? Hamiltonian circuit existence Partition problem: Is it possible to partition a set of n integers into two disjoint subsets with the same sum? Decision versions of TSP, knapsack problem, graph coloring, and many other combinatorial optimization problems.

2424 Engineered for Tomorrow NP-Complete Problems A decision problem D is NP-complete if it is as hard as any problem in NP, i.e., D is in NP every problem in NP is polynomial-time reducible to D Cook’s theorem (1971): CNF-sat is NP-complete

NP-Complete Problems (cont.) 2525 Engineered for Tomorrow NP-Complete Problems (cont.) Other NP-complete problems obtained through polynomial- time reductions from a known NP-complete problem Examples: TSP, knapsack, partition, graph-coloring and hundreds of other problems of combinatorial nature

P = NP ? Dilemma Revisited 2626 Engineered for Tomorrow P = NP ? Dilemma Revisited P = NP would imply that every problem in NP, including all NP-complete problems, could be solved in polynomial time If a polynomial-time algorithm for just one NP-complete problem is discovered, then every problem in NP can be solved in polynomial time, i.e. P = NP Most but not all researchers believe that P  NP , i.e. P is a proper subset of NP. If P  NP, then the NP-complete problems are not in P, although many of them are very useful in practice.

Engineered for Tomorrow Assignment questions 1. What are decision trees? Explain with example, how decision trees are used in sorting algorithms. (10 Marks) Dce 2012 2. Explain the concepts of P, NP, and NP – complete problems. Dec 2012. 3. Define the following: i) Tractable Problems, ii) Class p, iii) Class NP, iv) Polynomial Reduction, v) NP Complete June 2012, 05 marks 4. State subset sum Problem. Use backtracking, obtain a solution to the subset sum problem by taking S={6, 8, 2, 14} and d=16. June 2012, 07 marks 5. Explain approximation algorithms for NP-hard problems in general. Also discuss approximation algorithms for knapsack problem. June 2012, 08 marks 12/8/13

Engineered for Tomorrow Thank You..