Skip to content

Instantly share code, notes, and snippets.

@danielnunesdc
Created February 16, 2018 02:25
Show Gist options
  • Select an option

  • Save danielnunesdc/22cd79819ed55f9e2a06cae9bb2d51a3 to your computer and use it in GitHub Desktop.

Select an option

Save danielnunesdc/22cd79819ed55f9e2a06cae9bb2d51a3 to your computer and use it in GitHub Desktop.
from time import time
from random import shuffle
def busca_sequencial(v, x):
indice = 0
while indice < len(v):
if v[indice] == x:
return indice
indice += 1
return -1
vetor = list(range(0, 100))
shuffle(vetor)
print(vetor)
chave = 40
antes = time()
posicao = busca_sequencial(vetor, chave)
depois = time()
total = (depois - antes) * 1000
if posicao >= 0:
print('\nO elemento {} foi encontrado na posição {}.'.format(chave, posicao))
else:
print('\no elemento NÃO foi encontrado.')
print('\nO tempo total gasto foi {:.2} ms.'.format(total))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment