in reply to Binary searching with Perl.
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Binary searching with Perl.
by Abigail-II (Bishop) on May 24, 2003 at 11:47 UTC | |
by Anonymous Monk on May 24, 2003 at 13:45 UTC | |
|
Re: Re: Binary searching with Perl.
by zby (Vicar) on May 26, 2003 at 08:03 UTC |