C Program for Recursive Binary & Linear Search

C program for Recursive Binary & Linear Search

Here you will get and learn the program for recursive binary & linear search using C programming language.

 

How to Program for Recursive Binary & Linear Search

Recursive Binary Search and Recursive Linear Search are two different algorithms used for searching elements within a sorted list or array.

 

Recursive Binary Search

Binary search is a divide-and-conquer algorithm that works by repeatedly dividing the search interval in half. It compares the target value to the middle array element. The search is complete after the target value matches the middle element.
If the target value is smaller than the middle element, the search moves to the array’s lower half. If the target value is higher, the search will continue on the upper half. This operation is performed recursively until the target value is discovered or the search interval is empty.

Program for Recursive Binary & Linear Search

Image Source

Recursive Binary Search Program in C

Output 1

Enter 7 Numbers to input : 10 20 30 50 40 80 70
Enter Number To Search : 30

Element is present at index 2

 

Output 2

Enter 7 Numbers to input : 10 20 30 50 40 80 70
Enter Number To Search : 35

Element is not present in array

 


 

 

Recursive Linear Search

Linear search is a simple search algorithm that sequentially checks each element of the list until it finds the target value or reaches the end of the list. Recursive linear search applies the same logic but in a recursive manner.

 

Recursive Linear Search Program in C

Output 1

Enter 7 Numbers to input : 1 2 3 4 5 6 7
Enter Number To Search : 5

Element 5 is present at index 4

 

Output 2

Enter 7 Numbers to input : 1 2 3 4 5 6 7
Enter Number To Search : 9

Element 9 is not present in the array

 


 

Read Also

Heap Sort

Merge Sort

Selection Sort

Insertion Sort

 

 

Check out our DAA Lab Manual and Programs

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top