Reductions. Reduction. Linear Time Reduction: Examples. Linear Time Reductions

Similar documents
Algorithms 6.5 REDUCTIONS. designing algorithms establishing lower bounds classifying problems intractability

NP and Computational Intractability

COP 4531 Complexity & Analysis of Data Structures & Algorithms

1. Introduction Recap

8. INTRACTABILITY I. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley. Last updated on 2/6/18 2:16 AM

Algorithms. Algorithms. Algorithms 6.5 R EDUCTIONS. introduction designing algorithms. establishing lower bounds classifying problems intractability

Easy Problems vs. Hard Problems. CSE 421 Introduction to Algorithms Winter Is P a good definition of efficient? The class P

10.3: Intractability. Overview. Exponential Growth. Properties of Algorithms. What is an algorithm? Turing machine.

8.1 Polynomial-Time Reductions. Chapter 8. NP and Computational Intractability. Classify Problems

4/12/2011. Chapter 8. NP and Computational Intractability. Directed Hamiltonian Cycle. Traveling Salesman Problem. Directed Hamiltonian Cycle

CHAPTER 3 FUNDAMENTALS OF COMPUTATIONAL COMPLEXITY. E. Amaldi Foundations of Operations Research Politecnico di Milano 1

Limitations of Algorithm Power

Computational Intractability 2010/4/15. Lecture 2

Algorithm Design and Analysis

A difficult problem. ! Given: A set of N cities and $M for gas. Problem: Does a traveling salesperson have enough $ for gas to visit all the cities?

Polynomial-Time Reductions

Intractability. A difficult problem. Exponential Growth. A Reasonable Question about Algorithms !!!!!!!!!! Traveling salesperson problem (TSP)

Computational Complexity. IE 496 Lecture 6. Dr. Ted Ralphs

CS 301: Complexity of Algorithms (Term I 2008) Alex Tiskin Harald Räcke. Hamiltonian Cycle. 8.5 Sequencing Problems. Directed Hamiltonian Cycle

Polynomial-time Reductions

Algorithms Design & Analysis. Approximation Algorithm

7.8: Intractability. Overview. Exponential Growth. Properties of Algorithms. What is an algorithm? Turing machine.

SAT, NP, NP-Completeness

4/30/14. Chapter Sequencing Problems. NP and Computational Intractability. Hamiltonian Cycle

Lecture 18: P & NP. Revised, May 1, CLRS, pp

NP and Computational Intractability

Chapter 8. NP and Computational Intractability

7.8 Intractability. Overview. Properties of Algorithms. Exponential Growth. Q. What is an algorithm? A. Definition formalized using Turing machines.

Algorithm Design and Analysis

Complexity, P and NP

4/19/11. NP and NP completeness. Decision Problems. Definition of P. Certifiers and Certificates: COMPOSITES

Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA.

P, NP, NP-Complete, and NPhard

Chapter 8. NP and Computational Intractability. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Admin NP-COMPLETE PROBLEMS. Run-time analysis. Tractable vs. intractable problems 5/2/13. What is a tractable problem?

8.5 Sequencing Problems. Chapter 8. NP and Computational Intractability. Hamiltonian Cycle. Hamiltonian Cycle

CS 5114: Theory of Algorithms

Announcements. Analysis of Algorithms

NP Complete Problems. COMP 215 Lecture 20

3/22/2018. CS 580: Algorithm Design and Analysis. 8.3 Definition of NP. Chapter 8. NP and Computational Intractability. Decision Problems.

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

ECS122A Handout on NP-Completeness March 12, 2018

Algorithms and Theory of Computation. Lecture 22: NP-Completeness (2)

CSC 373: Algorithm Design and Analysis Lecture 15

NP Completeness and Approximation Algorithms

Algorithms. Algorithms. Algorithms 6.5 R EDUCTIONS. introduction designing algorithms. establishing lower bounds classifying problems.

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

Computational Complexity and Intractability: An Introduction to the Theory of NP. Chapter 9

Essential facts about NP-completeness:

CS 320, Fall Dr. Geri Georg, Instructor 320 NP 1

CS 580: Algorithm Design and Analysis

3/22/2018. CS 580: Algorithm Design and Analysis. Circuit Satisfiability. Recap. The "First" NP-Complete Problem. Example.

Correctness of Dijkstra s algorithm

CSC 1700 Analysis of Algorithms: P and NP Problems

Algorithm Design and Analysis

P and NP. Inge Li Gørtz. Thank you to Kevin Wayne, Philip Bille and Paul Fischer for inspiration to slides

VIII. NP-completeness

NP-Completeness. Subhash Suri. May 15, 2018

Computational Complexity

NP completeness and computational tractability Part II

8.5 Sequencing Problems

CS 580: Algorithm Design and Analysis

Design and Analysis of Algorithms

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University

P and NP. Warm Up: Super Hard Problems. Overview. Problem Classification. Tools for classifying problems according to relative hardness.

Lecture 19: Finish NP-Completeness, conp and Friends

Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter Some Problems. A Brief History of Ideas

Theory of Computation CS3102 Spring 2014 A tale of computers, math, problem solving, life, love and tragic death

NP-complete problems. CSE 101: Design and Analysis of Algorithms Lecture 20

Spring Lecture 21 NP-Complete Problems

Chapter 8. NP and Computational Intractability. CS 350 Winter 2018

More NP-Complete Problems

CSC 421: Algorithm Design & Analysis. Spring 2018

NP-Completeness. NP-Completeness 1

Data Structures in Java

CS 5114: Theory of Algorithms. Tractable Problems. Tractable Problems (cont) Decision Problems. Clifford A. Shaffer. Spring 2014

CS 583: Algorithms. NP Completeness Ch 34. Intractability

CS/COE

Lecture 4: NP and computational intractability

Analysis of Algorithms. Unit 5 - Intractable Problems

In complexity theory, algorithms and problems are classified by the growth order of computation time as a function of instance size.

Unit 1A: Computational Complexity

Introduction. Pvs.NPExample

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

NP-Completeness. f(n) \ n n sec sec sec. n sec 24.3 sec 5.2 mins. 2 n sec 17.9 mins 35.

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

Intro to Theory of Computation

Computational Complexity

Lecture 18: More NP-Complete Problems

Discrete Optimization 2010 Lecture 10 P, N P, and N PCompleteness

NP-COMPLETE PROBLEMS. 1. Characterizing NP. Proof

BBM402-Lecture 11: The Class NP

1.1 P, NP, and NP-complete

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch]

NP Completeness. CS 374: Algorithms & Models of Computation, Spring Lecture 23. November 19, 2015

4/22/12. NP and NP completeness. Efficient Certification. Decision Problems. Definition of P

NP-Completeness. Until now we have been designing algorithms for specific problems

P,NP, NP-Hard and NP-Complete

Automata Theory CS Complexity Theory I: Polynomial Time

Introduction to Complexity Theory

Transcription:

Reduction Reductions Problem X reduces to problem Y if given a subroutine for Y, can solve X. Cost of solving X = cost of solving Y + cost of reduction. May call subroutine for Y more than once. Ex: X = baseball elimination, Y = max flow. Linear time reductions Polynomial time reductions NP-completeness Consequences: Establish relative difficulty between two problems. (classify problems) Given algorithm for Y, can also solve X. (design algorithms) If X is hard, then so is Y. (establish intractability) Princeton University COS 6 Algorithms and Data Structures Spring 004 Kevin Wayne http://www.princeton.edu/~cos6 Linear Time Reductions Linear Time Reduction: Examples Problem X linear reduces to problem Y if X can be solved with: Linear number of standard computational steps. One call to subroutine for Y. Notation: X L Y. Examples we've already seen in the course. Removing duplicates reduces to sorting. Voronoi diagram reduces to Delaunay triangulation. Arbitrage reduces to negative cycle detection. Bipartite matching reduces to max flow. Brewer's problem reduces to linear programming. more generally, if given a O(f(N)) time subroutine for Y, can solve X in O(f(N)) time PRIME: Given (the decimal representation of) an integer x, is x prime? COMPOSITE: Given an integer x, does x have a nontrivial factor? FACTOR: Given two integers x and y, does x have a nontrivial factor less than y? other than 1 and x Claim. COMPOSITE L PRIME. composite (x) if (prime(x)) return false; return true; Other most common type of reduction. X polynomial reduces to Y. Stay tuned for NP-completeness. 4

Linear Time Reduction: Examples Linear Time Reduction: Examples PRIME: Given (the decimal representation of) an integer x, is x prime? COMPOSITE: Given an integer x, does x have a nontrivial factor? FACTOR: Given two integers x and y, does x have a nontrivial factor less than y? other than 1 and x Claim. PRIME L COMPOSITE. prime (x) if (composite(x)) return false; return true; PRIME: Given (the decimal representation of) an integer x, is x prime? COMPOSITE: Given an integer x, does x have a nontrivial factor? FACTOR: Given two integers x and y, does x have a nontrivial factor less than y? other than 1 and x Claim. COMPOSITE L FACTOR. Is 67791 composite? Does 67791 have a nontrivial factor less than 67791? Yes, 67791 = 7919 797. composite (x) if (factor(x, x)) return true; return false; 6 Problem Equivalence Primality Testing and Factoring Tool for classifying problems. Equivalence: If X L Y and Y L X then we write X L Y. given any algorithm for X, can solve Y in same running time, and vice versa Transitivity: if X L Y and Y L Z then X L Z. Equivalence: PRIME L COMPOSITE and COMPOSITE L PRIME. We established: PRIME L FACTOR. Natural question: Does FACTOR L PRIME? Consensus opinion = no. State-of-the-art. PRIME is in P. FACTOR not believed to be in P. Transitivity: PRIME L COMPOSITE L FACTOR. RSA cryptosystem. Based on dichotomy between two problems. To use RSA, must generate large primes efficiently. Can break RSA with efficient factoring algorithm. 7 8

Reduction Gone Wrong Undirected Shortest Path Reduces to Directed Shortest Path Caveat. System designer specs the interfaces for project. One programmer might implement iscomposite using isprime. Another programmer might implement isprime using iscomposite. Be careful to avoid infinite reduction loops in practice. Undirected shortest path (with nonnegative weights) linearly reduces to directed shortest path. Replace each directed arc by two undirected arcs. Shortest directed path will use each edge at most once. 9 public static boolean iscomposite(int x) { if (isprime(x)) return false; return true; } s 4 1 1 9 1 6 1 t 9 public static boolean isprime(int x) { if (iscomposite(x)) return false; return true; } s 4 4 1 1 1 1 1 6 1 t 1 1 9 Shortest Path with Negative Costs Reduction: Min Cut Reduces to Max Flow Caveat: Reduction invalid in networks with negative cost arcs, even if no negative cycles. s 7 v -4 t Max-flow min-cut theorem says value of max flow = capacity of min cut. Min cut linear reduces to max flow. Given a max flow, find all vertices reachable from source in residual graph to get min cut. 7-4 s 7 v -4 t Does max flow linear reduce to min cut? Apparently no easy way to determine max flow from min cut. But no better way known to compute a min cut than via max flow. Remark: can still solve shortest path problem in undirected graphs if no negative cycles, but need more sophisticated techniques. Reduce to weighted non-bipartite matching. (!) 11 1

