LIMITATIONS OF ALGORITHM POWER

Slides:



Advertisements
Similar presentations
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Advertisements

Limitation of Computation Power – P, NP, and NP-complete
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 
© The McGraw-Hill Companies, Inc., Chapter 8 The Theory of NP-Completeness.
© The McGraw-Hill Companies, Inc., Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Discrete Structure Li Tak Sing( 李德成 ) Lectures
Computability and Complexity 23-1 Computability and Complexity Andrei Bulatov Search and Optimization.
Complexity 15-1 Complexity Andrei Bulatov Hierarchy Theorem.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
1 NP-Completeness Objectives: At the end of the lesson, students should be able to: 1. Differentiate between class P, NP, and NPC 2. Reduce a known NPC.
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
88- 1 Chapter 8 The Theory of NP-Completeness P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class.
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.
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.
DAST 2005 Week 4 – Some Helpful Material Randomized Quick Sort & Lower bound & General remarks…
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
1 The Theory of NP-Completeness 2 NP P NPC NP: Non-deterministic Polynomial P: Polynomial NPC: Non-deterministic Polynomial Complete P=NP? X = P.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
Programming & Data Structures
The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial.
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.
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.
P and NP. Computational Complexity Recall from our sorting examples at the start of class that we could prove that any sort would have to do at least.
P and NP.
TECH Computer Science NP-Complete Problems Problems  Abstract Problems  Decision Problem, Optimal value, Optimal solution  Encodings  //Data Structure.
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.
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.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
Lecture 6 NP Class. P = ? NP = ? PSPACE They are central problems in computational complexity.
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.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
Fundamentals of Informatics Lecture 14 Intractability and NP-completeness Bas Luttik.
Lecture 25 NP Class. P = ? NP = ? PSPACE They are central problems in computational complexity.
1 Ch 10 - NP-completeness Tractable and intractable problems Decision/Optimization problems Deterministic/NonDeterministic algorithms Classes P and NP.
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.
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
Chapter 10 NP-Complete Problems.
Decision Trees DEFINITION: DECISION TREE A decision tree is a tree in which the internal nodes represent actions, the arcs represent outcomes of an action,
Lecture 2-2 NP Class.
Decision trees Polynomial-Time
Lower Bound Theory.
Analysis and design of algorithm
ICS 353: Design and Analysis of Algorithms
Chapter 11 Limitations of Algorithm Power
P, NP and NP-Complete Problems
The Theory of NP-Completeness
P, NP and NP-Complete Problems
Algorithms CSCI 235, Spring 2019 Lecture 36 P vs
Our old list of problems
Complexity Theory: Foundations
Presentation transcript:

LIMITATIONS OF ALGORITHM POWER ANALYSIS AND DESIGN OF ALGORITHMS UNIT-V CHAPTER 11: LIMITATIONS OF ALGORITHM POWER

OUTLINE Limitations of Algorithm Power Decision Trees Decision Trees for Sorting Algorithms Decision Trees for Searching a Sorted Array P, NP, and NP-complete Problems P and NP Problems NP-Complete Problems

DECISION TREES a < b b < c a < c a c b c Performance of algorithms like searching, sorting can be studied with a device called the decision tree. yes a < b no no yes b < c no yes a < c a c b c Figure: Decision tree for finding a minimum of three numbers. Each internal node of a binary decision tree represents a key comparison indicated in the node, e.g., k < k' .

DECISION TREES The node’s left subtree contains the information about subsequent comparisons made if k < k‘, while its right subtree does the same for the case of k > k‘. Each leaf represents a possible outcome of the algorithm’s run on some input of size n. The number of leaves can be greater than number of outcomes because, for some algorithms, the same outcome can be arrived through a different chain of comparisons. The algorithm’s work on a particular input of size n can be traced by a path from the root to a leaf in its decision tree, and the number of comparisons made by the algorithm on such a run is equal to the number of edges in this path. Hence, the number of comparisons in the worst case is equal to the height of the algorithm’s decision tree.

DECISION TREES Decision Trees for Sorting Algorithms For any binary tree with l leaves and height h, h ≥ log2 l ….. (1) Inequality (1) puts a lower bound on the heights of binary decision trees. Such a bound is called the information- theoretic lower bound. Decision Trees for Sorting Algorithms Most sorting algorithms are comparison-based, i.e., they work by comparing elements in a list to be sorted. Therefore, by studying properties of decision trees for comparison-based sorting algorithms, we can derive important lower bounds on the time efficiencies of such algorithms.

a < b a < c b < c b < c b < a a < c b < a abc yes a < b no abc abc yes a < c no yes b < c no abc cba bac cba yes b < c no b < a no yes a < c no yes b < a a < b < c a < c < b c < a < b b < a < c b < c < a c < b < a Figure: Decision tree for the three-element selection sort. A triple above a node indicates the state of the array being sorted. Note the two redundant comparisons b < a with a single possible outcome because of the results of some previously made comparisons.

Decision Trees for Sorting Algorithms We can interpret an outcome of a sorting algorithm as finding a permutation of the element indices of an input list that puts the list’s elements in ascending order. For example, for the outcome a < c < b obtained by sorting a list a, b, c (refer previous slide), the permutation in question is 1, 3, 2. Hence, the number of possible outcomes for sorting an arbitrary n-element list is equal to n !. The worst-case number of comparisons made by comparison-based sorting algorithm cannot be less than log2 n ! : Cworst(n) ≥ log2 n ! Using Stirling’s formula for n!, we get log2 n! ≈ log2 √2Πn(n/e)n = nlog2 n – nlog2 e + log2 n + log2 2Π ≈ n log2 n 2 2 About n log2 n comparisons are necessary to sort an arbitrary n-element list by any comparison-based sorting algorithm.

Decision Trees for Sorting Algorithms We can also use decision trees for analyzing the average-case behavior of a comparison-based sorting algorithm. We can compute the average number of comparisons for a particular algorithm as the average depth of its decision tree’s leaves, i.e., as the average path length from the root to the leaves. For example, for the three-element insertion sort whose decision tree is given in next slide, this number is (2 + 3 + 3 + 2 + 3 + 3)/6 =2 2 . 3 Under the standard assumption that all n! outcomes of sorting are equally likely, the following lower bound on the average number of comparisons Cavg made by any comparison-based algorithm in sorting an n-element list has been proved: Cavg(n) ≥ log2 n! This lower bound is about n log2 n.

Figure: Decision tree for the three-element insertion sort. abc yes a < b no bac abc yes a < c no yes b < c no bca acb a < b < c b < a < c yes yes a < c no b < c no a < c < b c < a < b b < c < a c < b < a Figure: Decision tree for the three-element insertion sort.

Decision Trees for Searching a Sorted Array The decision trees can be used for establishing lower bounds on the number of key comparisons in searching a sorted array of n keys: A[0] < A[1] < . . . < A[n – 1]. The principal algorithm for this problem is binary search. The number of comparisons made by binary search in the worst case is given by the formula Cworst(n) = log2 n + 1 = log2 (n + 1) . we will use decision trees to determine whether this is the smallest possible number of comparisons. Since we are dealing with three-way comparisons in which search key K is compared with some element A[i] to see whether K <A[i], K=A[i], or K > A[i], it is natural to try using ternary decision trees.

A[1] A[0] A[2] A[1] A[3] <A[0] A[0] (A[0], A[1]) (A[1], A[2]) A[2] > A[0] = A[2] A[1] > < = > < = A[3] <A[0] A[0] (A[0], A[1]) (A[1], A[2]) A[2] < = > (A[2], A[3]) A[3] >A[3] Figure: Ternary decision tree for binary search in a four-element array. The leaves indicate either a matching element in the case of a successful search or a found interval that the search key belongs to in the case of an unsuccessful search. For an array of n elements, all such decision trees will have 2n + 1 leaves (n for successful searches and n+1 for unsuccessful ones).

Decision Trees for Searching a Sorted Array Since the minimum height h of a ternary tree with l leaves is log3 l , we get the following lower bound on the number of worst-case comparisons: Cworst(n) ≥ log3 (2n + 1) . To obtain a better lower bound, we should consider binary rather than ternary decision trees such as the one shown below: A[1] < > A[0] A[2] < > < > < A[0] (A[0], A[1]) (A[1], A[2]) A[3] < > (A[2], A[3]) > A[3] Figure: Binary decision tree for binary search in a four-element array.

Decision Trees for Searching a Sorted Array Internal nodes in such a tree (refer previous slide) correspond to the same three-way comparisons as before, but they also serve as terminal nodes for successful searches. Leaves therefore represent only unsuccessful searches, and there are n + 1 of them for searching an n-element array. The binary decision tree is simply the ternary decision tree with all the middle subtrees eliminated. For binary decision trees, Cworst(n) ≥ log2 (n + 1) . This inequality closes the gap between the lower bound and the number of worst-case comparisons made by binary search.

P, NP, AND NP-COMPLETE PROBLEMS 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. Problems that cannot be solved in polynomial time are called intractable. Problems like GCD of two integers, sorting, searching, checking connectivity, finding a minimum spanning tree, finding shortest paths in a weighted graph etc. can be solved in polynomial time.

P, NP, AND NP-COMPLETE PROBLEMS Class P is a class of decision problems that can be solved in polynomial time by (deterministic) algorithms. This class of problems is called polynomial. Some decision problems cannot be solved at all by any algorithm. Such problems are called undecidable. Example: Halting problem: given a computer program and an input to it, determine whether the program will halt on that input or continue working indefinitely on it. There are many important problems for which no polynomial-time algorithm has been found. Some of the best-known problems that fall into this category are: Hamiltonian circuit: Determine whether a given graph has a Hamiltonian circuit (a path that starts and ends at the same vertex and passes through all the other vertices exactly once).

P, NP, AND NP-COMPLETE PROBLEMS Traveling salesman: Find the shortest tour through n cities with known positive integer distances between them (find the shortest Hamiltonian circuit in a complete graph with positive integer weights). Partition problem: Given n positive integers, determine whether it is possible to partition them into two disjoint subsets with the same sum. Graph coloring: For a given graph, find its chromatic number (the smallest number of colors that need to be assigned to the graph’s vertices so that no two adjacent vertices are assigned the same color).

P, NP, AND NP-COMPLETE PROBLEMS A nondeterministic algorithm is a two-stage procedure that takes as its input an instance I of a decision problem and does the following: Nondeterministic (“guessing”) stage: An arbitrary string S is generated that can be thought of as a candidate solution to the given instance I. Deterministic (“verification”) stage: A deterministic algorithm takes both I and S as its input and outputs yes if S represents a solution to instance I. (If S is not a solution to instance I, the algorithm either returns no or is allowed not to halt at all.) Class NP is the class of decision problems that can be solved by nondeterministic polynomial algorithms. This class of problems is called nondeterministic polynomial.

P ⊆ NP . This is true because, if a problem is in P, we can use the deterministic polynomial-time algorithm that solves it in the verification-stage of a nondeterministic algorithm that simply ignores string S generated in its nondeterministic (“guessing”) stage. What problems are in NP? Hamiltonian circuit existence Traveling salesman problem Partition problem: Is it possible to partition a set of n integers into two disjoint subsets with the same sum? 18

P, NP, AND NP-COMPLETE PROBLEMS A decision problem D1 is said to be polynomially reducible to a decision problem D2 if there exists a function t that transforms instances of D1 to instances of D2 such that 1. t maps all yes instances of D1 to yes instances of D2 and all no instances of D1 to no instances of D2; 2. t is computable by a polynomial-time algorithm. This definition implies that if a problem D1 is polynomially reducible to some problem D2 that can be solved in polynomial time, then problem D1 can also be solved in polynomial time.

NP-Complete A decision problem D is said to be NP-complete if 1. it belongs to class NP; 2. every problem in NP is polynomially reducible to D. The definition of NP-completeness implies that if there exists a deterministic polynomial-time algorithm for just one NP-complete problem, then every problem in NP can be solved in polynomial time by a deterministic algorithm, and hence P = NP. NP problems NP-complete problem Figure: Notion of an NP-complete problem. Polynomial-time reductions of NP problems to an NP-complete problems are shown by arrows. 20

End of Chapter 11