CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
3
You visited us 3 times! Enjoying our articles? Unlock Full Access!
Question

If the binary search algorithm determines that the search arguments is in the upper half of the array, which of the following statements will set the appropriate variable to the appropriate value ?

A
start sub = middle sub - 1
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
B
start sub = middle sub + 1
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
stop sub = middle sub -1
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
stop sub = middle sub +1
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is A start sub = middle sub - 1

If the binary search algorithm determines that the search arguments is in the upper half of the array, start sub = middle sub - 1 statements will set the appropriate variable to the appropriate value.

Binary search is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the array. If they are not equal, the half in which the target cannot lie is eliminated and the search continues on the remaining half, again taking the middle element to compare to the target value, and repeating this until the target value is found. If the search ends with the remaining half being empty, the target is not in the array.


flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon