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

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

View Full Document Right Arrow Icon
Points off 1 2 3 4 Total off Net Score CS 307 – Midterm 2 – Fall 2005 Name__________________________________________ UTEID login name _______________________________ TA's Name ___________________________ (Chendi, Don, or Peggy) 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 “Compiler 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 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( ivan(5) ); public int ivan(int n) { if( n < 1 ) return 3; else return 3 + ivan(n - 1); } CS 307 – Midterm 2 – Fall 2005 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
B. What is the output of jan(4); public void jan(int n) { if( n <= 0 ) System.out.print( '*' ); else { System.out.print( n ); jan( n – 2 ); System.out.print( n ); } } C. What is the output of System.out.println( ras(8) ); public int ras(int n) { if( n <= 2 ) return 2; else return 3 + ras(n – 2) + ras(n - 2); } D. What is the output of System.out.println( fran(“man”)); // pre: s != null // recall the first character of a String is at position 0 // substring(int) returns a substring starting at the specified // position and going to the end of the String public String fran(String s) { String result = “”; if( s.length() <= 1) result = s; else result = s.charAt(0) + fran(s.substring(1)) + s.charAt(0); return result; } CS 307 – Midterm 2 – Fall 2005 2
Background image of page 2
E. What is the Big O of method ivan in part A? F.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
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 at Austin.

Page1 / 18

Fa05m2 - 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 Right Arrow Icon
Ask a homework question - tutors are online