# Linear Search

Searching: In the data structure, searching is the process in which an element is searched in a list that satisfies one or more than one condition.

### Types of searching

There are two types of searching in the data structure.

1. Linear searching
2. Binary searching

### Linear searching

In this searching technique, the searching element is compared one by one with each element of the list until the element is found. It is also called sequential searching.

In this, the searching element is compared with the first element of the list. If both the elements are the same, it returns the index value of that element. Otherwise, it returns -1. Similarly, the entire list is compared until the searching element is found. If the element is not found even after comparing the entire list, the searching prints "unsuccessful" message.

It is a very simple searching technique, but it takes a lot of time because the average-case complexity of the linear search is O (n).

### Algorithm of Linear searching

For example, suppose you have the following array, and you have to search 30 in it.

### Linear search program in C language

```#include<stdio.h>
void main ()   {
int a[10] = {15, 13, 40, 51, 32, 80, 14, 13, 57, 19};
int element, i, flag;
printf("\n enter the searching element \n");
scanf("%d",&element);
for (i = 0; i< 10; i++)
{
if(a[i] == element)
{
flag = i+1;               break;

}
else
flag = 0;
}
if(flag != 0)
{
printf("\n element found and index value is %d\n",flag);
}
else
{
printf("\n element not found\n");
}
}     ```

### Output

```enter the searching element
40
element found and index value is 2```