C Program For Binary Search using Recursion
Learn How To Find an Element in 1-Dimensional Array using Binary Search using Recursion in C Programming Language. It is important that we should know How A For Loop Works before getting further with the C Program Code.
Note: The prerequisite for Binary Search is the Elements in the Array must be in Sorted Order.
Recursive Binary Search Algorithm Analysis
The worst case scenario of Binary Searching is when the element is not present in the Array. The best case of this algorithm is when the element to be searched is present at the middle position in the Array. The Runtime complexity of Binary Search Algorithm using Recursion is O(log n). The Binary Search Algorithm is preferred only when the data is static. Binary Search is not suitable to be implemented in Linked Lists as direct access is not allowed in Linked Lists.
Must Read: C Program For Binary Search using Functions
C Program For Binary Search using Recursion Method
int RecursiveBinarySearching(int arr, int low, int high, int element)
if(low > high)
middle = (low + high) / 2;
if(element > arr[middle])
RecursiveBinarySearching(arr, middle + 1, high, element);
else if(element < arr[middle])
RecursiveBinarySearching(arr, low, middle - 1, element);
int count, element, limit, arr, position;
printf("\nEnter the Limit of Elements in Array:\t");
printf("\nEnter %d Elements in Array: \n", limit);
for(count = 0; count < limit; count++)
printf("\nEnter Element To Search:\t");
position = RecursiveBinarySearching(arr, 0, limit - 1, element);
if(position == -1)
printf("\nElement %d Not Found\n", element);
printf("\nElement %d Found at Position %d\n", element, position + 1);
In case you get any Compilation Errors with this C Program To Search Array Element using Binary Search using Recursion or if you have any doubts about it, let us know about it in the Comment Section below.