fastsearch
Find the value (wert) in the in ascending order sorted array (array) with
fastsearch-algorithm.
function index = fastsearch (array, von, bis, wert, bias)
Input
array: array to search in
von: lower border of the search region, should be set to 1.
bis: higher border of the search region, should be set to
length(array). These variables cannot be initialize within the
function because of the recursion.
wert: element to search for
bias: 0: search exact the element
+1: search the element or the next greater
-1: search the element or the next smaller
Output
index: index of the element in array;
-1 if not found
The algorithm is very quick, check the time below:
--------------------
>> a=rand(1,10^7);
b=sort(a);
tic;c=fastsearch(b,1,length(b),b(123456),1);toc
Elapsed time is 0.000795 seconds.
>> c
c =
123456
--------------------
>> tic;c=fastsearch(b,1,length(b),0.16234,-1);toc
Elapsed time is 0.014674 seconds.
>> 0.16234-b(c)
ans =
7.6316e-008
>> 0.16234-b(c+1)
ans =
-7.0494e-008
Cite As
Valentin Kuklin (2026). fastsearch (https://www.mathworks.com/matlabcentral/fileexchange/16976-fastsearch), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
