Open In App

Difference between Big O Notation and Tilde

Last Updated : 16 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In asymptotic analysis of algorithms we often come across terms like Big O, Omega, Theta and Tilde, which describe the performance of an algorithm. Here, we will see difference between two notations: Big O and Tilde.

Big O Notation (O)

This notation is basically used to describe the asymptotic upper bound. Mathematically, we can describe it as :

f(n) = O(g(n))
if there exist positive constants c and n0 such that
0 <= f(n) <= c*g(n)
for all n >= n0

The above notation depicts that at the point n = n0, the growth of the function g(n) increases gradually. In algorithms we always deal with larger values of n i.e. nā†’āˆž. So, we can also define the Big O notation as:

Photo1

Therefore, f(n) = O(g(n)) if the above limit value lies in the range [0 , āˆž)

Example: n2 = O(n3)

Read more about Big O Notation.

Tilde Notation (~)

Tilde notation is used when we want to make a simple approximation of a complex function. It simply drops the lower order terms. It is denoted by ~g(n). If f(n)~g(n) indicates that the value of f(n)/g(n) tends towards 1 for a larger value of n. Mathematically, we can express it as :

Photo2

Example:
1.  (n - 1/2)(n - 1/3) = n2 - 5n/6 + 1/6 can be written as ~n2 because when we divide both (n2 - 5n/6 + 1/6 and ~n2) the functions and find the limit for larger value of n, it will become 1.

2. In an AVL tree before we insert or delete a key, we first compare and find the location of the key. The number of comparisons required in the worst case is:

h+1, where h is the height of the tree.
The height will be log2n, since AVL tree is a height balanced tree.

Therefore, we can replace the value of h in the expression and it becomes :

log2n+1

We can ignore the lower order term and it becomes ~log2n. So, the number of comparisons in an AVL tree is approximated to ~log2n.

Some important points about ~ notation in asymptotic analysis:

  • It follows equivalence relation property.
  • It is identical to big theta notation. There is a minute difference in the arbitrary constant as in big theta notation there can be different values for the constants in the lower bound as well as upper bound but in the case of Tilde, we always get f/g value as 1 or tending towards 1.

Difference between big O notations and tilde

The differences between Big Oh and Tilde notations are:

Big Oh (O)Tilde (~)
It generally defines the upper bound of an algorithm.Since it is similar to theta notation, it defines both the upper bound and lower bound of an algorithm.

The arbitrary constant incase of Big Oh notation is c which is greater than zero.

0 <= f(n) <= c*g(n) ; c>0, n>=n0

Here, the constant will always be 1 since on dividing f by g or g by f we always get 1. So, it gives a sharper approximation of an algorithm.

If the time complexity of any algorithm is n3/3-n2+1 ,it  is given by O(n3) and the constant is ignored.

Here, for the same time complexity it will be ~(n3/3). This constant 1/3 is meaningless as in asymptotic analysis we are only interested to know about the growth of a function for a larger value of n.
It is mostly used in asymptotic analysis as we are always interested to know the upper bound of any algorithm.Big theta is mostly used instead of Tilde notation as in case of Big Theta we can have different arbitrary constants, c1 for upper bound and c2 for the lower bound.
It defines the worst case.It mostly defines the average case.

To get more insights about asymptotic analysis, refer to the following links :


Next Article

Similar Reads