Advertisement
fahadkalil

busca_binaria_interativa

May 10th, 2021
1,297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. def busca_binaria(lista, alvo):
  2.     _min = 0
  3.     _max = len(lista) - 1
  4.        
  5.     while _min <= _max:
  6.         _mid = (_max + _min) // 2
  7.  
  8.         if lista[_mid] == alvo:
  9.             return _mid
  10.        
  11.         elif lista[_mid] < alvo:
  12.             _min = _mid + 1
  13.  
  14.         else:
  15.             _max = _mid - 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement