06.05.2013 Views

presentación-PDF

presentación-PDF

presentación-PDF

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.

Subsecuencia de suma máxima III<br />

public static int subsecuenciaSumaMaxima (int [] a)<br />

{<br />

int sumaMax = 0; O(1)<br />

int sumaActual = 0; O(1)<br />

for (j = 0; j < a.length; j++) O(n)<br />

{<br />

sumaActual += a [j];<br />

if (sumaActual > sumaMax)<br />

sumaMax = sumaActual;<br />

else if (sumaActual < 0)<br />

{<br />

O(1)<br />

O(n)<br />

sumaActual = 0;<br />

}<br />

}<br />

return sumaMax; O(1)<br />

}<br />

Complejidad: O(1) + O(1) + O(n) + O(1) = O (n)

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

Saved successfully!

Ooh no, something went wrong!