Network Flow Running Times and Linear Time Reductions Integer Arithmetic MST undirected O(m (m,n)) undirected shortest path nonnegative weights O(m) Integer multiplication: given two N-digit integer s and t, compute s t. min vertex cover bipartite O(mn 1/ ) bipartite matching O(mn 1/ ) shortest path nonnegative weights O(m + n log n) directed MST O(m + n log n) Integer division: given two integers s and t of at most N digits each, compute the quotient q = s / t and remainder r = s mod t. non-bipartite matching O(mn 1/ ) Operation Grade School Best Known Lower Bound min cut undirected O(mn log(m/ n )) max flow undirected O(mn log(m/ n )) shortest path no negative cycles O(mn) undirected shortest path no negative cycles O(mn + n log n) Addition O(N) (N) Multiplication O(N ) (N) Division O(N ) (N) min cut O(mn log(m/ n )) X X L Y Y max flow O(mn log(m/ n )) min cost flow O(m log n + mn log n) max flow bipartite DAG O(mn log(m/ n )) transportation O(m log n + mn log n) assignment problem O(mn + n log n) weighted nonbipartite matching O(mn + n log n) Fundamental questions. Is multiplication easier than division? Is addition easier than multiplication? Is division easier than multiplication? 1 14 Integer Arithmetic Sorting and Convex Hull Integer multiplication: given two N-digit integer s and t, compute s t. Sorting. Given N distinct integers, rearrange in increasing order. Integer division: given two integers s and t of at most N digits each, compute the quotient q = s / t and remainder r = s mod t. Convex hull. Given N points in the plane, find their convex hull in counter-clockwise order. Operation Grade School Best Known Upper Bound Addition O(N) O(N) Multiplication O(N ) O(N log N log log N) Division O(N ) O(N log N log log N) Lower bounds. Recall, under comparison-based model of computation, sorting N items requires (N log N) comparisons. We show sorting linearly reduces to convex hull. Hence, finding convex hull of N points requires (N log N) "comparisons" where comparison means ccw. Theorem. Integer multiplication and integer division have the same asymptotic complexity. Multiplication linear reduces to division. Division linear reduces to multiplication. 1 17

Sorting Reduces to Convex Hull -SUM Reduces to -COLLINEAR Sorting instance (integers): x, 1, x, x N f(x) = x -SUM: Given N distinct integers x 1, x, x N, are there distinct integers x i, x j, x k such that x i + x j +x k = 0? Convex hull instance: Key observation. ( x 1, x 1 ), ( x, x ),, ( x N, x N ) Region {x : x x} is convex all points are on hull. Starting at point with most negative x, counter-clockwise order of convex hull yields items in sorted order. ( x, i x ) i ( x j, x j ) -COLLINEAR: Given N distinct points (x 1, y 1 ), (x, y ), (x N, y N ), are there points that all lie on the same line? pattern recognition assignment Conjecture: Any algorithm for -SUM requires (N ) time. Claim. -SUM L -COLLINEAR. Corollary. Unless you can solve -SUM is sub-quadratic time, any algorithm for -COLLINEAR requires (N ) time. Reduction. To determine if there is a solution to -SUM instance x 1, x, x N, determine if there is a solution to -COLLINEAR instance with (x 1, x 1 ), (x, x ),, (x N, x N ). 18 19 -SUM Reduces to -COLLINEAR Polynomial-Time Reduction Claim. If a, b, and c are distinct then a + b + c = 0 if and only if (a, a ), (b, b ), (c, c ) are collinear. y = x X polynomial reduces to Y if X can be solved using: Polynomial number of standard computational steps. Polynomial number of calls to subroutine for Y. Notation: X P Y. Alternate viewpoint. Can solve X in polynomial time given special piece of hardware that solves instances of Y in a single step. no different from polynomial in this context Proof. Necessary and sufficient conditions for two line segments to be equal. a b a b b c b c ( a b)( a ab b ) ( b c )( b bc c ) a b b c c bc a ab 0 ( c a )( c a b) 0 c a or a b c 0 Ex: Baseball elimination reduces to max flow. Solve N max flow problems on a graph with N vertices. Remark 1: If X L Y then X P Y. Remark : If X can be solved in polynomial time, then X P Y for any Y. 0 1

