{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

quiz5-questions

quiz5-questions - EE 322C Data Structures Spring 2009 Quiz...

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

EE 322C Data Structures Spring 2009 Quiz 5 Instructor: Ramesh Yerraballi Student: Anirudh Pande Grader: Vinoth Chandar Date: 4/29/09 Due : Wednesday 4/29 in class Total : 100 points 1) Collections.sort(List<T>) method takes any list and sorts it according to the type of objects held in the list. For example, Strings are sorted alphabetically, Integers are sorted by value and Date objects chronologically. [15 points ] a) How is this behavior implemented? Collections.sort is implemented as a modified mergesort, where the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist. The method sorts the specified list into ascending order, according to the natural ordering of its elements. The implementation of the method dumps the specified list into an array, sorts the array, and iterates over the list resetting each element from the corresponding position in the array. The best case of the algorithm offers a n log(n) performance. For the method to work, all elements in the list must implement the Comparable interface. Furthermore, all elements in the list must be mutually comparable, meaning, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the list. Finally, the specified list must be modifiable, but not resizeable. b) List<Integer> lst = new ArrayList<Integer> (); Write java code to provide you a sorted list of integers, lst, in the descending order, using the Collections.sort method. [You cannot use the Collections.reverse method]

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}