Finding the Min for positive and negative in python 3.3 list

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Mar 13 07:23:22 EDT 2013


On 13 March 2013 10:43, Wolfgang Maier
<wolfgang.maier at biologie.uni-freiburg.de> wrote:
>
> thinking again about the question, then the min() solutions suggested so far
> certainly do the job and they are easy to understand.
> However, if you need to run the function repeatedly on larger lists, using min()
> is suboptimal because its performance is an O(n) one.
> It's faster, though less intuitive, to sort your list first, then use bisect on
> it to find the zero position in it. Two manipulations running at O(log(n)).

Sort cannot be O(log(n)) and it cannot be faster than a standard O(n)
minimum finding algorithm. No valid sorting algorithm can have even a
best case performance that is better than O(n). This is because it
takes O(n) just to verify that a list is sorted.


Oscar



More information about the Python-list mailing list