Examlex

Solved

Here Is the Code for a Recursive Method for Binary

question 3

Essay

Here is the code for a recursive method for binary search that is searching a sorted array of ints. The array is assumed to be sorted in ascending order.
// we are looking for the value stored in the parameter key
public static int binarySearch ( int [ ] arr, int key, int start,
int end )
{
System.out.println( "Start = " + start + "; end = " + end );
if ( start <= end )
{
int middle = ( start + end ) / 2;
if ( arr[middle] == key ) // found it at index middle
return middle;
else if ( arr[middle] > key ) // look left
return binarySearch( arr, key, start, middle - 1 );
else // look right
return binarySearch( arr, key, middle + 1, end );
}
else // not found
return -1;
}
We are running the following code:
int [ ] numbers = { 4, 6, 8, 10, 11, 12, 14, 16, 18 };
int found = binarySearch( numbers, 10, 0, 8 );
What is the output? Show what the output statement in the binarySearch method outputs. The question is not about the value of found; the value of found is 3.


Definitions:

Oogenesis

The process in which ova (egg cells) are produced in the ovaries of female organisms, undergoing several stages of cell division and maturation.

Ovary

The ovary is a female reproductive organ in which ova or eggs are produced, along with the secretion of hormones such as estrogen and progesterone.

Uterine Tube

Also known as the fallopian tube, it is part of the female reproductive system that connects the ovaries to the uterus.

Uterus

A major female hormone-responsive reproductive sex organ of most mammals, including humans, responsible for gestating embryos and fetuses.

Related Questions