2

Can some one provide me a real time example for how to calculate big theta.

Is big theta some thing like average case, (min-max)/2?

I mean (minimum time - big O)/2

Please correct me if I am wrong, thanks

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Navin Leon
  • 1,136
  • 3
  • 22
  • 44
  • 2
    Have you read e.g. http://en.wikipedia.org/wiki/Big_O_notation, which has a table comparing the various asymptotic notations? – Oliver Charlesworth Sep 17 '11 at 10:13
  • thanks for the link, yes i gone through this before; the table mainly describes abt big O and am hard to follow that, however i need real time example to get more understanding – Navin Leon Sep 17 '11 at 10:18

4 Answers4

7

Big-theta notation represents the following rule:

For any two functions f(n), g(n), if f(n)/g(n) and g(n)/f(n) are both bounded as n grows to infinity, then f = Θ(g) and g = Θ(f). In that case, g is both an upper bound and a lower bound on the growth of f.

Here's an example algorithm:

def find-minimum(List) 
  min = +∞
  foreach value in List 
    min = value if min > value
  return min

We wish to evaluate the cost function c(n) where n is the size of the input list. This algorithm will perform one comparison for every item in the list, so c(n) = n.

c(n)/n = 1 which remains bounded as n goes to infinity, so c(n) grows no faster than n. This is what is meant by big-O notation c(n) = O(n). Conversely, n/C(n) = 1 also remains bounded, so c(n) grows no slower than n. Since it grows neither slower nor faster, it must grow at the same speed. This is what is meant by theta notation c(n) = Θ(n).

Note that c(n)/n² is also bounded, so c(n) = O(n²) as well — big-O notation is merely an upper bound on the complexity, so any O(n) function is also O(n²), O(n³)...

However, since n²/c(n) = n is not bounded, then c(n) ≠ Θ(n²). This is the interesting property of big-theta notation: it's both an upper bound and a lower bound on the complexity.

Victor Nicollet
  • 24,361
  • 4
  • 58
  • 89
  • As I know that's not a big theta definition, there isn't anything says F(n)/G(n) it just says f(n) <= C1 g(n) and g(n) <= C2 f(n) ...., for your definition counter example, assume f = g = 0 for all n, so your definition has no meaning for this sample. – Saeed Amiri Sep 17 '11 at 10:56
  • 1
    Both definitions are equivalent, except for f = g = 0. – Victor Nicollet Sep 18 '11 at 16:59
  • For the example algorithm above: Should min be initially negative infinity? And only be set if min < value ? – Ye. Jan 28 '18 at 06:04
1

Big theta is a tight bound, for a function T(n): if: Omega(f(n))<=T(n)<=O(f(n)), then Theta(f(n)) is the tight bound for T(n).

In other words Theta(f(n)) 'describes' a function T(n), if both O [big O] and Omega, 'describe' the same T, with the same f.

for example, a quicksort [with correct median choices], always takes at most O(nlogn), at at least Omega(nlogn), so quicksort [with good median choices] is Theta(nlogn)

EDIT: added discussion in comments:
Searching an array is still Theta(n). the Theta function does not indicate worst/best case, but the behavior of the desired case. i.e, searching for an array, T(n)=number of ops for worst case. in here, obviously T(n)<=O(n), but also T(n)>=n/2, because at worst case you need to iterate the whole array, so T(n)>=Omega(n) and therefore Theta(n) is asymptotic bound.

amit
  • 175,853
  • 27
  • 231
  • 333
  • How about a searching a array of length n, here the best case is O(1) and worst case is O(n), then what is big theta in this case – Navin Leon Sep 17 '11 at 10:26
  • @Navin Leon: it is still Theta(n) worst case, the behavior of the Theta function is not worst/best case, it's asymptotic bound for the case you are looking for. i.e, searching for an array, T(n)=number of ops for worst case. in here, obviously `T(n)<=O(n)`, but also `T(n)>=n/2`, because at worst case you need to iterate the whole array, so `T(n)>=Omega(n)` and therefore Theta(n) is asymptotic bound. – amit Sep 17 '11 at 10:30
0

From http://en.wikipedia.org/wiki/Big_O_notation#Related_asymptotic_notations, we learn that "Big O" denotes an upper bound, whereas "Big Theta" denotes an upper and lower bound, i.e. in the limit as n goes to infinity:

f(n) = O(g(n))      -->    |f(n)| < k.g(n)

f(n) = Theta(g(n))  -->    k1.g(n) < f(n) < k2.g(n)

So you cannot infer Big Theta from Big O.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
0

ig-Theta (Θ) notation provides an asymptotic upper and lower bound on the growth rate of an algorithm's running time. To calculate the big-Theta notation of a function, you need to find two non-negative functions, f(n) and g(n), such that:

There exist positive constants c1, c2 and n0 such that 0 <= c1 * g(n) <= f(n) <= c2 * g(n) for all n >= n0. f(n) and g(n) have the same asymptotic growth rate. The big-Theta notation for the function f(n) is then written as Θ(g(n)). The purpose of this notation is to provide a rough estimate of the running time, ignoring lower order terms and constant factors.

For example, consider the function f(n) = 2n^2 + 3n + 1. To calculate its big-Theta notation, we can choose g(n) = n^2. Then, we can find c1 and c2 such that 0 <= c1 * n^2 <= 2n^2 + 3n + 1 <= c2 * n^2 for all n >= n0. For example, c1 = 1/2 and c2 = 2. So, f(n) = Θ(n^2).

drsu
  • 19
  • 4