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

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -