Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Binary Search
#python 3.5.2 from time import time array = [i for i in range(9999999)] N = -90 def binary_search(arr,N): length = len(arr) mid = length//2 if( arr[mid] == N or length == 1): if(length == 1 and arr[0] != N): return 'Not Found , but nearest number found is : ' + str(arr[0]) else: return 'Found' elif(arr[mid] < N): return binary_search(arr[mid+1:],N) else: return binary_search(arr[:mid],N) start = time() print(binary_search(array,N)) end = time() print("Total search time : ", end - start)
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
inerse_matrix_gauss_jordan
sum of odd numbers
#converting list into set
Prime Factorization of a Number
even odd
Page353ex42
Email_Python
Example for striping string
lesson 6 final
square cube function
Please log in to post a comment.