# Sp06m2 - Points off 1 2 3 4 Total off Net Score CS 307...

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

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

View Full Document
B. What is the output of System.out.println( giant(8) ); public int giant(int n){ int result = 0; if( n <= 2 ) result = 1; else result = 2 + giant( n – 3 ); return result; } C. What is the output of System.out.println( trek(5) ); public int trek(int n) { if( n <= 1 ) return 3; else return 1 + trek( n – 2 ) + trek( n - 1 ); } Consider a SinglyLinkedList that uses Node objects as discussed in class. The SinglyLinkedList class has references to the first node in the list, myHead , and the last node in the list, myTail . Assume the data in every node in the list is an integer. Consider the following two methods which are instance methods in the SinglyLinkedList class. // pre: none // post: return the total of all integers in the list. public int getTotal(){ return helper(myHead, 0); } private int helper(Node n, int total){ if( n == null ) return total; else return helper( n.getNext(), total + n.getData() ); } D. Given N elements in the singly linked list what is the Big O time for method getTotal ? E. Given N elements in the singly linked list what is the Big O space for method getTotal ? CS 307 – Midterm 2 – Spring 2006 2
F. Consider the following methods for a List class. The List behaves like a List from the Java standard library as discussed in class. Method Summary void add (Object o) Appends the specified element to the end of this list. void add (int index, Object element) Inserts the specified element at the specified position in this list.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern