Open In App

Difference between big O notations and tilde

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

In asymptotic analysis of algorithms we often encounter terms like Big-Oh, Omega, Theta and Tilde, which describe the performance of an algorithm. 
You can refer to the following links to get more insights about asymptotic analysis :

  1. Analysis of Algorithms 
  2. Different Notations
  3. Difference between Big Oh, Big Omega and Big Theta

In this article we are going to see the difference between the two notations: Big Oh and Tilde.

1. Big Oh 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-Oh notation as :

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

Example – n^2=O(n^3)

2. 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 :

Example 
1. (n-1/2)(n-1/3) = n^2-5/6n+1/6      can be written as ~n^2     because when we divide both 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 log_2n, since AVL tree is a height balanced tree. 

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

log_2n+1

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

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.

The differences between Big Oh and Tilde notations are :

S No-Big Oh (O)Tilde (~)
1It 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.
2

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.
3.

If the time complexity of any algorithm is 

n^3/3-n^2+1     ,it  is given by O(n^3     ) and the constant is ignored.

Here, for the same time complexity it will be ~(n^3/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.
4.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.
5.It defines the worst case.It mostly defines the average case.

For more details, please refer: Design and Analysis of Algorithms.


Last Updated : 13 Jul, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads