Skip to content

Latest commit

 

History

History

arrayBinarySearch

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Challenge Summary

  • Search an array for a value without using methods

Challenge Description

  • Write a function called BinarySearch which takes in 2 parameters: a sorted array and the search key. Without utilizing any of the built-in methods available to your language, return the index of the array’s element that is equal to the search key, or -1 if the element does not exist.

Approach & Efficiency

  • Approach
    • Pass array and value into function
    • Declare a direction value
    • Find and declare midpoint
    • Check if the midpoint matches the value
    • Detect direction based on left and right of midpoint
    • While-loop to go in the direction until array end and test for match
    • Test with node and console.log, then unit tests
  • Big 0
    • 0(1) 0(n)

Solution

whiteboard