Computers are often used for large data storage of records like databases. Searching a record from billions of records and fetching it from file system is a time critical task. Time taken to find a random record decides the performance of the search algorithms. Several search algorithms have been invented to reduce this search time.
Linear search is a basic form of search. It basically iterates through all the records in the table and stopped when it found the desired record.
Example: Say we have n records record;
record_t * linear search(int id)
for(i = 0; i < n; i++)
if(record[i].id == id)
- It is very easy to implement. Thus code complexity is low.
- This method is very useful and efficient when dealing with small number of records.
- When the number of the records grows it becomes very slow as the O(n).
- This method cannot be used in large records.
int linear_search(int low_indx, int high_indx,
int record, int record_val)
for(index = low_indx; index < high_indx; index++)
printf("Iteration %d \n",index);
if(record[index] == record_val)
int main(int argc, char *argv)
int records =
0, 3, 6, 7, 8, 9, 10, 13, 14, 16,
19, 20, 25, 27, 29, 31, 32, 38, 40, 41
int record_index, record;
record_index = linear_search(0, 20, records, record);
if(record_index == -1)
printf("Record not found!");
printf("Record index %d", record_index);
Rate this topic.
Help us to improve this topic. Your feedback is essential to us. Please suggest your remarks, ratings and corrections regarding the above section. Please fill the form and submit. If your suggestion contains graphics/formatted text/word document, please attach file(s).
Note: Only members are allowed, * fields are mandatory.