{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Fa06FinalSolnAndCriteria

Fa06FinalSolnAndCriteria - CS307 Fall 2006 final Exam...

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

View Full Document Right Arrow Icon
CS307 Fall 2006 final Exam suggested solutions and grading criteria. 1. Answer as written or -2. On Big O questions leaving off O() okay. On output questions differences in spacing okay. O A. 19 / \ 12 21 / \ -5 14 B. SITRKNE B C. ITSNKRE C D. TINKERS D E. No F. 19 4 13 10 7 16 G. O(1) H. O(N) I. 100 J. O(log N) K. O(N) L. O(N) L M. It is better to sort and then do a binary search. M If the data is not sorted the number of operations is roughly 1.25 x 10^5 * 5 x 10 ^ 5. (Assumes each linear search goes about half way through the list of items.) This equals 6.25 x 10^10 ops. t If the data is sorted using quicksort, and NlogN sort, and then searched using binary search the number of ops is roughly b 1 x 10^6 * log 1 x 10^6 + 1.25 x 10^5 * log 1 x 10^ 6 = 1 x 10^6 * 2 x 10^1 + 1.25 x 10^5 * 2 x 10^1 = 2 x 10^7 + 2.5 x 10^6 = 2 x 10^7 + .25 x 10^7 = 2.25 x 10^7 2 2.25 x 10^7 is much less than 6.25 x 10^10. Or words and calculations to that effect. (No partial credit.) O N. n1 n3 n2 ----- ----- ----- | | | | | | --|-- --|-- --|-- | | | | | | | | | V V V -------------------- -------------------- | | | | | | | | | | / | ---------->| | / | / | | | | | | | | | | | ----|--------------- ----|--------------- | ^ | ^ | | | | ------- -------
Background image of page 1

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

View Full Document Right Arrow Icon
O. O(N)
Background image of page 2
2. Suggested Solution: 2 public boolean isCircular(){ if( head == null ) return false; Node temp = head; while( temp.getNext() != null && temp.getNext() != head ) temp = temp.getNext(); return temp.getNext() == head; } criteria: c 1 point, handle empty case correctly 3 points, attempt to traverse list
Background image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}