Answered step by step
Verified Expert Solution
Question
1 Approved Answer
X+X+2 {x-Y>0} 1. (a) Explain the notation: {Pre} Code Post} [10 marks) (b) Which of the following statements are true? In each case you should
X+X+2 {x-Y>0} 1. (a) Explain the notation: {Pre} Code Post} [10 marks) (b) Which of the following statements are true? In each case you should be able to justify your argument informally. i. {x>Y} "YY21 ii. {x is even X+X+1 {v is odd} "Y 2 *x " [10 marks) (c) Write an algorithm, as a procedure, in pseudo-code which: inputs an array A[1...n and an item M; returns the index (position) of the item M if it occurs in A, otherwise returns 0. Examples of its application include input: A output 17,11,3, 2 7 16, 3 10 [6,5, 1, 2,9 1 Your algorithm should not perform useless comparisons. [20 marks] (d) Give an appropriate loop invariant for your algorithm in Part (c). [10 marks]
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