April 2018
Beginner to intermediate
426 pages
10h 19m
English
In Chapter 13, Sorting and Searching Algorithms, we learned how to implement the binary using an iterative approach. If we go back and take a look at the algorithm, we can use the divide and conquer approach to implement the binary search as well. The logic is the following:
The divide and conquer binary search algorithm is the following:
function binarySearchRecursive( array, value, low, high, compareFn = defaultCompare) { if (low <= high) { const mid = Math.floor((low + high) / 2); const element = array[mid]; if (compareFn(element, value) ...