Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Tracking minimum of values in an array over time

by ambrus (Abbot)
on Oct 06, 2011 at 15:47 UTC ( #930009=note: print w/replies, xml ) Need Help??

in reply to Tracking minimum of values in an array over time

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.

  • Comment on Re: Tracking minimum of values in an array over time

Replies are listed 'Best First'.
Re^2: Tracking minimum of values in an array over time
by tj_thompson (Monk) on Oct 06, 2011 at 22:01 UTC

    A min heap would be an excellent way to determine the min value of the set at any time. Good call. For my particular problem, since I'm actually interested in making certain that all elements have crossed the floor value (as pointed out by Ant above), I think counting the number of values that cross the floor as they are incremented is the smartest solution.

    Good thoughts Ambrus, thanks!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://930009]
Discipulus was outside The Clash concert in 1985..
[marto]: Wolfsbane , now I'm having flashbacks
[choroba]: Isn't Using PerlPod Creatively rather a meditation?
[choroba]: I don't see a question
[1nickt]: ugh, I stuck my head in the bass bin for 30 seconds on a dare at Ted Nugent at Hammersmith Odeon. Yes, I am 40% deaf now.
[johngg]: My daughter is incredibly jealous of my wife who got to see The Clash at Brixton many years ago. They went to see The Vaccines there recently.

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2017-03-24 12:13 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (301 votes). Check out past polls.