

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Mihaela Gheorghiu Spring 2002 CSCE-310 Data Struct. & Alg.
More on Asymptotic Notation
January 23, 2002
How to use asymptotic notation for algorithm analysis.
Asymptotic notation is used to determine rough estimates of relative running time of algo-
rithms. In class we saw an example of worst-case analysis of pseudocode that led to a big-O
estimate. A worst-case analysis of any algorithm will always yield such an estimate, because it
gives an upper bound on the running time
of the algorithm, that is
, and so
. In some cases, an exact analysis of the running time is possible, and then we get
, so
. Here is an example:
a <- 0 1 unit 1 time
for i <- 1 to n do 1 unit n times
for j <- 1 to i do 1 unit n(n+1)/2 times
a <- a+1 1 unit n(n+1)/2 times
where the times for the inner loop have been computed as follows: for each from to
, the loop
is executed times, so the total number of times is
(see Appendix A.1 in the book for this, and other summation formulas). Hence in this case
If we write
7 , then
, that is
. We actually
write
, as recommended by the following rule.
Be as simple and as precise as possible in analysis.
Although the definitions of asymptotic notation allow one to write, for example,
, in practice we never write something like that; we simplify the function in between
the parentheses as much as possible (in terms of rate of growth), and write instead
.
Similarly, we don’t write, for example,
, but
. Also, it is
wrong to write, for instance,
; write instead
, after computing the sum.
Also, the analysis should be as precise as possible, in the sense that it should provide the closest
asymptotic bounds for functions; for example, while it is true that!
, we know that! is
actually constant time, rather than quadratic time, so!
or!
is the right analysis.
In the spirit of the simplicity rule above, when we are to compare, for instance, two candidate
algorithms H and I having running times
and
.! , rather
than writing
, we write
, and
, and then we
1
Mihaela Gheorghiu Spring 2002 CSCE-310 Data Struct. & Alg.
conclude that H is better than I , using the fact that
(quadratic) is better than
(cubic) time,
since
. A comparison of the most common functions is given next.
Common functions.
The following relations hold for some of the most common functions encountered in algorithm
analysis (where “ ” means “better than”):
The same relations hold for
instead of
. Also, the following general rules apply:
, for any constants where
;
, for any
constants with ;
(
, for any constants , with .
The same rules apply for
instead of
.
Other things to prove about asymptotic bounds.
iff
. Proof: By definition,
iff there exist constants
! such that
, for all
. Dividing by , we get
, for all
. But this is just
the definition of
, in which
.
.
Proof: By contradiction. Suppose!
, Then, by definition, we have constants $
such that !
, for all
. Dividing by
we get !
, for all
. This
means that
, for all
. But this is obviously not true for
&(')*
%-,
.
.,
at position. Justify your answer.
(a)
3
;
(b) / ( 54 (
.
Solution: (a) Using the property of logarithms
7698 ;: <
, we get
3
, so
.
(b) Using the fact that /1032=
6
, we get / ( 54 (
/ ( ?>
, so / ( @4 (
(since
"
for all
A"
).
Read carefully Chapter 3 of the book, with all the details pertaining to
, including
Section 3.2. Be prepared to use formulas from this section, and from Appendix A of the book
at any time.
2