Professional Documents
Culture Documents
Searching
Searching
Sequential Search
O (n)
2
Sequential Search
int SeqSearch(int x[ ], int n, int item)
{
for(i=0;i<n;i++)
{
if(x[i]==item)
return 1;
else
return 0;
}
return 0;
}
It is known that
3 6 7 11 32 33 53
Binary Search
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 -20
Binary Search: Example
Table : Values of low, high and middle and the number of comparisons
for search item 89