Using C++

Aim : Implementation of recursive and non-recursive functions to perform the following searching operations for a key value in a given list of integers: i) Linear search ii) Binary search.

Theory

📌 Searching Techniques

🔹 (i) Linear Search

Linear search is a simple searching algorithm that sequentially checks each element in the list until the desired element (key) is found or the list ends.

📌 Working of Linear Search

📌 Time Complexity:

🔹 (ii) Binary Search

Binary search is a more efficient searching algorithm that works on sorted arrays. It repeatedly divides the search space into halves until the key is found or the search space becomes empty.

📌 Working of Binary Search

📌 Time Complexity:

Search Type Iterative (Non-Recursive) Recursive
Linear Search Uses a loop to check elements sequentially. Calls itself recursively for each index.
Binary Search Uses a loop to repeatedly divide the array. Calls itself recursively with a new range.
Memory Usage Lower (no extra function calls). Higher (due to recursive function stack).
Performance Efficient for small datasets. More readable but uses extra memory.
Program 1 :
Program 2 :

Conclusion : Hence we have performed our practical successfully