Binary search, MATLAB in Engineering

Binary Search:

The binary search supposes that the vector has been sorted first. The algorithm is just similar to the way it works whenever looking for a name in a phone directory (that is sorted in alphabetic order). To find the value of a key, look at the element in the middle.

  • If that is the key, then the index has been found.
  • When it is not the key, decide whether to search the elements before or after this place and adjust the range of values in which the search occurs and begin this process again.

To implement this, we will use variables low and high to identify the range of values in which to search. To start, the value of low will be 1, and the value of high will become the length of the vector. The variable mid be the index of the element in the middle of the range from low to high. When the key is not found at mid, then there are two possible way to adjust the range. When the key is less than the value at mid, we change high to mid - 1. When the key is greater than the value at mid, then we change low to mid 1.

 

Posted Date: 10/22/2012 7:58:38 AM | Location : United States







Related Discussions:- Binary search, Assignment Help, Ask Question on Binary search, Get Answer, Expert's Help, Binary search Discussions

Write discussion on Binary search
Your posts are moderated
Related Questions
How can I use the weighted moving average formula in matlab to smooth a column data of 404 values?

calcrectarea subfunction: function call: area = calcrectarea(len,wid); function header: function area = calcrectarea(len, wid)   In the function call, the two arg

Function cirarea - Anonymous functions: The function handle name is cirarea. The one argument is passed to the input argument radius. The body of the function is an expression

Use of Nested if-else statements: By using the nested if-else to select from among the three possibilities, not all the conditions should be tested. In this situation, if x is

Image Processing: The Images are represented as grids, or matrices, of picture elements (known as pixels). In MATLAB an image usually is represented as a matrix in which each

For Loops which do not use an iterator Variable in the action: In all the illustrations that we seen so far, the value of the loop variable has been used in same way in the ac

Function fieldnames - structure functions: The function fieldnames will return the names of the fields which are contained in the structure variable. >> pack_fields = fiel

Set Operations: The MATLAB has numerous built-in functions which perform set operations on vectors. These involve intersect, union, setdiff, unique, and setxor. All these func

Creating Cell arrays: There are many ways to create cell arrays. For illustration, we will create a cell array in which one element will store an integer, one element store ch

I have a vector of X, one for Y , one for x-direction velocity U and one for y-direction velocity V. they are at same size. How can I plot streamline of that flow? I follow all exa