June 2020
Intermediate to advanced
382 pages
11h 39m
English
If an algorithm takes the same amount of time to run, independent of the size of the input data, it is said to run in constant time. It is represented by O(1). Let's take the example of accessing the nth element of an array. Regardless of the size of the array, it will take constant time to get the results. For example, the following function will return the first element of the array and has a complexity of O(1):
def getFirst(myList): return myList[0]
The output is shown as:

Addition of a new element to a stack by using push or removing an element from a stack by using pop. Regardless of the size of the stack, ...
Read now
Unlock full access