m2CritAndSol'n - CS 307 Fall 2003 Midterm 2 Suggested...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 CS 307 Fall 2003 Midterm 2 Suggested Solutions and Grading Criteria 1. Answer as written or -3. Partial credit only where noted. On Big O problems no points off for missing O( ) A.O(N) B.O(N) C.O(N^3) D.O(N^2) E.18 E F.6 G.O(logN) base 2 okay, but not necessary H.500 sec I.8 * 23 * 2 / 20 or 92 / 5 or 18.4 +/- 1 seconds J.The worst case can occur if the pivot always picks the lowest or highest value in the list (Or words to that effect.) ( return helper(a, b, distance, 0, new ArrayList()) private boolean helper(City cur, City dest, int limit, int soFar, ArrayList visited) {boolean result = false if(cur.equals(dest)) result = soFar <= limit else if(beenTo.contains(cur) || soFar > limit) result = false else {//haven't been here on current route. soFar.add(cur) ArrayList connections = cur.connectsTo() City next C for(int i = 0 {next = (City)(connections.get(i)) if( helper( next, dest, limit, soFar + cur.distanceTo(next), visited) result = true } // remove from list for possible alternate routes
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 11/30/2010 for the course CS 307 taught by Professor Scott during the Spring '08 term at University of Texas at Austin.

Page1 / 6

m2CritAndSol'n - CS 307 Fall 2003 Midterm 2 Suggested...

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