Polynomial-Time Reduction Hamilton Path Goal: classify and separate problems according to relative difficulty. Those that can be solved in polynomial time. Those that (probably) require exponential time. HAMILTON-PATH. Given an undirected graph, is there a path that visits every vertex exactly once? Establish tractability. If X P Y and Y can be solved in polynomialtime, then X can be solved in polynomial time. Establish intractability. If X P Y and X cannot be solved in polynomial-time, then Y cannot be solved in polynomial time. EULER-PATH. Given an undirected graph, is there a path that visits every edge exactly once? Hamilton Path Reduces to Shortest Path Hamilton Path Reduces to Shortest Path HAMILTON-PATH. Given an undirected graph, is there a path that visits every vertex exactly once? SHORTEST-PATH. Given an directed network and two vertices s and t, find the shortest simple path from s to t. Claim. HAMILTON-PATH P SHORTEST-PATH. For each undirected edge, make two directed edges of weight 1. For all pairs of vertices v and w, find shortest path from v to w. If shortest path has length (V) then this is a Hamilton path. Claim. HAMILTON-PATH P SHORTEST-PATH. Conjecture. No polynomial algorithm exists for HAMILTON-PATH. Corollary. Polynomial algorithm for SHORTEST-PATH is unlikely. This explains why we needed the "no negative cycles" assumption for shortest path algorithms. Shortest Path Nonnegative weights Algorithm Dijkstra Running Time E log V No negative cycles Bellman-Ford E V Arbitrary weights Brute force V s 6 s 6 4

Subset Sum Reduces To Integer Programming Polynomial-Time Reductions SUBSET-SUM. Given N integers a 1, a, a N, and another integer b, is there a subset of integers that sums to exactly b? hard unless P = NP CNF-SAT Integer programming. Given integers b i,a ij find 0/1 variables x i that satisfy a linear system of equations. -CNF-SAT CLIQUE X X P Y Dick Karp Y N aij x j j 1 x j b i {0, 1} 1 i M 1 j N -COLOR DIR-HAM-CYCLE IND-SET VERTEX-COVER SUBSET-SUM polynomial reduces to IP. Solve integer program below and select subset of indices with x i = 1. PLANAR-- COLOR HAM-CYCLE SET-COVER SUBSET-SUM N aj x j j 1 x j b { 0, 1 } 1 j N HAM-PATH SHORTEST-PATH TSP SCHEDULE PARTITION KNAPSACK INTEGER PROGRAMMING 6 7 NP-Completeness Polynomial-Time Reductions P. Set of all decision problems solvable in polynomial time on a deterministic Turing machine. CNF-SAT NP. Set of all decision problems solvable in polynomial time on a nondeterministic Turing machine. -CNF-SAT CLIQUE NP-complete. Decision problem X is NP-complete if every problem in NP polynomial reduces to X. -COLOR DIR-HAM-CYCLE IND-SET VERTEX-COVER Cook's theorem. CNF-SAT is NP-complete. Corollary. If P NP, then no polynomial algorithm for CNF-SAT. Practical consequence. If P NP, then can't hope to design polynomial algorithm for any problem on the previous slide. PLANAR-- COLOR HAM-PATH HAM-CYCLE TSP SET-COVER PARTITION SUBSET-SUM INTEGER PROGRAMMING SHORTEST-PATH SCHEDULE KNAPSACK 8 9

Summary Reductions are important in theory to: Classify problems according to their computational requirements. Establish intractability. Establish tractability. Reductions are important in practice to: Design algorithms. Design reusable software modules. sorting, priority queue, symbol table, graph, shortest path, max flow, regular expressions, linear programming Determine difficulty of your problem and choose the right tool. use exact algorithm for tractable problems use heuristics for NP-hard problems (e.g., bin packing)