solve1 - CSE2011F06/HR - Solution of #1 1. Headers (a) and...

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

View Full Document Right Arrow Icon
CSE2011F06/HR - Solution of #1 1. Headers (a) and (b) are clearly not type-safe because invoking compareTo needs a cast and that may crash. Headers (c), (d) and (e) are type-safe but have differing versatility: (c) allows only objects that can be compared with themselves such as a list of dates and a date, while (d) allows a list of times and a time because time is comparable to a date. What (d) does not allow is a list of dates and a time, and this case is handled by (e). 2. Prove by induction that: a. The base case is a triangle. The induction hypothesis is that the predicate holds for a polygon of n sides. For an n+1 polygon, draw a chord between two vertices that are one vertex apart. This divides it into a polygon of n sids and a triangle. The predicate holds for both. b. Straightforward algebra. c. The base case i=0 holds because the loop skips (is not entered). And if the invariant holds after i iterations, then pow = a i at the top of the loop's body. The statements executed afterwards are pow = pow * a , which makes pow = a i * a = pow = a i+1 , and i+ + , which makes pow = a i . Hence, the invariant holds at the next iteration.
Background image of page 1

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

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

This note was uploaded on 12/11/2010 for the course CSE CSE 2011 taught by Professor Neugyen during the Fall '09 term at York University.

Page1 / 2

solve1 - CSE2011F06/HR - Solution of #1 1. Headers (a) and...

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