Binary Search Exercise


Write a Binary Search algorithm!


The function you write should accept two parameters: 1) an array and 2) the value to find.
The function should return the index of the found value, or -1 if not found.

  1. Pair up!
  2. Write pseudocode for this problem! Improve on the steps from the Binary Search: Steps slide.
    Can you get those steps as close to actual code as possible?
  3. Walk through your pseudocode together with your partner using an example/ test case, to make sure each step is doing exactly what you think it should.
  4. Now turn your pseudocode into code! You can use any environment you want to run and test code.
    If you would like premade test cases in Javascript, feel free to fork this repl.

Stumped? Click here for some hints.