m2SP02Solution

# m2SP02Solution - Possible Solutions for Midterm 2 Spring...

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

Sheet1 Page 1 Possible Solutions for Midterm 2, Spring 2002 On Big O any constants or lesser terms means -2 for that part A.O( N ^ 2 ) or N ^ 2 B.O( N ) or N C.23 D.50 E.2 ^ N F.10 - - 81 55 back front b G.O( N ^ 2 log N ) or N ^ 2 log N (base 2 included is okay) H.runitme error OR stack overflow OR exception. I.2 J.A reference to the Head and Tail nodes and an integer variable to track the number of nodes in the list. (or words to that effe c Question 2: if(myHead == myTail) {myHead = null myTail = null } else {ListNode temp = myHead while(temp.getNext() != myTail) temp = temp.getNext() myTail = temp myTail.setNext( null ) } iMySize-- Question 3: Solutions: public static void printSubsets( int[] nums ) {ArrayList set = new ArrayList() help( nums, 0, set ) }

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

View Full Document
Sheet1 Page 2 public void help( int[] nums, int cur, ArrayList set) {if( cur == nums.length ) System.out.println( set ) else {set.add( new Integer( nums[cur] ) ) help( nums, cur + 1, set) set.remove( set.size() - 1 ) help( nums, cur + 1, set)
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.

### Page1 / 6

m2SP02Solution - Possible Solutions for Midterm 2 Spring...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online