Binary Search Algorithm Using Recursion in Python with source code 2021

preview_player
Показать описание
Binary Search Algorithm Using Recursion in Python
Steps involve:

step 1: compare x with a middle term
step 2: if x matches with the middle term, we return the mid index
step 3: else if x is greater than the mid-term, then x can only lie in the right (greater) half subarray after the mid-term. then we apply the algorithm again for the right half
step4: else if x is smaller, the largest x must lie in the left (lower) half. so we apply the algorithm for the left half.

Time complexity
Worst complexity: O( log n )
Best complexity: O( 1 )

Рекомендации по теме
join shbcf.ru