Re: Potential binary search optimization or feature
| From: | Stanislav Malyshev | Date: | Wed, 01 Apr 2015 07:53:57 +0000 |
| Subject: | Re: Potential binary search optimization or feature | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-85628@lists.php.net to get a copy of this message | ||
Hi!
> to utilize a binary search algorithm. Since the requirement for a binary
> search is that the array being searched is sorted, I thought is would be a
> good idea to have a Boolean parameter in the binary search function to
> specify if the input array should be sorted or not. something among the
Sorting array takes at least O(n*log n) (well, with comparison sort, but
that's what you'd have to use I assume), while linear search can be done
in O(n). So no profit here.
If you *know* the array is sorted, binary search function could be
useful, but I'm not sure how wide the use case for it would be.
> lines of "function binary_search(string target, array arrayToSearch, bool
> sort)". Doing this, the function can preform a sort if required to, thus
> not needing to sort a array that is already sorted.
Array function's name would have to start with array_ prefix.
--
Stas Malyshev
smalyshev@gmail.com