0% found this document useful (0 votes)
99 views19 pages

Complexity Theory

1. An algorithm is a well-defined set of steps to solve a problem that takes inputs and produces outputs. 2. The time complexity of an algorithm describes how long it takes to run based on the size of the input. Common time complexities include constant, logarithmic, linear, quadratic, and exponential. 3. P and NP are complexity classes where problems in P can be solved in polynomial time on a deterministic machine and problems in NP can be solved in polynomial time on a non-deterministic machine.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views19 pages

Complexity Theory

1. An algorithm is a well-defined set of steps to solve a problem that takes inputs and produces outputs. 2. The time complexity of an algorithm describes how long it takes to run based on the size of the input. Common time complexities include constant, logarithmic, linear, quadratic, and exponential. 3. P and NP are complexity classes where problems in P can be solved in polynomial time on a deterministic machine and problems in NP can be solved in polynomial time on a non-deterministic machine.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Complexity Theory

What is an algorithm?
 It is a well defined procedure which will take set of values as
input and which will produce set of values of values as
output.
OR
• It is a combination of sequence of finite steps to solve the
problem.

Input Output
Properties of algorithm
 It should produce at least one output.
 It should take zero or more numbers of input.
 Every steps in algorithm should be unambiguous.
 It should produce the output within the finite amount of
time.
 It should be language independent
 For same input it should produce same output at any point of
time.
Rate of growth
Time Complexity Name Example
1 Constant Finding maximum or
minimum element from the
sorted array
logn Logarithmic Finding an element in sorted
array
n Linear Finding an element in
unsorted array

nlogn Linear logarithmic Sorting n items by DAC


(Merge sort ) Method
n2 Quadratic Sorting of n element ( If
already sorted ) by quick
sort method.
n3 Cubic Matrix multiplication
2n Exponential 0/1 knapsack problem
What is O(1)?????
 For any constant C if we find the ‘big oh’ then it will be O(1)

suppose f(n)=34500 and g(n)= 1 , it is given that f(n) is


O(g(n). How to show it???

if f(n) is 0(g(n) i.e. f(n)≤c .g(n)


34500 ≤ c.1, here we can take any value of c which will
satisfy this, in this case I can take 34500 .
Thus we can say for any constant C , C is O(1).
o i/p: Unsorted array of unique elements.
o o/p: Find the element such that it should not be maximum or
minimum.
Find the time complexity of given problem?
solution:
1. First we will sort the array and we can give any element other
than first and last index.
2. We can find the max and min and we will give any element other
than this.
3. we can take three element and we will compare these three
if a>b>c then b definitely neither maximum nor minimum.
Problem Classification
Problem

Procedure Procedure
with without
Algorithm Algorithm

Deterministic Nondeterministic
Machine Machine

Polynomial Exponential Polynomial Exponential


time Time Time time
Polynomial and exponential time
 Exponential time means , in essence , trying every possibility
and they are very slow in nature.
exponential time is O(kn), for some k.
• Polynomial time means having some clever algorithm to
solve a problem and we don’t try every possibility.
polynomial time is O(nk), for some k
Decision problem
 A decision problem is a question with YES or NO answer and
the answer depends on value of input.
example: “ given an array of n element ,search weather given
element is there or not”.

INPUT ALGORITHM
Complexity Class
 In computer science , in order to understand the problem for
which solution are not there , the problems are divided into
classes and we call them as complexity class.
 In complexity theory, a complexity class is a set of problems
with related complexity.
 It is the branch of Theory of Computation that studies the
resource required during computation to solve given
problem.

The most common resources are time and space.


Types of Complexity classes
 We have two complexity classes.
1) P class Complexity Problems
2) NP class

P-Class NP-Class

NP-Complete
NP-Hard
P class
 The complexity class P is the set of decision problem that can
be solved by deterministic machine in polynomial time ( P
stands for polynomial time).
 P class problem are set of problems whose solutions are easy
to find.
 In computer science we say problem is easy when we can
solve the problem in polynomial time.
NP-Class
 The complexity class NP(NP stands for non –deterministic
polynomial time) is the set of decision problems that can be
solved by non-deterministic machine in polynomial time.
 NP class problem refers to set of problems whose solution
are hard to find but easy to verify.
 Easy to verify means verification in polynomial time.
 Easy to verify if answer is ‘YES’.
How to verify:
 I/P: Graph with n vertices.
 Question: Does G contains Hamiltonian cycle or not?
1
Prover verifier
YES
2 3 4
HOW

5 6 7

YES
Verification done in O(n)
times.
Polynomial time reduction
 Let A is known problem and B is unknown problem.
 If B is polynomial reducible to A
B ≤p A then B is also known problem.

Polynomial equivalence : Two problems A and B are said to


be polynomial equivalent iff
A ≤p B and B ≤p A
NP-Hard
 It is a class of problem such that every problem in NP reduces to it.
 A problem Y is said to be NP-hard iff
X ≤p Y, for all X belongs to NP.

Important observation:
NP
X
This type of problem is hard to solve and hard
to verify also.
Y Y
NP-Complete
 A problem Y is NP-complete iff It is a part of both NP-Hard
and NP.
 A problem Y is said to be NP-Complete iff
X ≤p Y, for all X belongs to NP and Y belongs to NP.
NP
X
This type of problem is hard to solve but easy
to verify .
Y
Cont…
 How to show that a given decision problem Z is NPC ?
a) Show that Z belongs to NP
b) Select a known NPC problem Y
c) Construct a transformation Y ≤p Z
Relation between NPH and NPC
 All NP- complete is NP-Hard but all NP-Hard is not NP-
Complete.

NP-HARD

NP

NP-complete

You might also like