Follow

Subscribe

Follow

Subscribe

Asymptotic classes

Continue to deepen your knowledge of algorithm analysis. Learn about asymptotic classes and the differences in performance between them.

Before reading this article, you must have already read the article on asymptotic behavior. If you haven’t read it yet, click here.

We saw in the last article the importance of identifying asymptotic behavior for the algorithm analysis process. In this article we will know the asymptotic classes. Classes that computer science uses to classify algorithms according to their performance.

Introduction to asymptotic classes of algorithms

It has been shown that the T(n) complexity function of an algorithm provides little detail about its efficiency. However, the graphical analysis of its asymptotic behavior can show more accurately how its performance behaves during its execution.

The secret of the asymptotic behavior of an algorithm lies in the highest degree polynomial term of its complexity function, as this term defines its asymptotic class. See below:

In the algorithm:

classes-assintoticas-formula-01

What really matters is the highest degree term, the n2. Therefore, it is a quadratic class algorithm.

In the algorithm:

classes-assintoticas-formula-02

What really matters is the highest degree term, the n. Therefore, it is a linear class algorithm.

In the algorithm:

classes-assintoticas-formula-03

What really matters is the highest degree term, the n2. Therefore, it is a quadratic class algorithm.

In the algorithm:

classes-assintoticas-formula-04

What really matters is the highest degree term, the n. Therefore, it is a linear class algorithm.

In the algorithm:

classes-assintoticas-formula-05

What really matters is the highest degree term, the n. Therefore, it is a linear class algorithm.

See below a list of the most common asymptotic classes existing in algorithm analysis.

n!

Factorial

The worst class of algorithm. It usually occurs in some algorithms that use brute force technique to solve problems.

classes-assintoticas-graph-01
2n

Exponential

More efficient than factorial, but still far from being an efficient algorithm. It also occurs in algorithms that use brute force to solve problems.

classes-assintoticas-graph-02
nk

Polynomial

They are more efficient than exponentials, but are only suitable for solving small problems. When the value of n grows a lot, the algorithm becomes very inefficient.

classes-assintoticas-graph-03
n2

Quadratic

Quadratic order polynomials. This class occurs a lot in algorithms that process information in pairs. Usually in nested loops (one loop inside the other).

classes-assintoticas-graph-04
n log n

Loglinear

Slightly less efficient than linear ones. This is a typical asymptotic class of algorithms that implement the “divide and conquer” paradigm.

classes-assintoticas-graph-05
n

Linear

Very efficient algorithm. The linear class occurs in algorithms that need to process n input elements and do small computations on those elements.

classes-assintoticas-graph-06
log n

Logarithmic

The best of all worlds for algorithms. This class is typical of algorithms that can solve problems by turning them into smaller problems at each step of the solution.

classes-assintoticas-graph-07
1

Constant

The nirvana of algorithms.
In fact, this is a very unlikely situation, as it occurs in algorithms that do not perform any significant computations and therefore are not very useful.

classes-assintoticas-graph-08

Difference in efficiency within the same class

What if two algorithms are of the same asymptotic class? Which will be the most efficient?

Two algorithms belonging to the same class have the same asymptotic behavior. This means that: small variations in performance between algorithms of the same class are not of great importance.

Let’s see why:

Imagine two algorithms C and D, both of linear class:

classes-assintoticas-algo-c

Algorithm C

classes-assintoticas-algo-d

Algorithm D

Below is the table with the number of instructions performed by the algorithms for the initial values of n. It can be seen that the C algorithm is more efficient than D, despite both being from the same asymptotic class (the linear class).

classes-assintoticas-algo-c-table
classes-assintoticas-algo-d-table

Regardless of the fact that algorithm C is more efficient than D, this difference between efficiencies will never propagate. Observe in the graphs illustrated below how the difference in efficiency between both will always remain constant for different values of n.

classes-assintoticas-anim-01

Note that, regardless of how large the value of n is, the efficiency difference between algorithms of the same asymptotic class will always remain constant. For this reason, the additive and multiplicative constants of the complexity formula are not important for the analysis. In algorithms belonging to the same class, the performance will be very similar for large values of n(n→∞).

In this way, it is clear that, for the analysis of algorithms, what matters is just defining the class of the algorithm, as it defines its asymptotic behavior.

Difference in efficiency in different classes

In algorithms of different asymptotic classes, the difference in efficiency will propagate as the value of n grows. Consider the two algorithms E(quadratic class) and F(linear class):

classes-assintoticas-algo-e

Algorithm E

classes-assintoticas-algo-f

Algorithm F

Below is the table with the number of instructions performed by the algorithms for the initial values of n. It is noticed that the F algorithm is more efficient than the E.

classes-assintoticas-algo-e-table
classes-assintoticas-algo-f-table

The interesting thing to note here is that this difference in efficiency between the algorithms propagates as the value of n grows, as these are two algorithms of different asymptotic classes. Observe in the graphs illustrated below how the difference in efficiency between both propagates for different values of n.

classes-assintoticas-anim-02

Note that, as the value of n grows, the difference in efficiency between the algorithms becomes increasingly pronounced. Therefore, the importance of asymptotic classes for the analysis process is clear. In algorithms belonging to different classes, the performance will suffer a lot of impact for large values of n(n→∞).

Continue your studies in this course and read the next article where we introduce the concept of asymptotic notation (the famous BIG O notation), used to formally represent asymptotic behaviors in algorithm analysis.

Was this article helpful to you?

So support us and share it with others who are interested in this subject!

WhatsApp
Facebook
Twitter
LinkedIn
Email

Other articles

Subscribe

This website uses cookies to ensure you get the best experience on our website.