python - binary search complexity -


we got question in class asks if binary search algorithm:

def binary_search(array, needle_element):     mid = (len(array)) // 2     if not len(array):         return false     if needle_element == array[mid]:         return true     **if** needle_element > array[mid]:         return binary_search(array[mid + 1:],needle_element)     **if** needle_element < array[mid]:         return binary_search(array[:mid],needle_element) 

compare algorithm elif instead of 2 lasts if. stay on same time complexity? meaning still log(n)?


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -