Question
[C] Recall Binary Search: Input: a list of n sorted integer values and a target value Output : True if target value exists in list
[C]
Recall Binary Search:
Input: a list of n sorted integer values and a target value
Output: True if target value exists in list and location of target value, false otherwise
Method:
Set left to 1 and right to n
Set found to false
Set targetindex to -1
While found is false and left is less than or equal to right
Set mid to midpoint between left and right
If target = item at mid then set found to true and set targetindex to mid
If target < item then set right to mid 1
If target > item then set to left to mid + 1
Return the targetindex
Write a C function called binary_search().
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started