|
|
| Don't ask to ask, just ask | |
| PerlMonks |
Re: Tracking minimum of values in an array over timeby ambrus (Abbot) |
| on Oct 06, 2011 at 15:47 UTC ( #930009=note: print w/ replies, xml ) | Need Help?? |
|
You can use a priority queue, such as a binary heap (Not necessarily that implementation, just something similar.) You keep the indices and values of your array in this priority queue, with lowest values down. Whenever you change a number in the array, you delete the corresponding entry from the priority queue and then reinsert a new one. The priority queue will then keep track of the element with the lowest value for you.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||