Sie sind auf Seite 1von 3

CPS 130 Homework 4 - Solutions

1. (CLRS 4.2-2) Argue that the solution to the recurrence


( ) = ( 3) + (2 3) +
is
( lg ) by appealing to a recursion tree.
Solution: The recursion tree for the recurrence is given in CLRS. Note that the values
across the levels of the recursion tree sum to . The shortest path from a root to a leaf is
 1 2
1
! 3 ! 3 ! !1
Since (1 3) = 1 when = log3 , the height of the tree is at least log3 . Thus the
solution to the recurrence is at least log3 =
( lg ).
2. Give asymptotic upper and lower bounds for the following recurrences. Assume T(n) is
constant for  2. Make your bounds as tight as possible, and justify your answers.
 ( ) = ( 1) +
Solution: Note that you cannot apply Master method. Assume
(1) = 1 and
iterate:
( ) = ( 1) +
= ( 2) + ( 1) +
=
= ( 1) + ( 1 + 1) + +
= (1) + 2 + 3 +
X
=
=1
= ( 2+ 1)
= ( 2 )
 ( ) = (p ) + 1
Solution: Note that you cannot apply Master method. Assume
(2) = 1 and
iterate:
( ) = ( )+1
= ( )+1+1
=
= ( )+
T n

T n=

n=

:::

T n

T n

T n

T n

T n

:::

T n

:::

:::n

n n

T n

T n

T n2

T n4
:::

T n 2i

For this type of recurrence we cannot stop at 1 because cannot be 1, except


at the limit. The recursion depth is given by = 2, which gives = log log .
Substituting in the relation above we get:
( ) = (2) + log log
= (log log )
 ( ) = 2 ( 2) + lg
Solution: Note that you cannot apply Master method. Assume
(1) = 1 and
iterate:
( ) = 2 ( 2 ) + log
1

n 2i

n 2i

T n

T n

T n=

n=

T n

= 22 ( 22 ) + 2  log2
2
=
X1
= 2 ( 2 ) + log
=0
2
n

:::
i

X1
i

= 2 (2 ) +
i

k =0

log

n
n

The recursion depth is = log2 and substituting we get:


i

() = 2

log2 n

log2 n 1

(1) +

log
logX 1
1
= (1) + 
=0 log
log
X 1
= (1) + 
=1
= (1) +  log
= (1) +  (log log )
= ( log log )
Here we used the standard notation for the harmonic sum
X
= 1 = (log )
T n

k =0

2n

nT

2n

nT

nT

nT

Hn

k =1

 ( )= (

1) + 1
Solution: Assume
(1) = 1 and iterate:

T n

T n

=n

() =

T n

=
=
=

T n

T n
:::

T n

1) + 1

2) + 1 1 + 1
)+ 1+1 + + 1
n

::

Taking =
i

1 we get:

(1) + 21 + + 1
X1
=
=1
=
= (log )

() =

T n

:::

Hn

Das könnte Ihnen auch gefallen