linear search is not the most efficient way to


Linear search is not the most efficient way to search an item within a collection of items. Though, it is extremely simple to implement. Furthermore, if the array elements are arranged into random order, it is the merely a reasonable way to search. Additionally, efficiency becomes significant only in large arrays; if the array is small, there aren't various elements to search and the amount of time it takes is not even noticed by the user. Therefore, for several conditions, linear search is a perfectly valid approach.

Before learning Linear Search, let us described some terms associated to search.

A file is a set of records and a record is in turn a collection of fields. A field, that is utilized to differentiate among several records, is known as a 'key'.

For instance, the telephone directory that we discussed in earlier section can be assumed as a file, where each record contains two fields: name of the person & phone number of the person.

Now, it depends on the application whose field will be the 'key'. It can be the name of person (usual case) and it can also be phone number. We will situate any particular record by matching the input argument 'a' with the key value.

The simplest of all the searching techniques is Linear or Sequential Search. As the name suggests, all the records in a file are searched sequentially, one by one, for the matching of key value, till a match occurs.

The Linear Search is applicable to a table which it should be organised in an array. Let us assume that a file contains 'n' records and a record has 'a' fields but only one key. The values of key are organised in an array say 'm'. As the file has 'n' records, the size of array will be 'n' and value at position R(i) will be the key of record at position i. Also, let us assume that 'el' is the value for which search has to be made or it is the search argument.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: linear search is not the most efficient way to
Reference No:- TGS0264335

Expected delivery within 24 Hours