Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to get 2nd highest value from an array?

by gjb (Vicar)
on Dec 13, 2005 at 23:12 UTC ( #516469=note: print w/ replies, xml ) Need Help??


in reply to How to get 2nd highest value from an array?

If the list (or hash) is large, first doing a sort is a Really Bad IdeaTM given that this is an O(n log n) operation. As choedebeck's code above illustates it can be done in time linear in the size of the list/hash, i.e., O(n). This is a significant difference for large values of n.

Hope this helps, -gjb-


Comment on Re: How to get 2nd highest value from an array?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://516469]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2015-07-05 06:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls