22.06.2015 Views

Capítulo 3 Complejidad de algoritmos recursivos ⎩ ⎨ ⎧ = > − = 0 1 0 ...

Capítulo 3 Complejidad de algoritmos recursivos ⎩ ⎨ ⎧ = > − = 0 1 0 ...

Capítulo 3 Complejidad de algoritmos recursivos ⎩ ⎨ ⎧ = > − = 0 1 0 ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Instituto Tecnológico <strong>de</strong> Ciudad Ma<strong>de</strong>ro<br />

Dra. Laura Cruz Reyes<br />

Unidad I COMPLEJIDAD DE ALGORITMOS<br />

Capítulo 3 <strong>Complejidad</strong> <strong>de</strong> <strong>algoritmos</strong> <strong>recursivos</strong><br />

T n n n n n<br />

m−1<br />

( ) = + 3 + 9 + ... + 3 + 0<br />

(log 3 n) −1<br />

T( n) = n+ 3n+ 9 n+ ... + 3 n<br />

(log 3 n) −1<br />

i<br />

Tn ( ) = n∑<br />

(3 )<br />

i=<br />

0<br />

k<br />

i<br />

k+<br />

Usando la serie ∑ ar = a (( r 1 −1)/( r −1)<br />

)<br />

i=<br />

0<br />

, se resuelve la recurrencia.<br />

log 3 ( n) 2<br />

⎛(3 −1) ⎞ nn ( −1)<br />

n −n<br />

Tn ( ) = n⎜<br />

⎟= ==<br />

⎝ 3−1 ⎠ 2 2<br />

Tn<br />

2<br />

( ) =Θ( n)<br />

El siguiente ejemplo ilustra el segundo caso correspondiente a una serie constante.<br />

⎧T(2 n/3) + 1 n><br />

1<br />

Tn ( ) = ⎨<br />

⎩0 n = 1<br />

De la fórmula general <strong>de</strong> divi<strong>de</strong>-y-vencerás:<br />

T(n) = b T( n/c ) + f(n),<br />

b=1, c=3/2, f(n) =1,<br />

Para <strong>de</strong>terminar que la recurrencia correspon<strong>de</strong> al caso 2 <strong>de</strong>l Teorema Maestro, sea,<br />

f( n) = 1<br />

gn n n n<br />

log c log 3/2<br />

( ) = b = 1 = 0 = 1<br />

Se <strong>de</strong>muestra que f(n) = Θ(g(n)):<br />

⎛ f( n) ⎞ ⎛1⎞<br />

lim ⎜ ⎟= lim ⎜ ⎟=<br />

1<br />

x→∞<br />

gn ( ) x→∞<br />

⎝ ⎠ ⎝1⎠<br />

c<br />

∴ f( n) =Θ n<br />

log b<br />

( )<br />

logc Como f( n ) =Θ ( n<br />

b ), entonces todos los lgn términos <strong>de</strong> la recurrencia son iguales al<br />

último término,<br />

∴ Tn=Θ n n=Θ n n=Θ<br />

n<br />

logc log3/21<br />

( ) ( b<br />

lg ) ( lg ) (lg )<br />

Alternativamente se pue<strong>de</strong> resolver la recurrencia mediante la construcción <strong>de</strong>l árbol <strong>de</strong><br />

recursión.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!