


















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!



















Sept
Our
principle
interest
in
analyzing
algorithms
is
to
determine
time
and
space
efficiency
We
measure
these
relative
to
the
problem
size,
which
we
usually
denote
by
n
Time
how
fast
an
algorithm
runs
Space
amount
of
memory
an
algorithm
uses
c
op
execution
time
of
basic
operation
(machine/language/system
dependent)
C(n)
number
of
basic
operations
required
for
a
problem
of
size
n
T(n)
estimated
running
time
op
our
real
interest
< day
< month
year
For
a
particular
problem
size,
we
may
be
interested
in:
Worst
case
efficiency:
Longest
running
time
for
any
input
of
size
n
Best
case
efficiency:
Shortest
running
time
for
any
input
of
size
n
Average
case
efficiency:
Average
running
time
for
all
inputs
of
size
n
Algorithm:
Selection
Sort
Best
case:
Worst
case:
Average
case:
∑
− =
(^11) n i
i
∑
− =
(^11) n i
i
∑
− =
(^11) n i
i
This
measure
spreads
cost
over
multiple
runs
of
an
algorithm
Useful
in
cases
when
results
of
a
high
cost
portion
of
an
algorithm
can
be
reused.
Example:
search
sort
binary
search
If
the
data
rarely
changes,
we
can
avoid
the
sort
portion
of
the
algorithm
for
most
runs.
Suggest
a
modification
to
a
sorting
algorithm
that
results
in
best
case
comparison
count
of
n
Would
it
be
a
good
idea
to
make
this
modification
to
all
sorting
algorithms?
O(g(n))
big
Oh
all
functions
which
grow
slower,
or
the
same,
as
g(n)
(g(n))
big
Omega
all
function
that
grow
faster,
or
the
same,
as
g(n)
(g(n))
big
Theta
all
functions
with
same
order
of
growth
as
g(n)
Reflexivity:
f(n)
є
O(f(n))
f(n)
є Θ
(f(n))
f(n)
є Ω
(f(n))
Transitivity:
f(n)
є
O(g(n))
and
g(n)
є
O(h(n))
Æ
f(n)
є
O(h(n))
f(n)
є Θ
(g(n))
and
g(n)
є Θ
(h(n))
Æ
f(n)
є Θ
(h(n))
f(n)
є Ω
(g(n))
and
g(n)
є Ω
(h(n))
Æ
f(n)
є Ω
(h(n))