Question
The searching technique in Problem 2 is called as Sequential Search or Linear Search. It works well for small or unsorted arrays. However, for large
The searching technique in Problem 2 is called as Sequential Search or Linear Search. It works well for small or unsorted arrays. However, for large arrays linear searching is inefficient especially if the array is sorted. For this we use a different searching technique to find a number. This search algorithm considers a sorted array. The algorithm locates the middle element of the array and compares it to the search key. If theyre equal, the search key is found and the array subscript of that element is returned. If theyre not equal, the problem is reduced to searching onehalf of the array. If the search key is less than the middle element of the array, the first half of the array is searched, otherwise the second half is searched. If the search key is not found in the specified subarray (piece of the original array), the algorithm is repeated on one-quarter of the original array. The search continues until the search key is equal to the middle element of a subarray, or until the subarray consists of one element thats not equal to the search key (i.e., the search key is not found). Write a program to find whether a given number is present using a sorted array using the searching technique as mentioned above.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started