Binary Search Using Recursion

Recall from Chapter 11, “Arrays Part II: Multidimensional Arrays. Searching and Sorting Arrays,” how we used the binary search technique to locate a number in a sorted array of numbers. The implementation in Chapter 11 made use of iteration. In this section, we will use the same basic ideas of binary search, but this time implemented with a recursive method. Because the underlying ideas are the same whether we use iteration or recursion, you might want to revisit the binary search section in Chapter 11 before beginning the recursion example described next.

The binary search technique can be viewed as a series of searches where each search is a smaller version of the previous search. Each search can briefly be described ...

Get C# Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.