Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polynomial time and exponential time

Tags:

algorithm

Could someone explain the difference between polynomial-time, non-polynomial-time, and exponential-time algorithms?

For example, if an algorithm takes O(n^2) time, then which category is it in?

like image 676
Abdul Samad Avatar asked Nov 30 '10 19:11

Abdul Samad


People also ask

What is the difference between exponential and polynomial?

Polynomial Function: A single term or the sum of two or more terms containing variables with positive whole-number exponents. You cannot have a variable in the denominator (this means that you can't divide by x). Exponential Function: This type of function has an x as the exponent.

Is polynomial time better than exponential time?

In general a polynomial algorithm will be considered to be more efficient than an exponential algorithm.

What is polynomial time?

An algorithm is said to be of polynomial time if its running time is upper bounded by a polynomial expression in the size of the input for the algorithm, that is, T(n) = O(nk) for some positive constant k.

What does exponential time mean?

noun. An amount of time expressible as an exponential whose exponent is an increasing function of the size of a given problem whose solution is required.


2 Answers

Below are some common Big-O functions while analyzing algorithms.

  • O(1) - constant time
  • O(log(n)) - logarithmic time
  • O((log(n))c) - polylogarithmic time
  • O(n) - linear time
  • O(n2) - quadratic time
  • O(nc) - polynomial time
  • O(cn) - exponential time
  • O(n!) - factorial time

(n = size of input, c = some constant)

Here is the model graph representing Big-O complexity of some functions

graph model

cheers :-)

graph credits http://bigocheatsheet.com/

like image 76
Mohan Avatar answered Oct 11 '22 08:10

Mohan


Check this out.

Exponential is worse than polynomial.

O(n^2) falls into the quadratic category, which is a type of polynomial (the special case of the exponent being equal to 2) and better than exponential.

Exponential is much worse than polynomial. Look at how the functions grow

n    = 10    |     100   |      1000  n^2  = 100   |   10000   |   1000000   k^n  = k^10  |   k^100   |    k^1000 

k^1000 is exceptionally huge unless k is smaller than something like 1.1. Like, something like every particle in the universe would have to do 100 billion billion billion operations per second for trillions of billions of billions of years to get that done.

I didn't calculate it out, but ITS THAT BIG.

like image 45
hvgotcodes Avatar answered Oct 11 '22 10:10

hvgotcodes