Linear Search:- Linear Search are also called as sequential Search,in this technique we search the data items from structured data base in ...
Linear Search:-Linear Search are also called as sequential Search,in this technique we search the data items from structured data base in a linear way.
Linear way means one after another.This method considered as simple when we compared this to binary search.This technique is used in c,c++,java,c# etc.
Complexity of Linear Search is o(n).
Program/algorithm/Example of Linear Searching:-
Linear way means one after another.This method considered as simple when we compared this to binary search.This technique is used in c,c++,java,c# etc.
Complexity of Linear Search is o(n).
Program/algorithm/Example of Linear Searching:-
#include<iostream.h>
#include<conio.h>
void main()
{
int a[30],i,j,k,x,n,flag;
cout<<"Enter Size"
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
flag=0;
cout<<"Enter element to search";
cin>>x;
for(i=0;i<n;i++)
{
if(a[i]==x)
{
flag=1;
break;
}
}
if(flag==1)
cout<<"Element Found";
else
cout<<"Not Found";
}
If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.
COMMENTS