Homework #4 |
Last Updated: 02/09/2012 |
A lab consultant who can help with C251 questions is in LF105 or LF111.
See: www.ius.edu/rwisman/lab for current schedule.
Contact me by email with any questions. I can also usually arrange to meet on campus.
Options:
- Bring a handwritten homework to class on due date.
- Email Word document HW4.doc to instructor by 13:00 on due date.
The special symbols can be copied from the notes and pasted into Word. Here are some:
$"¬®³¹«£ºÆÏÎÈÍÇ ë û é ù
And answer True/False:
For example, 14a. asks whether x3 is O(x2).
8b) hint: Count the total multiplications and additions in: y := y * c + an-i
Extra credit
Induction Proof of loop invariant - Summation of a sequence
Hint: See Chapter 4 notes Example proof of loop invariant - Maximum of a sequence
Note
Use of Pk and Pk+1 not necessary but helpful in thinking about the induction.
a. What is the postcondition?
b. What is the loop invariant?
-- Precondition: ∃a1
procedure Pn( a1, a2, a3, ..., an : integers)Pk ← a1
i ← 1
while i < n Pk+1 ← Pk + ai+1
i ← i + 1
Pk ← Pk+1
Show ∀j: 1 ≤ j ≤ i, ∑aj = Pk ^ i ≤ n is always true
1. Base Step: before the loop,
c. Base step? 2. Inductive Step: Pk → Pk+1 at the end of each loop,
d. Show what for Pk+1? e. Assume what?
f. Proof
3. and after the loop completes i = n ∴ ∀j: 1 ≤ j ≤ i = n, ∑aj = Pk