0% found this document useful (0 votes)
20 views13 pages

Module 5

Uploaded by

danugokul850
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views13 pages

Module 5

Uploaded by

danugokul850
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

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.

Complexity classes are useful in organising similar types of problems.

Types of Complexity Classes

This article discusses the following complexity classes:

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.

Deterministic Turing Machine

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.

Following is the schematic diagram of a deterministic one-tape Turing machine.

A program for a deterministic Turing machine specifies the following information −

 A finite set of tape symbols (input symbols and a blank symbol)


 A finite set of states
 A transition function

NP Class

The NP in NP class stands for Non-deterministic Polynomial Time. It is the collection of


decision problems that can be solved by a non-deterministic machine in polynomial time.

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.

 Problems of NP can be verified by a Turing machine in polynomial time.


 To solve the computational problem, another model is the Non-deterministic Turing
Machine (NDTM). The structure of NDTM is similar to DTM, however here we have
one additional module known as the guessing module, which is associated with one
write-only head.
 Following is the schematic diagram.


 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

An NP-hard problem is at least as hard as the hardest problem in NP and it is a class of


problems such that every problem in NP reduces to NP-hard.

Features:

 All NP-hard problems are not in NP.


 It takes a long time to check them. This means if a solution for an NP-hard problem is
given then it takes a long time to check whether it is right or not.

 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.

TOPIC: COOKS THEOREM:

In computational complexity theory, the Cook–Levin theorem, also known as Cook’s


theorem, states that the Boolean satisfiability problem is NP-complete. That is, it is in NP,
and any problem in NP can be reduced in polynomial time by a deterministic Turing machine
to the Boolean satisfiability problem.

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.

Hence, an SAT is a significant problem and can be stated as follows:

Given a boolean expression F having n variables x1,x2,….,xn, and Boolean operators, is it


possible to have an assignment for variables true or false such that binary expression F is
true?

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

o f = (x1 V x̄ 2 V x3) ∧ (x1 V x̄ 3 V x2)


OR (v) operator. The following is an example of an expression in the CNF form:

 3 – CNF: An expression is said to be in 3-CNF if it is in the conjunctive normal form,


and every clause has exact three literals.

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.

Here are some key NP-hard graph problems:

1. Hamiltonian Cycle Problem

 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).

2. Graph Coloring Problem

 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.

3. Traveling Salesperson Problem (TSP)

 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).

5. Vertex Cover Problem

 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.

Solving NP-Hard Graph Problems

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.

5. Reduction and Hardness Proofs:


o Problems can often be shown to be NP-hard by reducing known NP-hard
problems to them.

TOPIC: NP SCHEDULING PROBLEMS

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.

1. Job Shop Scheduling Problem (JSP)

 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.

2. Open Shop Scheduling Problem (OSP)

 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.

3. Single Machine Scheduling with Deadlines

 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.

4. Multiprocessor Scheduling (Parallel Machines)

 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.

5. Weighted Job Scheduling with Deadlines

 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: Schedule tasks with resource constraints, precedence relations, and


durations.
 Goal: Minimize project duration or resource usage.
 Applications: Construction, event planning, and software development.
 Complexity: NP-hard for general cases.

8. Preemptive Scheduling Problems

 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.

9. Batch Scheduling Problem

 Problem: Group jobs into batches for simultaneous processing on machines.


 Goal: Minimize makespan, total completion time, or energy costs.
 Applications: Batch manufacturing, chemical processing, and parallel computing.
 Complexity: NP-hard.

Common Techniques for Tackling NP-hard Scheduling Problems

1. Exact Methods:
o Integer Linear Programming (ILP)
o Branch-and-Bound
o Dynamic Programming (small instances)

2. Heuristics and Metaheuristics:


o Greedy algorithms
o Genetic algorithms
o Simulated annealing
o Tabu search

3. Approximation Algorithms:
o Used when exact solutions are infeasible but near-optimal solutions are
acceptable.

4. Constraint Programming (CP):


o Solves complex problems with precedence constraints and resource
limitations.

5. Machine Learning Approaches:


o Predict job priorities or simulate optimal schedules for complex scenarios.

TOPIC: Simplified NP-hard problems

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:

1. Subset Sum Problem

 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.

3. Traveling Salesperson Problem (TSP) with Triangle Inequality

 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).

4. Graph Coloring on Planar Graphs

 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.

5. Maximum Cut in Bipartite Graphs

 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.

6. Knapsack Problem with Binary Weights

 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.

8. Scheduling with Unit Task Times

 Problem: Schedule jobs with unit processing times on machines to minimize


makespan.
 Simplification: All tasks take the same time, reducing complexity compared to
variable durations.
 Applications: Parallel computing, task management.
 Example: Divide 10 equal tasks among 3 machines to minimize the maximum time
any machine works.
 Complexity: NP-hard for general tasks; polynomial-time solutions exist with
additional constraints.

9. Longest Path in Directed Acyclic Graphs (DAGs)

 Problem: Find the longest path between two nodes in a graph.


 Simplification: Restrict the graph to be a DAG (no cycles), allowing polynomial-time
solutions using topological sorting.
 Applications: Project scheduling, circuit design.
 Example: Find the critical path in a project dependency graph.
 Complexity: NP-hard for general graphs, solvable for DAGs.

10. Hamiltonian Path on Grid Graphs

 Problem: Find a path that visits each vertex exactly once.


 Simplification: Restrict the graph to a grid (e.g., square lattice), making heuristic
approaches more effective.
 Applications: Maze generation, robotics.
 Example: Navigate a 4×44 \times 4 grid while visiting every cell exactly once.
 Complexity: NP-hard for general graphs, simpler heuristics for grids.
Why Simplify NP-Hard Problems?

Simplified versions help in:

1. Understanding Problem Structure: Focus on core difficulties without additional


complications.
2. Algorithm Design: Develop heuristics or approximations that generalize to more
complex cases.
3. Practical Applications: Solve restricted real-world problems effectively.

You might also like