Illustrations of sequential search, MATLAB in Statistics

Illustrations of Sequential search:

The two illustrations of calling such function is as shown below:

>> values = [85 70 100 95 80 91];

>> key = 95;

>> seqsearch(values, key)

ans =

    4

>> seqsearch(values, 77)

ans =

    0

This illustration supposes that the key is found only in one element in the vector. Also, however it works; it is not a very efficient algorithm. When the vector is large, and the key is found in the starting, this still loops through the rest of the vector. The improved version would loop until the key is found or the whole vector has been searched. In another words, a while loop is used instead of a for loop; there are two sections to the condition.

46_Illustrations of Sequential search.png

Posted Date: 10/22/2012 7:57:51 AM | Location : United States







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

Write discussion on Illustrations of sequential search
Your posts are moderated
Related Questions
Advanced File Input and Output: In that section, we saw how to read the values entered by user using the input as well as the output functions disp and fprintf, that shows inf

Nested Structures: The nested structure is a structure in which at least one of the members is itself a structure. For illustration, a structure for the line segment may co

Help function: Function is computing the two values, there are two output arguments in the function header (i.e., area & circum), that are placed in the square brackets [ ]. A

Program of Persistent variables: The program below elaborates this. The script calls a function func1 that initializes a variable count to 0, then increment it, and print the

Illustration of Customizing plots: Illustration, the bar and barh functions by the default place a width of 0.8 between bars. Whenever called as bar(x,y), the width of 0.8 is

Execution of persistent variables: The functions can also be called from the script or from the Command Window, as shown here. For illustration, the functions are called first

Vectorizing: In most of the cases in MATLAB, loops are not essential. As MATLAB is written specifically to work with the vectors and matrices, most operations can be completed

Nested for Loops: The action of a loop can be any of the valid statement(s). Whenever the action of a loop is the other loop, this is known as nested loop. As an illustrati

Reading from Files: There are many lower level functions which read from files. The function fscanf reads the formatted data into a matrix, by using conversion formats like %s

Illustration of reading from files: For illustration, suppose that there is a data file 'subjexp.dat' that has on each line a number followed by thecharacter code. The type fu