Corretude - UFCG
Corretude - UFCG
Corretude - UFCG
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Introdução Indução Algoritmos Recursivos Algoritmos IterativosExemplo 10Considere o algoritmo BuscaLinear abaixo.BuscaLinear(A, k)// Input: Um array A[1 . . n] e uma chave de busca k.// Output: O indice do primeiro elemento em A que casa com k, ou 01 for i = 1 to A.length2 if A[i] == k3 return i4 return 0Invariante do Laço: No começo de cada iteração i do laço forA[j] ≠ k para todo j < i.Prof. Dr. Leandro Balby Marinho 27 / 44 <strong>UFCG</strong> CEEI