# fa04m2 - 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 tang(4); public void tang(int n) { if( n <= 0 ) System.out.print( '*' ); else { tang( n – 1); System.out.print( n + " " ); } } C. What is the output of System.out.println( strake(6)); public int strake(int n) { if( n <= 3) return 3; else return 3 + strake(n – 1) + strake(n - 1); } D. What is Big O of the following code segment? (The variable n is an integer parameter sent to the method that contains this code segment.) int s = 0; for(int i = n; i >= 0; i--) { s += i * i; } 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 x = 1; int j = 1; while( j <= n ) { x *= j; j *= 2; } CS 307 – Midterm 2 – Fall 2004 2
What is the Big O of the following method? public int[][] tautog(int[][] mat) { //pre: mat != null, mat.length >= 10, // mat[0].length >= 10 int[][] result = new int[10][10]; for(int r = 0; r < result.length; r++) for(int c = 0; c < result[0].length; c++) result[r][c] = mat[r][c]; return result; } G. What is the Big O of the following code segment? Method guppy is O(1). Method shark is O(1). (The variable n is an integer parameter sent to the method that contains this code segment.) int foo = 0; for(int i = 0; i < n; i++) for(int j = 0; j < i; j++) { guppy(); shark(); foo++; } H. What is the Big O of the following code segment? Method dolphin is O(1). (The variables n and m are integer parameters sent to the method that contains this code segment.) for(int i = 0; i < n; i++)

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 / 17

fa04m2 - 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