{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS336F09SExam 1sol

# CS336F09SExam 1sol - Sample Exam 1CS 336 General...

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

Sample Exam 1CS 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 legibly and show your reasoning clearly. In your proofs, show a justification for each step. 1. Formalize the following English specification: Let b be an array of length n. Store in c reverse b. ( j| 0 j<n: c[n-j-1]=b[j]) 2. Find x to make the following program segment correct. Check. {Q: 0<n} i ,z:= 1, x; {R: 0 i n z = ( j| 1 j<i : j)} wp((“ i ,z:= 1, x ”, 0 i n z = ( j| 1 j<i : j)) =<wp :=> 0 1 n x= ( j| 1 j<i1: j) <empty range> 0 1 1 n x=1 <arith; ∧− simp > 1 n x=1 Now, since 0 < n (the Q) must imply 1 n x=1 (the wp (S,R)) and the only way this is true is if x is set to 1. Proof: Q wp(“S”, R) < instantiation> 0 < n wp((“ i ,z:= 1, 1 ”, 0 i n z = ( j| 1 j<i : j)) <wp :=> 0 < n 0 1 n 1= ( j| 1

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern