Showing posts with label Searching. Show all posts
Showing posts with label Searching. Show all posts

Monday, 21 January 2013

Binary Search


Binary Search:-Binary Search is a searching technique which is used to locate items in ordered list of particular number.This technique is used in c,c++,java,c# etc.

Complexity of Binary Search is o(logn).

Binary Search Example and Algorithm:-

#include<iostream.h>
#include<conio.h>
void main()
{
int a[30],i,j,x,n,a,l,f,flag;
cout<<"Enter Size";
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
flag=0;
cout<<"Enter Element to be Search";
cin>>x;
l=n-1;
f=0;
while(f<=l)
{
m=(f+l)/2;
if(a[m]==x)
{
flag=1;
break;
}
if(x>a[m])
{
f=m+1;
else
l=m-1;
}
if(flag==1)
cout<<"Element Found"<<m;
else
cout<<"NOT FOUND";
getch();
}


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

Linear Search


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:-


#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.

Searching(Computer Science)


Searching is a technique which is widely used in c,c++,java,c# and many other programming languages.We can search anything like files,folder,page,documents etc or in simple words we can search particular data item in a structured data base like dictionary.

Searching Technique is divide into 3 parts:-

1)Linear Search.
2)Binary Search.
3)Indexed Search.

1)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.


#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++)
.
.
.
For More Click Here


2)Binary Search:-Binary Search is a searching technique which is used to locate items in ordered list of particular number.

3)Indexed Searching:-Index searching is technique which improve the efficiency of search items.In index searching the file is divided into blocks and keys.




If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.