Question: Below is an improved version of sequential search where we append the search key to the end of the list. This way, the search
Below is an improved version of sequential search where we append the search key to the end of the list. This way, the search for the key will have to be successful, and therefore we can eliminate the end of the list check altogether. Use this algorithm to answer the questions that follow. 1: ALGORITHM SequentialSearch2(A[0..n-1], K) 2: 3: 4: 5: 6: // Searches for K in A sequentially using K as a sentinel // Input: An array A[0..n-1] and an element K // Output: The index of the first element in A that matches K or -1 if there is no match // A[n]+K i-0 while A[i] # K do 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: end ALGORITHM a. (5 points) What is the problem size (input) of this algorithm? C. i + i +1 end while if i = n then return -1 else return i end if b. (5 points) What is the basic operation? (5 points) What would be the number of basic operations performed using worst-case? Activa Go to Se
Step by Step Solution
There are 3 Steps involved in it
The presented algorithm is an improved version of the sequential search which incorporates the usage ... View full answer
Get step-by-step solutions from verified subject matter experts
