0% found this document useful (0 votes)
2 views

Polynomial Time U - 5

Uploaded by

13 JAYALAKSHMI K
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)
2 views

Polynomial Time U - 5

Uploaded by

13 JAYALAKSHMI K
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/ 5

UNIT - V

POLYNOMIAL TIME

X A

k
P O(n )

X Problem

A Algorithm
(Procedure for solve a problem based on
sequence of steps)

O(nk) Time Complexity


n - no. of input
k - Constant

P The algorithm complete to solve


the X problem during the Time
Complexity is a Polynomial Time
Polynomial Time:-
An algorithm is said to run in polynomial time.
The time complexity is expressed as a polynomial
function of the input size n.

T(n) = O(nk )
where,
n is the input size
k is the constant

Efficiency of Polynomial Time:-


Algorithms with polynomial time complexity are
efficient.
Their running time grows at reasonable rate as
the input size increases.

Exponent of Polynomial Time:-


The exponent k in the polynomial time expression
indicates the degree of the polynomial and influences
how the running time scales with the input size.
Examples of Polynomial Time:-
O(1) is a constant time (a polynomial with degree 0)
O(log n) is a logarithmic time (a polynomial with
degree 1)
O(n) is a linear time (a polynomial with degree 1)
O(n2) is a quadratic time (a polynomial with degree 2)
O(n3) is a cubic time (a polynomial with degree 3)

Reduction of Polynomial Time:-


Reduction is a method for solving one problem using
another.

X< PY

X Y
Polynomial Time
Reduction

Non deterministic
Polynomial Time
Reduce

NP

P NP
HARD
Algorithm for Polynomial Time:-
To compute the first n natural numbers.

#include<iostream>
int num(int n)
{
int sum=0;
#loop through the numbers from 1 to n
for(int i=1; i<=n; i++)
{
#add the values upto n
sum+=i;
}
return sum
}
int main()
{
#assume the value of n is 5
int n=5;
int value=num(n);
std::cout<<”Sum of the first”<<n<<”natural
numbers:”<<result<<std::endl;
return 0;
}
In this algorithm, the function num computes the sum of
first n natural numbers using for loop.
The Time Complexity of algorithm is O(n).
The loop iterates through the numbers from 1 to n, and
the sum is updated in each iteration.

You might also like