# NP-Completeness, Reducibility

(NP-完全性、帰着可能性)

## Data Structures and Algorithms

### 14th lecture, December 17, 2015

http://www.sw.it.aoyama.ac.jp/2015/DA/lecture14.html

### Martin J. Dürst

© 2009-15 Martin J. Dürst 青山学院大学

# Today's Schedule

• Remaining Schedule
• Leftovers and summary of last lecture
• NP problems
• Reduction
• NP-completeness
• Student Survey

# Remaining Schedule

• January 7: 15th lecture (approximation algorithms)
• January 14: Monday lectures!
• January 21: Make-up Classes
• January 26 - February 2: Term Final Exam Period

# Summary of Last Lecture

• Commonalities for many algorithms
⇒ Algorithm design strategies
• Use the design strategies to generate ideas for new algorithms
• Main design strategies: Simple/simplistic algorithms, brute force, greedy algorithms, divide and conquer, dynamic programming
• The appropriate strategy depends on the structure of subproblems
• Depending on details of the problem, the best design strategy can change
(Example: knapsack problem)

# Today's Goal

• Be able to distinguish between "simple" and "difficult" problems
• Expand your view, let's look at the algorithm universe

# Example Problems from Last Lecture

• Example problem 1: 3-SAT
• Example problem 2: Idependent Set
• Example problem 3: Traveling Salesman

# Homework: Find Commonalities in Problems

• Wide applicability in practice
• No known algorithm that is significantly faster than brute force
• Brute force takes exponential time
• If n increases (example: 100), it may become impossible to solve the problem
• Currently, there is no proof that there is no faster algorithm
• There are many problems with the same properties

# Polynomial Problems and Exponential Problems

• Polynomial Problems (O(nc)) are called "tractable"
• Exponential Problems (O(cn)) are called "intractable"

(the time complexity of a problem is the lowest time complexity among the algorithms that solve the problem, or the lowest theoretical time complexity)

# Properties of Polynomial Time

(or why is polynomial time so special)

• Problems with large exponents (e.g. O(n5)) almost non-existent
• Addition and multiplication of polynomials results in polynomials (ring of polynomials)
• Polynomial time is not significantly influenced by choice of machine model
Example: Parallel processing with m computers will only lead to a speedup by a factor of m
• It is difficult to find a criterion (e.g. >O(n2)??) to divide polynomial problems

The set of problems that can be solved in polynomial time is denoted as P

# NP Problems

• The variants of problems 1-3 from last lectune are all NP problems
• Defining properties of NP problems:
1. If the answer is true, and there is some evidence, then this can be verified quickly (i.e. in polynomial time)
(however, if the answer is false, verification may take longer)
2. If we can use as many computers as we want, we can find the answer in polynomial time
• Why "NP"?
Nondeterministic Polynomial Time
• The set of NP problems is denoted as NP
• Problems in P may become NP with only minor changes
Example: Shortest path (P) and longest path (NP) between two vertices in a graph
• There are many NP problems
• PNP
• P = NP ? PNP ?
This is the most famous and most important unsolved problem in Computer Science
Clay Mathematics Institute Millenium Problems Rules

# Problem Shape

• Function problems:
There is only one answer
Example: Sorting, matrix multiplication, fibonacci function,...
• Optimization problems:
Greatest, fastest, shortest,..., or
as big as possible, as short as possible,...
• Decision problems

# Decision Problem

• Problem where the result can only be true or false
(function problem that returns a boolean variable)
• It is possible to convert other problems to decision problems
Optimization problems: Find the largest solution → Is there a solution larger than k?
• A decision problem cannot be more difficult than the original problem
• For theory, decision problems are easier to work with
• By definition, NP problems are decision problems
• Problems that are at least NP (but maybe more difficult, and maybe not decision problems) are called NP-hard

# Comparing Problems in NP

• Getting order into NP problems
• Comparing problems

# An Example of Reduction

• Solving a 3-SAT problem by converting it to an independent set problem

# Overview of Reduction

• Idea: Solve a problem A by converting it to a different problem B
(prove that the problem can be solved)
• Input for A ⇒ (conversion) ⇒ input for B ⇒ algorithm for B ⇒ output for B ⇒ (backconversion) ⇒ output for A
• Conversion in both directions has to be possible in polynomial time
• If A can be reduced (is reducible) to B (in polynomial time), we write A ≤P B
• This mean that (within polynomial conversion), A is simpler or of the same difficulty as B

# NP-Completeness

• An NP problem to which all other NP problems can be reduced is called NP-complete
• This means that an NP-complete problem is more difficult (or of the same difficulty) as any other NP problem
• Almost all NP problems for which there is no known polynomial algorithm can be shown to be NP-complete
• If PNP, then there are also some problems that are not in P, but also not NP-complete
(but not many such problems are known)

# Computational Complexity Theory

• Goal: Classification of computational problems
• Criteria for classification:
• Time complexity
• Memory complexity
• Shape and size of circuit (or hardware in general)
• Parallelization

Reference: Complexity Zoo

# Post's Correspondence Problem

(Emil Post, 1946)

• Gives: A language using two or more characters, and two sequences of words of equal length: W = [w1, w2, ... wn], V = [v1, v2, ... vn]
• Problem: Is it possible to choose a (non-empty) sequence of corresponding words from W and V to form the same sentence?
(words may be repeated; spaces between words are ignored)
• Example: W = [aa, b], V = [a, aba]
Solution: aa-b-aa = a-aba-a (1-2-1)
• Example without solution: W = {ccd, cd, c}, V = {cc, ddc, d}
(reason: independent of word choice, the last character of the overall string will always be different)
• It can be proven that there exists no general algorithm for this problem

# Summary

• There are many problems that we (currently) cannot solve in polynomial time
• Many of these problems are NP-complete (or NP-hard)
• It is important to discover such problems early
• There are also problems that are even more difficult to solve than NP-complete problems

# Student Survey

(授業改善のための学生アンケート)

お願い: できるだけ自由記述を使って、具体的に書いてください

(悪い例: 発音が分かりにくい; 良い例: さ行が濁っているかどうか分かりにくい)

# Glossary

polynomial problem

tractable problem

exponential problem

intractable problem

ring of polynomials

nondeterministic polynomial time

function problem

optimization problem

decision problem

NP-hard
NP 困難
reduction

NP-completeness
NP 完全性
Computational Complexity Theory

Post's correspondence problem
ポストの対応問題