It depends if Array/List is sorted or not. The given answer is incorrect and my one was downvoted. Thanks voting bots!
https://stackoverflow.com/questions/35386546/big-o-of-min-and-max-in-python
FROM WIKIPEDIA:
O(1) is applicable
An algorithm is said to be constant time O(1)... In a similar manner, finding the minimal value in an array sorted in ascending order
O(n) is applicable
O(n).. finding the minimal value in an unordered array is not a constant time operation as scanning over each element in the array is needed in order to determine the minimal value
You need to check all of the the values to find the minimal one if the list is not sorted. My first idea is that Python does not have a hidden support for caching function return values. I'm not certain if min(value) is considered deterministic in python if you supply a reference instead of an actual list.
Below is an easy way to memoize a function and its return values in Python. If you apply this the complexity of your function can be reduced to O(1)+n
def memoize(func):
cache = dict()
def memoized_func(*args):
if args in cache:
return cache[args]
result = func(*args)
cache[args] = result
return result
return memoized_func