Binary search can be used to efficiently search for an element in a sorted list. This is an example of recursive approach written in Python 2.7.


Step -1: The program starts by looking at the middle element of the ordered list. If that is the element we are looking for (let’s call it target_element) , the program returns ‘True’
Step – 2: If Step-1 fails, we check if the target_element is smaller than the middle element. If yes, we search for the target_element in the left half of the initial list
Step – 3: If Step-2 fails, we search for the target_element in the right half of the initial list

This program takes as input a string of space separated sorted integers in ascending order and the target_element that is to be searched for in the list.

Returns ‘True’ if the target_element is present in the list, else returns ‘False’

Tracing the process:
In-order to trace the control flow, the program can be executed as follows:
python -m trace –trace