Advertisement
fmasanori

Busca Binária

Nov 22nd, 2011
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. def busca_binaria(x, v):
  2.     e = -1
  3.     d = len(v)
  4.     while e < d-1:
  5.         m = (e + d) // 2
  6.         if v[m] < x:
  7.             e = m
  8.         else:
  9.  
  10.     return d
  11.  
  12. import random
  13. v = []
  14. for i in range(1000):
  15.     v.append(random.randint(1, 1000))
  16. v.sort()
  17.  
  18. print (busca_binaria(500, v))
  19.  
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement