Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complexity of algorithms and complexity of problems. What are the differences?

Tags:

I would like to know the difference between the complexity of an algorithm and the complexity of a problem, that is, which points differ from the two things

like image 829
Leomar de Souza Avatar asked Jun 24 '17 21:06

Leomar de Souza


People also ask

What is the difference between a problem and algorithm?

To summarize: A problem is a function or a mapping of inputs to outputs. An algorithm is a recipe for solving a problem whose steps are concrete and unambiguous. Algorithms must be correct, of finite length, and must terminate for all inputs.

What is complexity of a problem?

The complexity of a problem is the infimum of the complexities of the algorithms that may solve the problem, including unknown algorithms. Thus the complexity of a problem is not greater than the complexity of any algorithm that solves the problems.

What are the two types of complexity?

The complexity of an algorithm can be divided into two types. The time complexity and the space complexity.

What is complexity different types of complexity?

The complexity can be found in any form such as constant, logarithmic, linear, n*log(n), quadratic, cubic, exponential, etc. It is nothing but the order of constant, logarithmic, linear and so on, the number of steps encountered for the completion of a particular algorithm.


1 Answers

Good question! Most people make no distinction between the two, which is a big no-no.

Simply put, the complexity of an algorithm is the algorithm's running time. This could be represented many ways, big O, big Theta, or any of the assorted Landau Notations. There also other representations, but the most commonly used in big O notation, which can be applied to analyze the worst-case time complexity of an algorithm as a function of the input size.

The complexity of a problem is typically the lower bound of any algorithm that solves the problem (wiki is a decent resource here). For example we can prove comparison-based sorting has a lower bound of n log n. This means, any algorithm that sorts by comparing elements, no matter which algorithm, will take at least n log n time in the worst case. Using Landau notation we would say this problem takes Omega(n log n).

In summary, problem complexity is a lower bound and algorithm typically establishes an upper bound. When you find an algorithm whose upper bound matches a problem's lower bound, you've found an asymptotically optimal algorithm!

like image 134
ryan Avatar answered Sep 24 '22 11:09

ryan