Searching algorithms are one of the main categories of algorithms in Computer Science which are studied by novice programmers and students as a preparation for their journeys ahead to become skilled programmers. This post contains a short yet, a composite description on Binary Search algorithm and an implementation written using JavaScript language. Let’s just start! Happy learning :). Binary Search is one of the most popular searching algorithms. It is easy to grasp the knowledge on this algorithm intuitively. It is a divide-and-conquer algorithm, that divides the input array roughly in half every time it checks whether an element of the array is the one, we’re looking for. Binary search has a complexity of O(log n) in the worst case and O(1) in the best case. Note: The input for a binary search algorithm should be a sorted list. Below is an iterative approach to implement a binary search in JavaScript. function binarySearch (sortedArray, key) { let high = sortedArray.length-1 le...
A blog that help learn front-end development, data structures and algorithms.