Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2016-10-22 13:01 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (294 votes). Check out past polls.