Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def b_binaria_i(l, buscado):
- inicio = 0
- fin = len(l) - 1
- while inicio <= fin:
- medio = (inicio + fin) // 2
- if l[medio] == buscado:
- return True
- if l[medio] > buscado:
- fin = medio - 1
- else:
- inicio = medio + 1
- return False
- def b_binaria_r(l, buscado, inicio, fin):
- medio = (inicio + fin) // 2
- if inicio <= fin:
- if l[medio] == buscado:
- return True
- if l[medio] > buscado:
- return b_binaria_r(l, buscado, inicio, medio - 1)
- return b_binaria_r(l, buscado, medio + 1, fin)
- return False
- lista = [1, 4, 7, 8, 9, 10, 11, 15, 20, 23]
- print(b_binaria_r(lista, 2, 0, 9))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement