Verify that the program segment
if x < y then bb min := x else
bb min := y
is correct with respect to the initial assertion T and the final assertion (x ≤ y ∧ min = x) ∨ (x > y ∧ min = y).
Copyright By PowCoder代写 加微信 powcoder
Suppose that both the conditional statement p0 → p1 and the program assertion p1{S}q are true. Show that p0{S}q also must be true.
Problem 3 (in-class task!)
This program computes quotients and remainders.
while r ≥ d bb r := r − d bb q := q + 1
Verify that it is partially correct with respect to the initial assertion “a and d are positive integers” and the final assertion “q and r are integers such that a = dq + r and 0 ≤ r < d.”
1/3 CSI2101/UOttawa/MdH/W22
Solve these recurrence relations together with the initial conditions given. (a)an =an−2 forn≥2,a0 =5,a1 =−1.
(b)an+2 =−4an+1+5an,forn≥0,a0 =2,a1 =8.
Find the solution to an = 2an−1 + an−2 − 2an−3 for n = 3,4,5,..., with a0 = 3, a1 =6,anda2 =0.
Solve the recurrence relation an = 6an−1 − 12an−2 + 8an−3 with a0 = −5, a1 = 4, and a2 = 88.
Consider the nonhomogeneous recurrence relation an = 2an−1 + 2n. (a) Show that an = n2n is a solution of this recurrence relation. (b) Find all solutions of this recurrence relation.
(c) Find the solution with a0 = 2.
2/3 CSI2101/UOttawa/MdH/W22
What is the general form of the particular solution guaranteed to exist by The- orem 6 of the linear nonhomogeneous recurrence relation an = 6an−1 − 12aa−2 + 8an−3 + F (n) if
(a) F(n) = 3? (b) F(n) = n2? (c) F(n) = 2n? (d) F(n) = n22n?
3/3 CSI2101/UOttawa/MdH/W22
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com