Question: Input: A sequence of n numbers A = (a1, a2, , an) and a value v. Output: An index i such that v = A[i]

Input: A sequence of n numbers A = (a1, a2, , an) and a value v. Output: An index i such that v = A[i] or the special value NIL if v does not appear in A

a) (10 points) Write the pseudo code for a linear search. The linear search scans through a sequence looking for v. (Assume that indexing starts at 1 since the book uses this in its discussions of lists and sequences.) b) (10 points for loop invariant; 5 points for each property) Using a loop invariant, prove that your algorithm is correct. Make sure that your loop invariant fulfills the three necessary properties. (Be sure to discuss all three properties.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!