{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Fa06m2 - 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( crew(13, 1) ); public int crew(int n, int m){ int result = 0; if( m == 0 ) result = 3; else if( n < 1 ) result = 1; else result = m + crew( n / m, m + 1 ); return result; } C. What is the output of System.out.println( united(6) ); public int united(int n) { if( n <= 3 ) return 1; else return 2 + united( n – 1 ) + united( n - 1 ); } D. What is the Big O of method united in part C? E. What is the average case Big O of the following method? N = data.length. public int wizard(double data[], int tgt){ int total = 0; int limit = data.length / 2; for(int i = 0; i < limit; i++) if( data[i] > tgt ) total++; return total; } F. What is the result of the following postfix expression? 3 2 5 + * 2 + G. Consider a LinkedList class that uses singly linked nodes and has references to the first and last nodes in the list. The examples from class were for this kind of list. What is the Big O of removing the last element of such a LinkedList if there are already N elements present? Explain why. CS 307 – Midterm 2 – Fall 2006 2
H. What is the average case Big O of the following method? N = list.length. public int[] revolution(int[] list){ int[] result = new int[ list.length ]; for(int i = 0; i < list.length; i++) for(int j = 0; j < i; j++) foo( list, result, i, j); // foo is O(1) return result; } I. What is the average case Big O of the following method? N = vals.length. public int real(int[] vals){ int result = 0; for(int i = vals.length; i > 0; i /= 2) for(int j = 1; j < i; j++) result += bar(vals, i, j); // bar is O(1) return result; } J. Consider the following SortedSet class.

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