# Linear Search in Netbeans Java with Source Code

# Linear search

As you know that the process of looking for something is called searching. The** linear search** is also one of the method of searching the data in a certain place. This is the simplest form of searching any data. We search an element or value in a given array by traversing the array from the starting, till the desired element or value is found. In the searching the first value is checked with the value you want to find and if the first value is the value you want to find then it will return -1 but if it didn’t find the value in the first index then it will continue checking the value one by one with the given values in the array. It is also called sequential searching. It can be applied on both sorted and unsorted array.

The difference between the binary and linear array is that, the linear search is used to search in one by one order of searching. It can be slow method if the array or the value are large. It is not good for large projects. The time complexity of linear search is O(n). It also consume more time if the array is huge.

Pseudo code

Search(A,n,x)

{

For(i<0 to n-1)

If A[i]==x

Return i

Return -1

}

### Steps of operations

As seen in the above pseudo code, first of all an array should be created. the variable should be created (n,x). then for look is created which is activated when i is less than 0 to n -1. then it checks it array i is equal to x or not. If it is equal to i then it return the index of the certain value if it is not equal then it repeats the for look until the array is finished or 0. if it didn’t find any number in the array then it will return -1 value.

## Result output

You can download the Source Code for this project by clicking the download button below:

`Download`