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
smalys...@gmail.com

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to