# 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.

Points off 1 2 3 4 Total off Net Score CS 307 – Midterm 2 – Fall 2006 Name__________________________________________ UTEID login name _______________________________ TA's Name Alison Tekin Vineet (Circle One) Instructions: 1. Please turn off your cell phones 2. There are 4 questions on this test. 3. You have 2 hours to complete the test. 4. You may not use a calculator on the test. 5. When code is required, write Java code. 6. When writing methods, assume the preconditions of the method are met. 7. In coding question you may add helper methods if you wish. 8. After completing the test please turn it in to one of the test proctors and show them your UTID. 1. (2 points each, 30 points total) Short answer. Place you answers on the attached answer sheet. If the code contains a syntax error or other compile error, answer “compile error”. If the code would result in a runtime error / exception answer “Runtime error”. If the code results in an infinite loop answer “Infinite loop”. Recall that when asked for Big O your answer should be the most restrictive correct Big O function. For example Selection Sort has an average case Big O of O(N^2), but per the formal definition of Big O it is correct to say Selection Sort also has a Big O of O(N^3) or O(N^4). I want the most restrictive correct Big O function. (Closest without going under.) A. What is the output of System.out.println( fire(7) ); public int fire(int n){ if( n <= 1 ) return 3; else return 2 + fire( n – 3 ); } CS 307 – Midterm 2 – Fall 2006 1

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){

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.

## 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 / 22

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

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

View Full Document
Ask a homework question - tutors are online