Created
February 3, 2021 22:30
-
-
Save juniorUsca/a00e7ed4404fb439294e39e7e45f2925 to your computer and use it in GitHub Desktop.
busqueda_binaria
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
datos = [100,1,2,3,4,10,20,45,67,32] | |
buscar = 32 | |
datos.sort() | |
print(datos) | |
inicio = 0 | |
fin = len(datos) - 1 | |
encontrado = False | |
while encontrado == False and inicio <= fin: | |
mitad = inicio + (fin-inicio)//2 | |
print("inicio, fin", inicio, fin) | |
print("posicion mitad", mitad) | |
print("elemento mitad", datos[mitad]) | |
print("--------") | |
if datos[mitad] == buscar: | |
encontrado = True | |
else: | |
if datos[mitad] > buscar: | |
fin = mitad - 1 | |
else: | |
inicio = mitad + 1 | |
if encontrado == True: | |
print("siiii 😎") | |
else: | |
print("no esta en la lista 🥲") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment