Join the social network of Tech Nerds, increase skill rank, get work, manage projects...

• # Implement Binary Search Using C

• 0
• 0
• 0
• 0
• 0
• 0
• 0
• 0
• 169
Comment on it

Binary Search:- The Binary Search is one of the most important searching technique in Searching Algorithm. The one of property of this searching algorithm is, all the elements are in sorted order in array. The worst case and average case complexity of this algo is O(log n) and gives O(1) in best case.

This algorithm is based on divide and conquer approach.firstly we define the lower and upper bound of array This algo first find the middle element in the array. if searching element is less than the mid(middle) element it set mid+1 element to up(upper bound) and if searching element is greater than the mid(middle) element it set mid-1 element to lw(lower bound). If the mid(middle) element is equal to searching element the element is found.

Worst Case:- This indicate that the searching element is found at last position or first position in the array.

Best Case:- This indicate that the searching element is found at the middle in the array at first division(lw+up/2).

```#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,se=0,n,s,e[1000],lw=0,mid=0,up=0;
clrscr();
printf("Enter the size of an Array:=");
scanf("%d",&s);

printf("Enter the Element of an Array\n");
for(i=0;i<s;i++)
{
scanf("\n%d",&e[i]);
}
printf("Enter the Number You Want to Search:=");
scanf("%d",&se);
up=s-1;

while(lw<=up)
{
mid=(lw+up)/2;
printf("%d",mid);

if(se>e[mid])
{
lw=mid+1;
}
if(se<e[mid])
{
up=mid-1;
}
if(se==e[mid])
{
printf("%d is found at position %d",se,mid+1);
break;
}
if(lw>up)
{
printf("%d is not found",se);
}
}
getch();
}
```

## 0 Comment(s)

Sign In
OR
OR
Register

Sign up using

OR
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password:

• Hire
• Post Projects

### Post Projects

• All at 0 Cost ....
• Post Tech Job
• Select Best Bidder
• Track the Project
• Approve Work and Pay safely
• Browse Nerds
• Work
• Find Projects Find Projects
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
• Business
• Manage
• Company Company

### Manage Company

• All at 0 Cost ....
• Manage Company and Employee Profiles
• Use Online Project Management Tools for Free
• Company wide Employee Productivity Reports
• Knowledge Sharing and Collaboration Tools
• Get Sales Lead and Bid for Tech Projects
• Send Invoices and Receive Payment Safely
• Learn
• Nerd Digest Nerd Digest
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
• Business
• Tech Q & A Tech Q & A
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
• Business
• Record & Share

### Desktop Recording Tool

• All at 0 Cost ....
• Online tool for Recording Desktop Activity and Audio
• Store and Share from the Cloud
• Creating Software Product Demos
• Creating video tutorials
• Recording and Reporting Software and Project issues as videos
• Ask Tech Query
• Post Blogs