sp07m2Key - CS307 Midterm 2 Spring 2007 Suggested Solutions...

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

View Full Document Right Arrow Icon
CS307 Midterm 2 Spring 2007 Suggested Solutions and Criteria 1. Answer as written or -1. Ignore differences in capitilization. On Big O, it is okay if missing O(). A. 6 B. maepnnpeam C. 14 D. O(N^3) E. O(N) F. O(N^3) G. O(N + M) H. O(1) I. O(N) J. O(N) K. 8 seconds L. 21.9 seconds (or 4 * 23 * 5 / 21 or 460 / 21 ) M. 16 seconds N. ABDF O. CBBDB 2. This was suppose to be an easy question, but students had lots of problems. Very few full credit answers. Lot of confusion between a Node variable and a Node object. Not many people drew pictures to help. (Maybe they were on the scratch paper.) // pre: none // post: add obj to the end of this list public void addLast(Object obj){ if( myHead == null) myHead = new Node(obj, null); else { Node temp = myHead; // find last node in list while( temp.getNext() != null ) temp = temp.getNext(); // create and hook up last node temp.setNext( new Node(obj, null) ); } } 3 hanlde empty case 2 use temp Node variable Move temp to end of list 3 attempt 4 correct
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 / 4

sp07m2Key - CS307 Midterm 2 Spring 2007 Suggested Solutions...

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