Module 5
Module 5
In computer science, there exist some problems whose solutions are not yet found, the
problems are divided into classes known as Complexity Classes.
The common resources are time and space, meaning how much time the algorithm takes to
solve a problem and the corresponding memory usage.
The time complexity of an algorithm is used to describe the number of steps required
to solve a problem, but it can also be used to describe how long it takes to verify the
answer.
The space complexity of an algorithm describes how much memory is required for
the algorithm to operate.
1. P Class
2. NP Class
3. NP-hard
4. NP-complete
P Class
The P in the P class stands for Polynomial Time. It is the collection of decision
problems(problems with a “yes” or “no” answer) that can be solved by a deterministic
machine in polynomial time.
Features:
The solution to P problems is easy to find.
P is often a class of computational problems that are solvable and tractable. Tractable
means that the problems can be solved in theory as well as in practice. But the
problems that can be solved in theory but not in practice are known as intractable.
One of these models is deterministic one-tape Turing machine. This machine consists of a
finite state control, a read-write head and a two-way tape with infinite sequence.
NP Class
Features:
The solutions of the NP class are hard to find since they are being solved by a non-
deterministic machine but the solutions are easy to verify.
If the problem is solvable in polynomial time by a non-deterministic Turing machine,
the problem belongs to NP class.
Following are the differences between the P class problem and the NP class problem:
Sr.
P class Problem NP class Problem
No
P problems are a set of problems that
NP problems are problems that can be solved in
1. can be solved in polynomial time by
nondeterministic polynomial time.
deterministic algorithms.
The solution to NP problems cannot be obtained
P Problems can be solved and
2. in polynomial time, but if the solution is given, it
verified in polynomial time.
can be verified in polynomial time.
P problems are a subset of NP
3. NP Problems are a superset of P problems.
problems.
All P problems are deterministic in All the NP problems are non-deterministic in
4.
nature. nature.
It takes polynomial time to solve a It takes non-deterministic polynomial time to
5.
problem like n, n^2, n*logn, etc. quickly check a problem.
The solution to P class problems is
6. The solution to NP class problems is hard to find.
easy to find.
Examples of P problems are: Examples of NP problems are the Travelling
7.
Selection sort, Linear Search salesman problem and the knapsack problem.
NP-hard class
Features:
A problem A is in NP-hard if, for every problem L in NP, there exists a polynomial-
time reduction from L to A.
NP-complete class
A problem is NP-complete if it is both NP and NP-hard. NP-complete problems are the hard
problems in NP.
Stephen Arthur Cook and L.A. Levin in 1973 independently proved that the satisfiability
problem(SAT) is NP-complete. Stephen Cook, in 1971, published an important paper titled
‘The complexity of Theorem Proving Procedures’, in which he outlined the way of obtaining
the proof of an NP-complete problem by reducing it to SAT. He proved Circuit-SAT and
3CNF-SAT problems are as hard as SAT. Similarly, Leonid Levin independently worked on
this problem in the then Soviet Union. The proof that SAT is NP-complete was obtained due
to the efforts of these two scientists. Later, Karp reduced 21 optimization problems, such as
Hamiltonian tour, vertex cover, and clique, to the SAT and proved that those problems are
NP-complete.
This problem is also known as the formula – SAT. An SAT(formula-SAT or simply SAT)
takes a Boolean expression F and checks whether the given expression(or formula) is
satisfiable. A Boolean expression is said to be satisfactory for some valid assignments of
variables if the evaluation comes to be true. Prior to discussing the details of SAT, let us now
discuss some important terminologies of a Boolean expression.
Boolean variable: A variable, say x, that can have only two values, true or false, is
called a boolean variable
Literal: A literal can be a logical variable, say x, or the negation of it, that is x or x̄ ; x
is called a positive literal, and x̄ is called the negative literal
Clause: A sequence of variables(x1,x2,….,xn) that can be separated by a logical OR
operator is called a clause. For example, (x1 V x2 V x3) is a clause of three literals.
Expressions: One can combine all the preceding clauses using a Boolean operator to
form an expression.
CNF form: An expression is in CNF form(conjunctive normal form) if the set of
clauses are separated by an AND (^), operator, while the literals are connected by an
Thus, an SAT is one of the toughest problems, as there is no known algorithm other than the
brute force approach. A brute force algorithm would be an exponential-time algorithm, as 2n
possible assignments need to be tried to check whether the given Boolean expression is true
or not. Stephen Cook and Leonid Levin proved that the SAT is NP-complete.
Cook demonstrated the reduction of other hard problems to SATs. Karp provided proof of 21
important problems, Such as Hamiltonian tour, vertex cover, and clique, by reducing it to
SAT using Karp reduction.
Let us briefly introduce the three types of SATs. They are as follows:
1. Circuit- SAT: A circuit-SAT can be stated as follows: given a Boolean circuit, which
is a collection of gates such as AND, OR, and NOT, and n inputs, is there any input
assignments of Boolean variables so that the output of the given circuit is true? Again,
the difficulty with these problems is that for n inputs to the circuit. 2n possible outputs
should be checked. Therefore, this brute force algorithm is an exponential algorithm
and hence this is a hard problem.
2. CNF-SAT: This problem is a restricted problem of SAT, where the expression should
be in a conjunctive normal form. An expression is said to be in a conjunction form if
all the clauses are connected by the Boolean AND operator. Like in case of a SAT,
this is about assigning truth values to n variables such that the output of the
expression is true.
3. 3-CNF-SAT(3-SAT): This problem is another variant where the additional restriction
is that the expression is in a conjunctive normal form and that every clause should
contain exactly three literals. This problem is also about assigning n assignments of
truth values to n variables of the Boolean expression such that the output of the
expression is true. In simple words, given an expression in 3-CNF, a 3-SAT problem
is to check whether the given expression is satisfiable.
These problems can be used to prove the NP-completeness of some important problems.
TOPIC: NP HARD GRAPH PROBLEMS
NP-hard graph problems are computational problems involving graphs that are at least as
hard as the hardest problems in the complexity class NP. These problems cannot be solved in
polynomial time (unless P = NP) and are often tackled using approximation algorithms,
heuristics, or brute-force methods for small instances.
Problem: Given a graph, determine whether there exists a cycle that visits each
vertex exactly once and returns to the starting vertex.
Applications: Logistics, traveling salesperson problems, and DNA sequencing.
Complexity: NP-complete for general graphs; polynomial-time solvable for specific
graph classes (e.g., planar bipartite graphs).
Problem: Assign the minimum number of colors to the vertices of a graph such that
no two adjacent vertices have the same color.
Applications: Scheduling, register allocation in compilers, and frequency assignment.
Complexity: NP-hard for graphs with three or more colors.
Problem: Find the shortest possible route that visits each vertex exactly once and
returns to the origin.
Applications: Route optimization, logistics, and network design.
Complexity: NP-hard for general graphs; has polynomial-time solutions for specific
cases (e.g., when the graph satisfies the triangle inequality).
Problem: Find the smallest set of vertices such that every edge in the graph is
incident to at least one vertex in the set.
Applications: Network security, facility location, and matching problems.
Complexity: NP-hard; approximation algorithms exist.
6. Dominating Set Problem
Problem: Find the smallest set of vertices such that all vertices in the graph are either
in the set or adjacent to a vertex in the set.
Applications: Sensor placement, network routing, and facility location.
Complexity: NP-hard; challenging to approximate within reasonable bounds.
1. Exact Methods:
o Brute-force (small graphs)
o Integer programming
o Dynamic programming (for special cases)
2. Approximation Algorithms:
o Used for problems where finding exact solutions is infeasible.
o Example: Approximation for Vertex Cover and TSP.
3. Heuristics:
o Greedy algorithms, simulated annealing, or genetic algorithms.
o Provide good-enough solutions for practical purposes.
4. Parameterized Complexity:
o Focuses on specific aspects (parameters) of the problem that can make it
tractable.
Scheduling problems are fundamental in operations research and computer science, involving
the allocation of resources to tasks over time. Many scheduling problems are NP-hard,
meaning finding an optimal solution is computationally infeasible for large inputs (unless P =
NP). Below are key NP-hard scheduling problems and their characteristics.
Problem: Schedule jobs on machines, where each job requires a specific sequence of
tasks to be completed on specific machines.
Goal: Minimize makespan (total time to complete all jobs) or other metrics like
tardiness or flow time.
Applications: Manufacturing, production planning, and robotics.
Complexity: NP-hard for two or more machines.
Problem: Jobs can be processed in any order on the machines, but each task must be
assigned exactly once to its designated machine.
Goal: Minimize makespan or lateness.
Applications: Laboratories, hospitals, and parallel computing.
Complexity: NP-hard for three or more machines.
Problem: Schedule tasks on a single machine with deadlines and processing times,
minimizing lateness, tardiness, or missed deadlines.
Variants: Weighted tardiness or tasks with precedence constraints.
Complexity: NP-hard when there are precedence constraints or weighted tardiness.
Problem: Assign jobs to multiple machines, where each machine can handle only one
job at a time.
Goal: Minimize makespan, total completion time, or other metrics.
Variants:
o Identical machines: Jobs can run on any machine.
o Uniform machines: Machines have different processing speeds.
o Unrelated machines: Machines have different speeds and efficiency per task.
Complexity: NP-hard for two or more machines.
Problem: Schedule jobs with start times, durations, deadlines, and weights to
maximize total weight of completed jobs.
Applications: Cloud computing, resource allocation, and contract management.
Complexity: NP-hard.
7. Resource-Constrained Project Scheduling Problem (RCPSP)
Problem: Jobs can be interrupted and resumed later. Assign start and end times for
tasks while respecting constraints.
Goal: Minimize makespan, lateness, or tardiness.
Complexity: NP-hard for multiple machines, precedence constraints, or complex
objectives.
1. Exact Methods:
o Integer Linear Programming (ILP)
o Branch-and-Bound
o Dynamic Programming (small instances)
3. Approximation Algorithms:
o Used when exact solutions are infeasible but near-optimal solutions are
acceptable.
They are typically versions of complex NP-hard problems with fewer constraints or specific
settings that make them easier to understand or solve in practice. Below is a list of simplified
NP-hard problems and their features:
Problem: Given a set of integers and a target sum, determine if any subset of the
integers adds up to the target sum.
Simplification: This is a special case of the Knapsack Problem without weights.
Applications: Cryptography, resource allocation.
Example: Given numbers {3,34,4,12,5,2}\{3, 34, 4, 12, 5, 2\}, is there a subset that
sums to 99?
Complexity: NP-complete but simpler than full Knapsack.
2. Partition Problem
Problem: Can a set of integers be partitioned into two subsets with equal sums?
Simplification: A special case of Subset Sum with the target sum being half the total
sum of the set.
Applications: Load balancing, resource division.
Example: For {1,5,11,5}\{1, 5, 11, 5\}, the answer is "yes" because {1,5,5}\{1, 5, 5\}
and {11}\{11\} are equal.
Complexity: NP-complete.
Problem: Find the shortest route visiting all cities exactly once and returning to the
starting city.
Simplification: When distances satisfy the triangle inequality (d(a,b)
+d(b,c)≥d(a,c)d(a, b) + d(b, c) \geq d(a, c)), the problem is easier to approximate.
Applications: Logistics and route planning.
Example: Cities and their road network where direct distances are always shorter
than detours.
Complexity: NP-hard but 1.51.5-approximation algorithms exist (e.g., Christofides
algorithm).
Problem: Assign colors to vertices such that no two adjacent vertices share the same
color.
Simplification: Planar graphs always need at most 4 colors (by the Four Color
Theorem), which reduces complexity compared to general graphs.
Applications: Map coloring and scheduling.
Example: Coloring regions on a geographical map.
Complexity: NP-hard for general graphs, simplified for planar graphs with
constraints.
Problem: Partition the vertices of a graph into two sets such that the number of edges
between the sets is maximized.
Simplification: For bipartite graphs, the problem is trivial because all edges can cross
the cut.
Applications: Network design, statistical physics.
Example: Split the nodes of a bipartite graph to maximize inter-group connections.
Complexity: NP-hard for general graphs; polynomial-time solvable for bipartite
graphs.
Problem: Maximize the value of items that can fit in a knapsack with limited weight
capacity.
Simplification: Weights are restricted to 0 or 1, turning the problem into a subset
selection problem.
Applications: Resource allocation, investment decisions.
Example: Choose the most valuable items among those with negligible weights.
Complexity: NP-hard, but simplified compared to general weights.
7. Vertex Cover for Trees
Problem: Find the smallest set of vertices such that every edge in the graph is
incident to at least one vertex.
Simplification: For trees, this problem is solvable in linear time using a greedy
approach.
Applications: Network maintenance, monitoring systems.
Example: Cover edges in a network with a tree structure.
Complexity: NP-hard for general graphs, polynomial for trees.