Difference between Big-Theta and Big O notation in simple language

后端 未结 6 987
既然无缘
既然无缘 2020-12-04 09:08

While trying to understand the difference between Theta and O notation I came across the following statement :

The Theta-no         


        
6条回答
  •  感动是毒
    2020-12-04 09:51

    In very simple language difference would be like this:

    Big O notation is used for the worst case analysis of an algorithm. Big Omega is used for the best case analysis of an algorithm. Big Theta is used for the analysis of an algorithm when the the best case and worst case analysis is the same.

    Let's say you are looking for a number in a sorted array using binary search algorithm.

    [1 2 3 4 5 6 7] 
    

    In the worst case , such as when the target is 1 it has to perform log(n) split checks, which is log(7) in our case. It can be expressed as O(n).

    In the best case, such when the target is 3 it only performs one operation. It can be expressed as Ω(1)

提交回复
热议问题