Sp04Midterm2 - Points off 1 2 3 4 5 6 Total off Net Score...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Points off 1 2 3 4 5 6 Total off Net Score CS 307 – Midterm 2 – Spring 2004 Name__________________________________________ UTEID login name _______________________________ Section Leader's Name ___________________________ Instructions: 1. There are 4 questions on this test. 2. You have 2 hours to complete the test. 3. You may not use a calculator on the test. 4. When code is required, write Java code. 5. The style guide is not in effect except where noted. 6. Efficiency is not graded except where noted. 7. Ensure your answers are legible. 8. When writing code you may not use any methods or classes from the Java Standard Library except as noted and the System.out.print, System.out.println, the equals method, and native arrays. 9. In coding question you may add helper methods if you wish. 10. The last page of the test is scratch paper. 1. (2 points each, 30 points total) Short answer. If an error would occur answer "syntax error" or "runtime error" depending on what type of error it would be. Recall that when asked for Big O your answer should be the most precise 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). I want the most precise Big O function. (Closest without going under.) A. What is the output of System.out.println( surprise(4) ); public int surprise(int x) { if( x < 2 ) return 1; else return 1 + surprise( x – 1 ); } _____________________________________________________________________________ CS 307 – Midterm 2 – Spring 2004 1 B. What is the output of sophie(5); public void sophie(int y) { if( y < 0 ) System.out.print( y + " " ); else { System.out.print( y + " " ); sophie( y – 1); } } C. What is the output of pollychrest(7); public void pollychrest(int z) { System.out.print( z + " " ); if( z >= 0 ) { pollychrest( z – 2 ); System.out.print( z + " " ); } } _____________________________________________________________________________ D. What is the output of System.out.println( victory(4) ); public int victory(int a) { if( a < 0 ) return 1; else return 2 + victory(a – 1) + victory(a – 2); } _____________________________________________________________________________ CS 307 – Midterm 2 – Spring 2004 2 E. What is the Big O of the following code segment? (The variable n is an integer parameter sent to the method that contains this code segment.) int total = 0; for(int i = 0; i < n; i++) { total++; } _____________________________________________________________________________ F. What is T(N), the actual number of executable statements, for the following code segment? Count the each of the initialization statements, boolean expressions, and increment statements in a for loop as separate statements, not as a single statement. (The variable n is an integer parameter sent to the method that contains this code segment.) int total = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { total++;...
View Full 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 / 18

Sp04Midterm2 - Points off 1 2 3 4 5 6 Total off Net Score...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online