Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: List::BinarySearch and conditional tests with Test::More

by davido (Cardinal)
on Nov 30, 2014 at 07:01 UTC ( [id://1108767]=note: print w/replies, xml ) Need Help??


in reply to Re: List::BinarySearch and conditional tests with Test::More
in thread List::BinarySearch and conditional tests with Test::More

That should be...

$index = &List::BinarySearch::binsearch( sub {$a <=> $b}, 300, \@num_array, );

The difference from your original suggestion is that one should pass the array by reference.

Q: Why would the crazy author want the array parameter to be passed by reference? Doesn't he know this can be inconvenient? :) A: Because passing a list is an O(n) operation, whereas passing a reference is O(1). We wouldn't want the passing of parameters to have an order of growth that is worse than the order of growth of the underlying algorithm.

Of course you already know this, but it's worth mentioning in general.


Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-24 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found