Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. function binary_search, arguments: array, length, value, returns: int
  2. Begin_function
  3. Set first_index to 0
  4. Set last_index to length - 1
  5. While first_index is less than or equal to last_index
  6. Begin_while
  7. Calculate middle_index as (last_index + first_index) / 2
  8. If value is less than array[middle_index]
  9. Set last_index to middle - 1
  10. If value is more than array[middle_index]
  11. Set first_index to middle + 1
  12. Else
  13. Return middle_index
  14. End_while
  15. Return -1
  16. End_function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement