Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Binary search

by davido (Archbishop)
on Mar 29, 2013 at 16:33 UTC ( #1026168=note: print w/ replies, xml ) Need Help??


in reply to Binary search

There's a good discussion on Binary Searches with Perl in Mastering Algorithms with Perl (O'Reilly). I know this is probably homework, but if you need to see several different ways to implement a Binary Search in Perl you can view the source for List::BinarySearch. One of the methods used is adapted from the book mentioned above, and the other methods were based on a composite from several sources including Wikipedia and a couple of other algorithms books I happened to have.

But moritz is right: If your list isn't sorted to begin with, a Binary Search won't produce useful results. You'll either need to sort the list, or do a linear search.


Dave


Comment on Re: Binary search

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2014-12-22 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (118 votes), past polls