Computer Science, asked by renumittalia3582, 1 year ago

A programmer writes a program to find an element in the array A[5] with the elements:8 30 40 45 70 the program is run to find a number X,that is found in the first iteration of binary search.what is the value of X?

Answers

Answered by Daada20
108
Binary Search is performed on a sorted array.

For each iteration,

1. It first finds the mid element's value.

2. Comparison of X and mid values.
If value(X) = value(mid) then
You've found the number. EXIT.
If value(X) > value(mid) then
Perform Binary Search on second half of array.
If value(X) < value(mid) then
Perform Binary Search on first half of array.

The answer is 40.
Similar questions