0% found this document useful (0 votes)
22 views6 pages

Unit 5

Time complexity measures the time an algorithm takes to complete based on input size, classified using Big O notation. Classes P and NP categorize decision problems based on their solvability and verifiability in polynomial time, with NP-completeness indicating the hardest problems in NP. Key examples of NP-complete problems include the Subset Sum Problem, Hamiltonian Path Problem, and Graph Coloring Problem, with Cook's Theorem establishing the NP-completeness of the Boolean satisfiability problem.

Uploaded by

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

Unit 5

Time complexity measures the time an algorithm takes to complete based on input size, classified using Big O notation. Classes P and NP categorize decision problems based on their solvability and verifiability in polynomial time, with NP-completeness indicating the hardest problems in NP. Key examples of NP-complete problems include the Subset Sum Problem, Hamiltonian Path Problem, and Graph Coloring Problem, with Cook's Theorem establishing the NP-completeness of the Boolean satisfiability problem.

Uploaded by

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

Time Complexity

Time complexity refers to the computational complexity that describes the amount of time an
algorithm takes to complete as a function of the input size (denoted as n). It is expressed using
Big O notation (e.g., O(n), O(n²)) to classify algorithms by their growth rates.

Measuring Complexity

Measuring complexity refers to the process of evaluating the resource requirements of an


algorithm, primarily time and space, based on the size of the input. The most common and
important measure is time complexity.

Measuring complexity involves analyzing the number of basic operations an algorithm performs.
The key types are:

 Worst-case: Maximum time taken for any input of size n.


 Average-case: Expected time over all inputs of size n.
 Best-case: Minimum time for any input of size n.

The Class P

Class P consists of decision problems (yes/no questions) that can be solved by a deterministic
Turing machine in polynomial time, i.e., time bounded by a polynomial function of the input
size (like O(n), O(n²), etc.). These are considered efficiently solvable problems.

A decision problem belongs to the class P if there exists a deterministic algorithm (like one that
runs on a typical computer) that solves the problem in polynomial time, i.e., time T(n) = O(n^k)
for some constant k, where n is the size of the input.

Class P is a fundamental class in computational complexity theory. It stands for “Polynomial


time”.

 It contains all decision problems (i.e., problems with yes/no answers) that can be solved
by a deterministic Turing machine in polynomial time.
 In simple terms, these are the problems for which an efficient algorithm exists.
The Class NP

Class NP includes decision problems for which a solution can be verified in polynomial time by
a deterministic Turing machine. It also includes problems solvable in polynomial time by a non-
deterministic Turing machine.

Class NP stands for Nondeterministic Polynomial time. It refers to a class of decision problems
(problems with "yes" or "no" answers) for which:

 If the answer is “yes”, there exists a certificate (or solution) that can be verified in
polynomial time using a deterministic Turing machine.

In other words, NP problems may not be easy to solve, but if you are given a solution, you can
verify its correctness quickly (in polynomial time).

NP-Completeness

A problem is NP-complete if:

1. It is in NP.
2. Every problem in NP can be reduced to it in polynomial time.

These are the hardest problems in NP; solving one NP-complete problem in polynomial time
implies P = NP.

NP-Completeness is a concept in computational complexity theory used to describe the hardest


problems in NP. These problems are both:

1. In NP: Their solutions can be verified in polynomial time.


2. NP-Hard: Every problem in NP can be reduced to them in polynomial time.

Definition of P and NP Problem

 P problem: A problem that can be solved in polynomial time.


 NP problem: A problem for which a proposed solution can be verified in polynomial
time.
NP-Complete and NP-Hard Problems

 NP-Complete: Problems in NP to which all other NP problems reduce. Example: SAT,


3-SAT, Traveling Salesman Decision Problem.
 NP-Hard: At least as hard as NP-complete problems. They may or may not be in NP
(i.e., may not be decision problems). Example: Halting Problem, Optimization version of
TSP.

Unsolvable Problems

Unsolvable problems are those that no algorithm can solve for all possible inputs. These
problems are undecidable. Example: The Halting Problem, where it's impossible to determine
whether an arbitrary program halts or runs forever.

NP-Complete Problem: Subset Sum Problem

The Subset Sum Problem is a classic NP-complete decision problem. It can be stated as:

Given a set of positive integers S={s1,s2,...,sn}S = {s_1, s_2, ..., s_n}S={s1,s2,...,sn} and a
target integer T,
Does there exist a subset of S such that the sum of the elements in the subset equals T?

Let S= {3,34,4,12,5,2} and T=9.

One possible subset is {4,5}, since 4+5=9.

So, the answer is YES.

Why Is It in NP?

 A candidate solution is a subset of the set S.


 To verify the solution, just sum the subset and check if it equals T.
 This verification step takes linear time, i.e., O(n).

Hence, Subset Sum is in NP.

Why Is It NP-Complete?

 It was one of the first problems proven to be NP-complete.


 The proof involves polynomial-time reduction from another NP-complete problem (like
3-SAT or CLIQUE).
 The reduction shows that any NP problem can be converted into a Subset Sum instance
in polynomial time.
Hamiltonian Path Problem

The Hamiltonian Path Problem is a famous NP-complete problem in graph theory. It can be
defined as:

Given a graph G=(V,E),


Does there exist a path that visits each vertex exactly once?

Such a path is called a Hamiltonian path.


If the path is a cycle (i.e., it starts and ends at the same vertex), it is called a Hamiltonian cycle
or Hamiltonian circuit.

Why Is It NP-Complete?

 The Hamiltonian Path problem was proven to be NP-complete through reduction from the
Hamiltonian Cycle problem (which is also NP-complete).

 Richard Karp included it in his 1972 list of 21 NP-complete problems.

 The problem remains NP-complete even in restricted cases, such as:

 Directed graphs (Directed Hamiltonian Path)


 Undirected graphs
 Planar graphs

Graph Coloring Problem


The Graph Coloring Problem is a well-known NP-complete decision problem in graph theory.

Given an undirected graph G=(V,E) and an integer k,


Can the vertices of the graph be colored using at most k colors
such that no two adjacent vertices have the same color?

This is called a proper coloring of the graph.

Why Is It NP-Complete?

 The Graph Coloring Problem is NP-complete for k≥3k \geq 3k≥3.


 The decision version (“Can this graph be colored with kkk colors?”) is computationally
hard.
 It was one of Karp’s 21 original NP-complete problems (1972).
 It can be reduced from other NP-complete problems, like 3-SAT.
Decidability and Tractability

A problem is said to be decidable if there exists an algorithm (or Turing machine) that always
halts and gives a correct YES/NO answer for every possible input instance of the problem.

A problem is undecidable if no such algorithm exists that can always give a correct answer and
halt in a finite amount of time.

Tractable and Intractable problems


A problem is tractable if it can be solved in polynomial time (i.e., time complexity O(n^k) for
some constant k).

Tractable problems are "efficiently solvable" in practice (belongs to class P).

A problem is intractable if no known algorithm can solve it in polynomial time.


Typically, it requires exponential or super-polynomial time.

Intractable = Not efficiently solvable

 Tractable problems are practical to solve with current computers.

 Intractable problems are theoretically solvable (if decidable), but too slow to be used directly
for large inputs.

 Understanding tractability helps computer scientists:

 Choose suitable algorithms


 Approximate or simplify problems
 Recognize limits of computation

Cook's Theorem:
Cook’s Theorem is a fundamental result in computational complexity theory that established the
concept of NP-completeness.

Cook's Theorem proves that SAT is NP-complete.

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.

You might also like