Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function binary_search, arguments: array, length, value, returns: int
- Begin_function
- Set first_index to 0
- Set last_index to length - 1
- While first_index is less than or equal to last_index
- Begin_while
- Calculate middle_index as (last_index + first_index) / 2
- If value is less than array[middle_index]
- Set last_index to middle - 1
- If value is more than array[middle_index]
- Set first_index to middle + 1
- Else
- Return middle_index
- End_while
- Return -1
- End_function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement