assign1 - CSE2011F06/HR - Assignment #1 - Due Oct. 4, 06...

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

View Full Document Right Arrow Icon
CSE2011F06/HR - Assignment #1 - Due Oct. 4, 06 Preliminaries, 1. A utility class has a method named contains that takes two parameters, list and x , and returns true if, and only if, x is present in list . The method's precondition states that the list is sorted and this allows it to use the fast θ(lgN) binary search algorithm. To implement this algorithm, we need to be able to compare x with the list elements, and to do that safely, we need to enable the compiler to do static checking. To that end, provide a brief critique of each of the following five method headers. For each, indicate whether it compiles or not and explain any shortcomings it may have vis a vis versatility and type safety: a. public static boolean contains(List list, Object x) b. public static <T> boolean contains(List<T> list, T x) c. public static <T extends Comparable<T>> boolean contains(List<T> list, T x) d. public static <T extends Comparable<? super T>> boolean contains(List<T> list, T x) e. public static <T> boolean contains(List<? extends Comparable<? super T>> list, T x) Hint: You may want to try this by creating a Util.java utility with the above five methods (use a fake body and call the methods contains1 , . .., contains5 ) and a UseUtil.java client. The client can, for example, invoke all five methods in order to search for a java.util.Date in a list of dates, for a java.sql.Time in a list of times, or for a date in list of times. 2. Prove by induction that:
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 / 3

assign1 - CSE2011F06/HR - Assignment #1 - Due Oct. 4, 06...

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