solution

solution - Homework 2 Solution = 1. The add( int pos,...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 Homework 2 Solution Err:510 1. The add( int pos, Object ob ) method is not implementd since allowing the user of a Sorted List the ability to add anywhere, would allow them place it in a position that is not correct for a sorted list. 2. O(1). Start with top at index 0 to indicate the next available array location, you would "push" to the position indicated by "top". The pop operation could then decrement top and return the item at top. 3 Since Dictionary implementations are not guaranteed to store the items in any particular order, there is no reason to believe the getValues iterator object would return the values in sorted order. // Get the iterator object using getValues Call getValues to get an iterator of all values. // Get each value and store it locally for sorting while the iterator has more values: get the next value from the iterator add it to the next available position in an array // Sort the array use a quicksort or other sorting algorithm to sort the array // Print each value for each value in the sorted array print the value 4. O(n log n). It is O(n) to get the values from the iterator and O(n log n) to sort the value array and O(n) to print the values. O(n) + O(n log n) + O(n) = O(n log n) 5. It selects the first item in the data array as a pivot item and partitions the remaining elements into a left half with values that are less than
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 02/17/2011 for the course CS 367 taught by Professor Marvinsolomon during the Spring '08 term at Wisconsin.

Page1 / 8

solution - Homework 2 Solution = 1. The add( int pos,...

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