Noting that this is a learning exercise and "use a hash" advice is unhelpful.
A binary search only becomes more efficient than a linear search, if the data is already sorted, or if you can sort once and amortise the cost of that sort over many, many searches.
If the data being search is static within the context of the program, then you should ensure that the program receives that data pre-sorted. If the data is dynamically aquired (gets added to) during the life of the program, then you should maintain the data in it sorted state.
Maintaining dynamic datasets in an order state means using either a binary search and insert on a linked list or maintaining the data as a binary tree
In reply to Re: Binary searching with Perl.
by Anonymous Monk
in thread Binary searching with Perl.
by DigitalKitty
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |