Computational Complexity

COMPUTATIONAL COMPLEXITY
FENG LI
Sorting
Sorting
any sequence
Time complexity: O(n)
Time complexity: the amount of time taken by an algorithm to run
Sorting
All sequences
Time complexity: O(n!)
Sorting
Sorting Algorithm
Quick sort
Merge sort
Insertion sort
Time Complexity
n2
nlogn
n2
Time Complexity
Polynomial Time: n, n2, nlogn, n3, n20000000, ….
Exponential Time: 2n, 3n, n!, ….
Decision problem
Satisfaction on positions
1
2
3
4
5
6
7
8
Nancy
15
12
11
9
7
5
4
1
Peter
20
16
14
8
4
3
5
2
Mary
4
6
7
9
10
15
17
26
Is there a sequence with the satisfaction value not less than 90? Yes or No?
Decision Problem: A problem with a yes or no answer
Class of problems
 Class P: all problems can be solved in polynomial time.
 Class NP: all problems can be verified in polynomial time, i.e., that
is that there is not necessarily a polynomial time way to find a
solution, but once you have a solution it only takes polynomial time
to verify it is correct.
 Class NP-hard: all problems that are at least as hard as the hardest
problems in NP.
 Class NP-complete: all problems each of which is both in NP and
NP-hard.
Class of problems
P = NP?
$1,000,000 prize by Clay
Mathematics Institute in
2000.
NP-hard
ordinarily
NP-hard
There exists an algorithm with pseudopolynomial time complexity.
Strongly
NP-hard
There exist no algorithms with pseudopolynomial time complexity.
NP-hard
How to prove that a problem is NP-hard
Step 1. Select a known NP-hard problem.
Step2. Construct a special instance of the problem that can be
converted into an instance of the known NP-hard problem in
polynomial time.
Step 3. Prove that the instance of the problem has a feasible
solution if and only if the instance of the known NP-hard
problem has a feasible solution.
Example
 There are two machines and six jobs.
 Assign these jobs to the two machines.
 The maximum completion time is minimized.
job
J1
J2
J3
J4
J5
J6
Processin
g time
3
4
2
5
4
2
Example
job
J1
J2
J3
J4
J5
J6
Processin
g time
3
4
2
5
4
2
Machine 1
J1
J2
Machine 2
J3
J4
J5
J6
11
Machine 1
J1
Machine 2
J2
J3
J4
J5
J6
10
Example
 The number of jobs is n.
 Processing time of each job j is pj
 Completion time of each job j is Cj
 The maximum completion time is Cmax = max{Cj |j = 1, 2, …, n}.
How to prove that a problem is ordinarily NP-hard
Step 1. Select a known NP-hard problem.
Partition Problem (PP). Given q items, Q = {1, 2,…, q}, and
q
a
j 1
j
 2A
, for some integer A, the question asks whether there
is a subsets Q of Q such that its total size is equal to A, i.e.,
a
jQ
j
A
How to prove that a problem is ordinarily NP-hard
Step2. Construct a special instance of the problem that can be
converted into an instance of the known NP-hard problem in
polynomial time.
 The number of jobs is n.
 Processing time of each job j is pj
 Completion time of each job j is Cj
 The maximum completion time is Cmax =
max{Cj |j = 1, 2, …, n}.
Partition Problem (PP). Given q items, Q =
q
{1, 2,…, q}, and
a
j 1
j
 2 A , for some integer A,
the question asks whether there is a subsets Q
of Q such that its total size is equal to A, i.e.,
a
jQ
j
A
Constructing an instance:
The number of jobs: n = q
Processing time of each job: pj = aj.
The maximum completion time is
Cmax ≤ A.
How to prove that a problem is ordinarily NP-hard
Step 3. Prove that the instance of the problem has a feasible
solution if and only if the instance of the known NP-hard
problem has a feasible solution.
How to prove that a problem is ordinarily NP-hard
If part. Suppose that a partition Q exists. We construct a solution to the
corresponding instance of the problem as follows: jobs j for j  Q are processed in an
arbitrary order on machine 1 and jobs j for j  Q\Q are processed in an arbitrary on
machine 2.
 a   p =A , and 
jQ 
j
jQ 
j
jQ \ Q 
aj 

jQ \ Q 
p j =2A   p j  A
jQ 
Machine 1
Q
Machine 2
Q\Q
A
How to prove that a problem is ordinarily NP-hard
Only if part. Suppose that there is a solution for instance of the problem with the
maximum completion time no more than A. Let Q be the subset of the jobs in Q
processed on machine 1. Thus, jobs in Q\Q are processed on machine 2.
Since the maximum completion time of jobs is no more than A,
 p = a
