Menu

X X 2 X Y 0 1 Explain Notation Pre Code Post 10 Marks B Following Statements True Case Abl Q43816485

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 eac

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] Show transcribed image text 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]

Expert Answer


Answer to X+X+2 {x-Y>0} 1. (a) Explain the notation: {Pre} Code Post} [10 marks) (b) Which of the following statements are true? I…

OR