13.04.2013 Views

Algoritmos e complexidade Notas de aula - Arquivo Escolar

Algoritmos e complexidade Notas de aula - Arquivo Escolar

Algoritmos e complexidade Notas de aula - Arquivo Escolar

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

8 ci := ci + ci−1<br />

9 end for<br />

10 for i := n, . . . , 1 do<br />

11 bca i := ai<br />

12 ca i := ca i − 1<br />

13 end for<br />

14 return b1, . . . , bn<br />

Loteria Esportiva<br />

2.2. Complexida<strong>de</strong> pessimista<br />

Algoritmo 2.7 (Loteria Esportiva)<br />

Entrada Um vetor <strong>de</strong> inteiros r[1, . . . , n] com o resultado e uma matriz<br />

A13xn com as apostas dos n jogadores.<br />

Saída Um vetor p[1, . . . , n] com os pontos feitos por cada apostador.<br />

1 i := 1<br />

2 while i ≤ n do<br />

3 pi := 0<br />

4 for j <strong>de</strong> 1, . . . , 13 do<br />

5 i f Ai,j = rj then pi := pi + 1<br />

6 end for<br />

7 i := i + 1<br />

8 end while<br />

9 for i <strong>de</strong>1, . . . , n do<br />

10 i f pi = 13 then p r i n t ( Apostador i é ganhador ! )<br />

11 end for<br />

12 return p<br />

Exemplo 2.10 (Busca Binária)<br />

Busca Binária<br />

45

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

Saved successfully!

Ooh no, something went wrong!