{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Fa05M2SolnAndCriteria

Fa05M2SolnAndCriteria - CS 307 Fall 2005 Midterm 2...

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

CS 307, Fall 2005, Midterm 2 Suggested Solution and Grading Criteria Question 1. 2 points per part. Correct answer or -2. On Big O leaving off O( ) okay. Example, N instead of O(N), okay. Correct name of Big O functions also okay. Example: constant instead of O(1) 1. A. 18 B. 42*24 C. 37 D. manam E. O(N) F. O(1) G. 6N + 7, range on N: 5N - 7N okay. range on constant: 6 - 8 okay. H. O(N) I. O(N^3) J. O(N^2) K. O(logN) base 2 okay, but not required L. 32 seconds M. 20,000 seconds N. For a linked list a linear search will be more efficient than binary. This is because getting an element in the middle of the list takes O(N) time, so it is faster to just do a linear search. (Or words to that affect. Partial credit possible.) O. To achieve the worst case the value selected as the pivot must always be either the smallest or largest value in the list being sorted. (Or words to that effect. Partial credit possible.)

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

View Full Document
2. Suggested solution: public UnsortetSet(Bag b) { myCon = new Object[b.size]; mySize = 0; Iterator it = b.iterator(); Object temp; boolean present; int index = 0; while( it.hasNext() )
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}