Finding min or max value of an iterable (like keys of a dict, where keys are numbers) seems like the easiest thing in the world in Python:
my_dict = {2: 'v1', 4: 'v2', -1: 'v3'}
min(my_dict) # -> -1
max(my_dict) # -> 4
However, it feels like (it's mentioned here) that min
and max
always work on iterables, thus ensuring at least Ω(n) complexity.
But we are working with hash tables here, aren't we? Can't we make use of this fact and reduce complexity to O(1) or at least to O(log n)?