<< Chapter < Page Chapter >> Page >

Note that in the while loop two comparisons and one addition are performed. Thus one could use 3n as an estimate just as well. Also note that the very first line and the last two lines are not counted in. The reasons for those are firstly that differences in implementation details such as languages, commands, compilers and machines make differences in constant factors meaningless, and secondly that for large values of n, the highest degree term in n dominates the estimate. Since we are mostly interested in the behavior of algorithms for large values of n , lower terms can be ignored compared with the highest term. The concept that is used to address these issues is something called big-oh, and that is what we are going to study here.

Big - oh

The following example gives the idea of one function growing more rapidly than another. We will use this example to introduce the concept the big-Oh.

Example: f(n) = 100 n2, g(n) = n4, the following table and Figure 2 show that g(n) grows faster than f(n) when n>10. We say f is big-Oh of g.

n f(n) g(n)
10 10,000 10,000
50 250,000 6,250,000
100 1,000,000 100,000,000
150 2,250,000 506,250,000

Definition (big-oh): Let f and g be functions from the set of integers (or the set of real numbers) to the set of real numbers. Then f(x) is said to be O( g(x) ) , which is read as f(x) is big-oh of g(x) , if and only if there are constants C and n0 such that

     | f(x) | ≤ C | g(x) |

whenever x>n0 .

Note that big-oh is a binary relation on a set of functions (What kinds of properties does it have ? reflexive ? symmetric ? transitive ?).

The relationship between f and g can be illustrated as follows when f is big-oh of g.

For example, 5 x + 10  is big-oh of  x2,   because 5 x + 10<5 x2 + 10 x2 = 15 x2   for   x>1 .  

Hence for C = 15 and n0 = 1 ,   | 5x + 10 | ≤ C | x2 | . Similarly it can be seen that  3 x2 + 2 x + 4<9 x2  for   x>1 .   Hence 3 x2 + 2 x + 4 is O( x2 ) . In general, we have the following theorem:

Theorem 1: an xn + ... + a1 x + a0   is   O( xn )   for any real numbers an , ..., a0 and any nonnegative number n .

Note: Let f(x) = 3 x2 + 2 x + 4, g(x) = x2, from the above illustration, we have that f(x) is O(g(x)). Also, since x2<3 x2 + 2 x + 4, we can also get g(x) is O(f(x)). In this case, we say these two functions are of the same order.

Growth of combinations of functions

Big-oh has some useful properties. Some of them are listed as theorems here. Let use start with the definition of max function.

Definition (max function): Let f1(x) and f2(x) be functions from a set A to a set of real numbers B. Then max( f1(x) , f2(x) ) is the function from A to B that takes as its value at each point x the larger of f1(x) and f2(x).

Theorem 2: If  f1(x) is O( g1(x) ) , and   f2(x) is O( g2(x) ) , then  (f1 + f2)( x )  is   O( max( g1(x) , g2(x) ) ) .

From this theorem it follows that if  f1(x)  and  f2(x) are O( g(x) ) , then  (f1 + f2)( x )  is O( g(x) ) , and

(f1 + f2)( x )  is  O( max( f1(x) , f2(x) ) ) .

Theorem 3: If  f1(x) is O( g1(x) ) , and   f2(x) is O( g2(x) ) , then  (f1 * f2)( x )  is   O( g1(x) * g2(x) ) .

Questions & Answers

1. Discuss the processes involved during exchange of fluids between intra and extracellular space.
Mustapha Reply
what are components of cells
ofosola Reply
twugzfisfjxxkvdsifgfuy7 it
Sami
58214993
Sami
what is a salt
John
the difference between male and female reproduction
John
what is computed
IBRAHIM Reply
what is biology
IBRAHIM
what is the full meaning of biology
IBRAHIM
what is biology
Jeneba
what is cell
Kuot
425844168
Sami
what is biology
Inenevwo
what is sexual reproductive system
James
what is cytoplasm
Emmanuel Reply
structure of an animal cell
Arrey Reply
what happens when the eustachian tube is blocked
Puseletso Reply
what's atoms
Achol Reply
discuss how the following factors such as predation risk, competition and habitat structure influence animal's foraging behavior in essay form
Burnet Reply
cell?
Kuot
location of cervical vertebra
KENNEDY Reply
What are acid
Sheriff Reply
define biology infour way
Happiness Reply
What are types of cell
Nansoh Reply
how can I get this book
Gatyin Reply
what is lump
Chineye Reply
what is cell
Maluak Reply
what is biology
Maluak
what is vertibrate
Jeneba
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Discrete structures. OpenStax CNX. Jan 23, 2008 Download for free at http://cnx.org/content/col10513/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Discrete structures' conversation and receive update notifications?

Ask