June 2020
Intermediate to advanced
382 pages
11h 39m
English
An algorithm is said to run in logarithmic time if the execution time of the algorithm is proportional to the logarithm of the input size. With each iteration, the input size decreases by a constant multiple factor. An example of logarithmic is binary search. The binary search algorithm is used to find a particular element in a one-dimensional data structure, such as a Python list. The elements within the data structure need to be sorted in descending order. The binary search algorithm is implemented in a function named searchBinary, as follows:
def searchBinary(myList,item): first = 0 last = len(myList)-1 foundFlag = False while( first<=last and not foundFlag): mid = (first + last)//2 if myList[mid] ...
Read now
Unlock full access