SampleExam1S08 - {Q: 0 < n} i ,p:= 1, y; {P: 1in...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Name_______________________________ Sample Exam 1 CS 336 General Instructions: Do all of your work on these pages. If you need more space, use the backs (to ensure the grader sees it, make a note of it on the front). Make sure your name appears on every page. Please write large and legibly and show your reasoning clearly. In your proofs, show a justification for each step. No books are to be used during this test, nor any notes other than the single page of notes expressly permitted. 1. (10 points) Given two fixed arrays a[0. .m-1] and b[0. .n-1] where m>0 and n>0. It is known that no two elements of a[0. .m-1] are equal and no two elements of b[0. .n-1] are equal. Formalize the following English specification: C counts the number of elements that belong to a[0. .m-1] but not b[0. .n-1]. 2. (10 points) Find y to make the following program segment correct. Show that your values for y will make the program segment hold.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: {Q: 0 < n} i ,p:= 1, y; {P: 1in p=( j| 1j<i: j)} 3. (36 points) Find the weakest precondition and simplify for the following: a. wp(i,j:= i+2, j-3i, i = j) b. wp(i:= i+2; j:=j-3i, i = j) c. wp( i,m:= 0, b[0], 0in ( 2200 j| 0j<i: m=b[j]) d. wp( t :=n-i; if =b[i] m m:= b[i] b[i]m skip fi; i:=i+1, t >n-i) 4. (24 points) Consider the algorithm. { 0<n} i,p:= 0, 1; {0in p=q i } do i<n p:=p q; i:= i+1 od { p=q n } a) Prove that the invariant holds at the entry of the loop. b) Prove that if the program terminates, that it does so in a state that satisfies the post condition. 5. Let sum(w) denote the sum of all of the values in a ternary string w. Define the function sum inductively. (6 pts) Prove that sum(w 1 w 2 )= sum(w 1 ) + sum(w 2 ). (14 pts) Name_______________________________...
View Full Document

Page1 / 2

SampleExam1S08 - {Q: 0 < n} i ,p:= 1, y; {P: 1in...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online