CS336f1012 - 10/13/10 Lecture 12 CS336 S10 Asymptotic...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 10/13/10 Lecture 12 CS336 S10 Asymptotic Dominance Uses
for
Big‐O 
 

 Give
a
big‐O
estimate
for
(log(n!+2n)).

For
 your
estimate,
use
the
simplest
function
of
the 
 smallest
order.
 

 1 10/13/10 Uses
for
Big‐O 
 

 Give
a
big‐O
estimate
for
(log(n!+2n)).

For
 your
estimate,
use
the
simplest
function
of
the 
 smallest
order.
 
 nlogn
 •  Give
a
big‐O
estimate
for
(n+3n2)(log
n!+
2n
+
 logn3).

For
your
estimate,
use
the
simplest
 function
of
the
smallest
order.

 2 10/13/10 •  Give
a
big‐O
estimate
for
(n+3n2)(log
n!+
2n
+
 logn3).

For
your
estimate,
use
the
simplest
 function
of
the
smallest
order.
 •  n22n

 Example
 Estimate
the
running
time

 So the running time is O(n) 3 10/13/10 For
Algorithm
3 
 Before
 n
 n‐1
 …
 1
 0
 1
 after
 n‐1
 n‐2
 time
 n
 n‐1
 For
Algorithm
4 
 Before
 n=2p
 n/2=2p‐1
 …
 2
 1
 1
 after
 n/2
 n/4
 time
 p
 p‐1
 4 10/13/10 Example

 •  First
the
inner
loop

 Example

 Before
 1
 2
 …
 n=2p
 after
 2
 4
 time
 c
 2c
 2pc
 5 10/13/10 •  Prove
that
every
nonempty,
full
binary
tree
 has
an
odd
number
of
nodes.

Recall,
with
our
 definition
of
a
full
tree
is
that
every
node
has
 either
0
or
2
children.
(12
points)

 Proof,
by
induction
on
h:
 Base
Case
h=0
 #N(d,
∅,
∅)=
1
 Which
is
odd.
 6 10/13/10 Inductive
step:
 STRONG
INDUCTION
on
height
 IH:

For
full
binary
trees
of
height
less
than
or
equal
to
 h,
the
number
of
nodes
is
odd
(or
2k+1
for
some
 integer
k).
 •  We
want
to
prove
this
is
true
for
a
tree
of
height
h+1.


 Let
t
be
a
full
binary
tree
of
height
h+1.

then
t=
(d,l,r)
 where
l
and
r
are
both
full
binary
trees
of
height
<=
 h.
 Inductive
step:
 #N
t
 =
 <t=(d,l,r)>
 #N
(d,l,r)
 =
 <L.1>
 #N
l+
#N
r+1
 =
 <induction
hypothesis,
there
exists
a
j,k>
 (2j+1)
+
(2k+1)+1
 =
 <I.1>
 2( j+k+1)+1


ODD
 Hence,

by
PMI,
QED.
 7 10/13/10 Prove
that
if
f
is
Θ(g)
then
f2
is
Θ(g2).
 
 First
show
f2
is
O(g2)
if
f
is
Θ(g)
then
f
is
O(g)

 Proof:
 |f2(x)|
 =<arith.>
 (|f(x)|)2
 ≤
<f
is
O(g)
and
squaring
is
an
increasing
function>
 (C1
|g(x)|)2

for
all
x>k1
 ≤  <algebra>
 C1
2|g2(x)|)

for
all
x>k1
 Hence
by
definition
of
big
O
with
C=
C12

and
k=
k1,
f2
is
 O(g2).
 Prove
that
if
f
is
Θ(g)
then
f2
is
Θ(g2).
 
 Now
show
g2
is
O(f2)
if
f
is
Θ(g)
then
g
is
O(f)

 Proof:
 |g2(x)|
 =<arith.>
 (|g(x)|)2
 ≤
<f
is
O(g)
and
squaring
is
an
increasing
function>
 (C1
|f(x)|)2

for
all
x>k1
 ≤  <algebra>
 C1
2|f2(x)|)

for
all
x>k1
 Hence
by
definition
of
big
O
with
C=
C12

and
k=
k1,
g2
is
 O(f2).
 8 10/13/10 Prove
that
if
f
is
Θ(g)
then
f2
is
Θ(g2).
 
 Now,
since
f2
is
O(g2)
and
g2
is
O(f2)
then
f2
is
Θ(g2)


 9 ...
View Full Document

This note was uploaded on 11/30/2010 for the course CS 336 taught by Professor Myers during the Fall '08 term at University of Texas at Austin.

Ask a homework question - tutors are online