jQ 
j
jQ 
q
Since
of Q.
a
j 1
j
j
 A , and

jQ \ Q 
 2 A , we have
pj =

jQ \ Q 
a = 
jQ 
j
aj  A
jQ \ Q 
a j  A . This means that Q must be a partition
How to prove that a problem is ordinarily NP-hard
 The problem is at least NP-hard.
 There exists an algorithm with
pseudo-polynomial time
complexity.
We do not know that
whether this problem is
ordinarily NP-hard.
How to prove that a problem is ordinarily NP-hard
 We define boolean variables fk(t1, t2) that are to signal whether it is
possible to process jobs 1, 2, …, k such that the machines are ready at
times t1 and t2, respectively.
Machine 1
J1
J2
Machine 2
J3
J4
f6(11, 10) = true, f6(20, 10) = true,
f6(10, 10) = false.
J5
J6
9
11
How to prove that a problem is ordinarily NP-hard
Initialization. f0(t1, t2) = true if t1, t2 ≥ 0, and f0(t1, t2) = false, otherwise.
𝑛
Recursion. For k = 1, 2, …, n, t1 = 0, 1, …,
𝑛
𝑝𝑗, t2 = 0, 1, …,
𝑗=1
𝑝𝑗 ,
𝑗=1
fk(t1, t2) = {fk-1(t1 – pk, t2) ˅ fk-1(t1, t2 – pk) }.
Output. The objective value is determined by Cmax = min{t| fn(t, t) = true}.
2
𝑛
Time complexity:
𝑂 𝑛
𝑝𝑗
𝑗=1
How to prove that a problem is ordinarily NP-hard
 The problem is ordinarily NP-hard.
Example
 There are two machines and six jobs.
m machines
 Assign these jobs to the two machines.
 The maximum completion time is minimized.
job
J1
J2
J3
J4
J5
J6
Processin
g time
3
4
2
5
4
2
How to prove that a problem is strongly NP-hard
Step 1. Select a known NP-hard problem.
Step2. Construct a special instance of the problem that can be
converted into an instance of the known NP-hard problem in
polynomial time.
Step 3. Prove that the instance of the problem has a feasible
solution if and only if the instance of the known NP-hard
problem has a feasible solution.
How to prove that a problem is strongly NP-hard
Step 1. Select a known strongly NP-hard problem.
3-Partition Problem (3PP). Given 3q items, Q = {1, 2,…, 3q}, each item jQ has a
3q
positive integer size aj satisfying A / 4 < aj < A / 2, and
a
j 1
j
 qA , for some integer A,
the question asks whether there are q disjoint subsets Q1, Q2,…, Qq of Q such that
each subset contains exactly three items and its total size is equal to A.
How to prove that a problem is strongly NP-hard
Step2. Construct a special instance of the problem that can be
converted into an instance of the known NP-hard problem in
polynomial time.
How to prove that a problem is strongly NP-hard
 Constructing an instance:
 The number of machines: m = q
 The number of jobs: n = 3q
 The processing time of each job: pj = aj.
 The maximum completion time is Cmax ≤ A.
How to prove that a problem is strongly NP-hard
Step 3. Prove that the instance of the problem has a feasible
solution if and only if the instance of the known NP-hard
problem has a feasible solution.
How to prove that a problem is strongly NP-hard
If part. Suppose that a partition Q1, Q2,…, Qq exists. We construct a solution to the
corresponding instance of the problem as follows: jobs j for j  Qk are processed in an
arbitrary order on machine k, for k = 1, 2, …, m. It is easy to see that the objective
value of the solution is equal to A.
Machine 1
Q1
Machine 2
Q2
Machine m
Qm
A
How to prove that a problem is strongly NP-hard
Only if part. Suppose that there is a solution for instance of the problem with the
maximum completion time no more than A. Let Qk be the subset of the jobs in Q
processed on machine k, for k = 1, 2, …, m. Since the maximum completion time of
jobs is no more than A,
 p = a
jQk
j
jQk
3q
Since
a
j 1
j
j
 A , for k = 1, 2, …, m.
 qA , we have
a
jQk
j
 A , for k = 1, 2, …, m. Because A / 4 < aj < A / 2, it
follows that |Qi| = 3, for i = 1, …, q. This means that Q1, Q2, …, Qq must be a 3-
partition of Q.
How to prove that a problem is strongly NP-hard
 The problem is strongly NP-hard.
End???
Thanks for your attention!
Li Feng, Chen Zhi-Long, Tang Lixin. Integrated Production, Inventory
and Delivery Problems: Complexity and Algorithms. INFORMS
Journal on Computing. 2016.