# NP-Completeness, Reducibility

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

## Data Structures and Algorithms

### 14th lecture, January 16, 2020

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

### Martin J. Dürst © 2009-20 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 23: 15th lecture (approximation algorithms)
• January 30, 09:30-10:55: Term Final Exam

# 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 the problem and its 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, 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: n=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

# Problem Shape

• Function problems:
Example: Sorting, matrix multiplication, Fibonacci function,...
• Optimization problems:
Find the greatest, fastest, shortest,..., or
as big as possible, as short as possible,...
• Decision problems:
Answer is only yes or no

# 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 handle

# Polynomial Problems and Exponential Problems

• Polynomial problems (Ω(nc)) are called tractable
Examples: Ω(n2), Ω(n3)
• Exponential problems (Ω(cn)) are called intractable
Examples: Ω(1.1n), Ω(2n)

(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. Ω(n5)) are very rare
• 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 at best lead to a speedup by a factor of m
• It is difficult to find a criterion (e.g. >Ω(n2.731)??) to subdivide 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 lecture 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)
(evidence: a solution to 3-SAT, a short path in the Traveling Salesman problem,...)
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
• 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
• 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 (by definition)
• P = NP ? PNP ?
This is the most famous and most important unsolved problem in Computer Science
Clay Mathematics Institute Millenium Problems Rules

# Comparing Problems in NP

• Getting order into NP problems
• Comparing problems uses reduction

# An Example of Reduction

Solving a 3-SAT problem by converting (reducing) it to an independent set problem

• Create a triangle (graph) for each term of the 3-SAT formula
• Label each vertext of a triangle with a variable (or its negation) from the term
• Add edges to the graph connecting vertices with the same variable, but opposite negation state
• Solve the independent set problem for the graph
• Use the variables of the selected vertices (with their negation state) as the solution of the 3-SAT 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; main examples are graph isomorphism and prime factoring

# 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)
• The problem can be visualized as a card game
• 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)
• The above two examples are easy to solve
• 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

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

WEB 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

reducibility

NP-completeness
NP 完全性
graph isomorphism
グラフ同型
Computational Complexity Theory

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