Pseudocode; Loop Invariant 2. (15 pts) Given a sequence of n numbers A-(a1, a2,
ID: 3743343 • Letter: P
Question
Pseudocode; Loop Invariant
2. (15 pts) Given a sequence of n numbers A-(a1, a2, . . . , an) and a target value v, you are asked to decide if there is an element in A that is greater than v. If there is, the output is an index i such that Ali] > v; otherwise, the output is the special value NIL (a) Write pseudocode for a simple linear "combing" algorithm, which will scan through the input sequence A to decide if there is an element that is greater than v. (b) Using a loop invariant, prove that your algorithm is correct. Be sure that your loop invariant and proof covers the initialization, maintenance, and termination conditions.Explanation / Answer
Pseudocode for loop variant:
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.