egonSchiele / grokking_algorithms

Code for the book Grokking Algorithms (https://amzn.to/29rVyHf)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chapter 3 - Recursive Binary Search - doesn't work if item searched is at mid position

vidyabhandary opened this issue · comments

commented

05_binary_search_recursive.py - fails for cases like these,

[1, 3, 5, 7, 9], target = 5
OR
[77, 95, 101, 255, 309, 570, 600], target = 255

A check needed before calling the method recursively.

if arr[mid] == target:
      return arr[mid]