Question: Hello. I need a little help with this problem that has to do with the topic Linear Search. I think I understand the first question,
Hello. I need a little help with this problem that has to do with the topic Linear Search. I think I understand the first question, but not positive. Would someone be kind enough to help me check the first (a) part, and maybe help me solve the second (b) part? If you could please provide an explanation, as well, I would greatly appreciate it, so that I can understand what it is that I'm doing. Thanks so much for your help!
(a) Show the pseudocode for Linear Search that you will be analyzing. Give each line a number for reference in your analysis.
Will a code like this one work? Is this what it's asking for? If not, could you help me correct this, and explain what I did wrong?
(b) Using a loop invariant, prove that your algorithm is correct. Make sure that your loop invariant fulfills the three necessary properties (initialization, maintenance, termination).
(Hint: The loop can exit for two reasons. Use a simpler variant that deals with only the correctness of the after-exit returned value, as it would be too complex to cover both, and the within-loop returned value is easy to show correct.)
linearSearchCode(Array,m,x) I. for i = 0 to m 2 3 4 return nil if Array[i]-x return
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
