Medium
We have a table and we want to know if the value 42 is there. For this, we have the following code:
function findNum(array, 42, start, end)
{
If start > end then
{
display error;
}
Else
{
middle = (start+end)/2;
If array[middle] = 42
{
display ''we found 42'';
}
Else If array[middle]>42
{
findNum(array,42,start,middle-1);
}
Else
{
findNum(array,42, middle+1, end);
}
}
What must be checked for this binary search to work?
Edit
0
Community EvaluationsNo one has reviewed this question yet, be the first!
Similar QuestionsMore questions about Algorithme