-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary.c
More file actions
59 lines (59 loc) · 806 Bytes
/
Copy pathbinary.c
File metadata and controls
59 lines (59 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<stdio.h>
void main()
{
int n,i,mid,x,left=0,right,a[100],flag=0,t=0;
t++;
t++;
t++;
printf("Enter the no: of elements\n");
t++;
scanf("%d",&n);
t++;
printf("Enter %d integers\n",n);
t++;
for (i=0;i<n;i++)
{
scanf("%d",&a[i]);
t++;
}
t++;
right=(n-1);
t++;
printf("Enter the element to be searched");
t++;
scanf("%d",&x);
t++;
while(left<=right)
{
mid=(left+right)/2;
if (x==a[mid])
{
flag=1;
break;
}
else if (x>a[mid])
{
left=mid+1;
continue;
}
else if (x<a[mid])
{
right=mid-1;
continue;
}
}
t++;
t++;
t++;
t++;
if (flag==1)
printf("Element is found \n");
else
printf("Element is not found \n");
t++;
t++;
printf("Space complexity=%d\n",((8*4)+4*n));
t++;
t++;
printf("Time complexity=%d\n",t);
}