Implementation of binary search, MATLAB in Engineering

Assignment Help:

Implementation of binary search:

The binary search can be implemented as a recursive function. The recursive function below also implements this binary search algorithm. It receives four arguments: a sorted vector, and a key to search for, and the values of low and high (which, to start, will be 1 and the length of the vector). It will return -1 when the key is not in the vector, or the index of element in which it is found. The base cases in the algorithm are if low > high, that means the key is not in the vector, or whenever it is found. Or else, the common case I to adjust the range and call the binary search function again.

1764_Implementation of binary search.png

The illustrations of calling this function is shown here:

>> recbinsearch(svec, 5,1,length(svec))

ans =

    3

>> recbinsearch(svec, 25,1,length(svec))

ans =

    7

>> recbinsearch(svec, 4,1,length(svec))

ans =

    -1


Related Discussions:- Implementation of binary search

Related structure functions, Related Structure Functions: There are ma...

Related Structure Functions: There are many functions which can be used with structures in a MATLAB. The function isstruct will return 1 for logical true when the variable arg

Sound files, Sound Files: The sound signal is an illustration of a con...

Sound Files: The sound signal is an illustration of a continuous signal which is sampled to result in a discrete signal. In this situation, sound waves traveling through the a

Illustration of sorting strings, Illustration of Sorting strings: To s...

Illustration of Sorting strings: To sort on the rows rather than second dimension should be specified. >> sort(words,2) ans = Hello Hdowy Hi Gbdeo

Illustration of initializing the data structure, Illustration of initializi...

Illustration of initializing the data structure: illustration of initializing the data structure by preallocating is here as shown: >> cyls(3) = struct('code', 'c', 'dimen

Illustration of vectors of structures, Illustration of Vectors of structure...

Illustration of Vectors of structures: In this illustration, the packages are vector which has three elements. It is shown as a column vector. Each and every element is a stru

Str2num function - string, str2num function - String: The function str2...

str2num function - String: The function str2num does the opposite; it takes the string in which a number is stored and converts it to the type double: >> num = str2num('123.

Function cellplot - cell array, Function cellplot - Cell array: The fu...

Function cellplot - Cell array: The function cellplot place a graphical display of the cell array in a figure Window; though, it is a high-level view and fundamentally just di

Interchange rows - gauss-jordan elimination, Interchange rows : for illust...

Interchange rows : for illustration interchanging rows ri and rj is written as

Replacement - gauss-jordan elimination, Replacement : Replace a row b...

Replacement : Replace a row by adding it to (or subtract from it) a multiple of the other row. For a given row ri, this is written as   ri  - srj →  ri Note that when r

Frd to ss, I have a frequency response data. How do I convert that to state...

I have a frequency response data. How do I convert that to state space? I am given a 6 row and 3 column data (steady state). How do i convert that to state space model?

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd