brief final review sheet
Transcription
brief final review sheet
CSCI 135 – Discrete Structures – Final Review Questions – Spring 2015 Anything we have covered in the course is fair game for the midterm, including all exercises in chapters 1 to 5, and many of the exercises in chapters 8 to 12. Questions will be very similar to those from homework and in-class quizzes. You should be able to find proofs and write them in the detailed format described in the book. I will provide hints and guidance where appropriate, e.g. for proofs that are very tricky or difficult to find. For practice, you would do well to work through examples and exercises from the book. There should be plenty to keep you occupied. I can provide solutions by email to a limited number of specific, individual exercises if you are stuck or want to check your work. I also have a complete set of solutions for all textbook exercises. You may examine this in person during office hours or by appointment. The following exercises might also help you get started with studying. Review Question 1: Use method 10.5 to prove that the following annotated program is correct. {x + y = 0} if x = 5 then x := x+1 ; y := y-1 else y := -x fi {x + y = 0} Recall method 10.5: To prove {Q} if B then S1 else S2 fi {R} it suffices to prove: {Q B} S1 {R}, and {Q ¬B} S2 {R}. Review Question 2: Prove the following argument is valid. The first three sentences are hypotheses and the fourth sentence is to be proved. If Mary walks 20 miles, she will be exhausted. Either she will walk 20 miles, or (exclusive or) she will give up sooner. Mary is not exhausted. Therefore she gave up sooner. Use the following variables: W: Mary walks 20 miles. E: Mary is exhausted. G: Mary gives up sooner. Review Question 3: Draw a circuit for the following expression, where a, b and c are the inputs and z is the output. Use only inverters, 2-input-and gates, and 2-input-or gates. z = ¬(a b) V ¬(b c) Review Question 4a: List the bound variable(s) in the quantification. (x: Z | 0 ≤ x ≤3 : y = x2) Review Question 4b: Enumerate (i.e. list) the elements of the following set. { y | (x | 0 ≤ x ≤3 : y = x2)} Review Question 5: Prove that n2 ≤ 2n for any integer n ≥ 4. That is, prove (n | 4≤n: n2 ≤ 2n). Use induction on n. Review Question 6: Determine the weakest precondition for the following statement and postcondition. Simplify as much as possible. { ? } i,p := 0,1 { (0≤i≤n) (p = 2i) } Review Question 7: The algorithm below is annotated with a precondition, loop invariant, bound function and postcondition. Prove the algorithm is correct using Checklist (12.45) given below. {precondition Q: (0 ≤ n)} i, p := 0, 1; {invariant P: (0 ≤ i ≤ n) (p = 2i)} {bound T: n-i} do i ≠ n i, p := i + 1, p•2; od {postcondition R: (p = 2n)} Checklist (12.45) 1. Loop init establishes the invariant: Precondition wp( init, P ) 2. Loop body maintains invariant: P B wp( body, P ) 3. Loop completion establishes the post-condition: P ¬B Postcondition 4. T is bounded from below before an iteration: PBT>0 5. T decreases upon each iteration: P B T=oldT wp( body, T<oldT ) Other topics: • Quantification (translation from English to quantification or vice versa; expand a quantification; “simple” proofs involving quantification – empty range, split-off term) • Truth Table • Historical Notes • Fill in the hints for a chapter 3-style proof • Applications of Chapter 3-Style Proofs (e.g. word problems, circuits, ...)