{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Fa07m2 - Exam Number Points off 1 2 3 4 Total off Net Score...

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
CS 307 – Midterm 2 – Fall 2007 2 C. What is the output of System.out.println( c(4) ); public int c(int n) { if( n <= 0 ) return 3; else return n + c(n - 1) + c(n - 1); } D. What is the Big O of method d ? N = values.length . public int d(int[] values){ int total = 0; for(int i = 0; i < values.length / 2; i++) total += values[i]; return total; } E. What is the Big O of method e ? public int e(int N){ int sum = 0; for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ sum += (i - 1) * (j - 1); } } for(int i = 0; i < N; i++) sum -= i; return sum; } F. What is the worst case Big O of method f ? N = mat.length //pre: mat is a square matrix public int f(int[][] mat, int row, int col){ int total = 0; for(int r = row - 2; r <= row + 2; r++) for(int c = col - 2; c <= col + 2; c++) if( 0 <= r && r < mat.length && 0 <= c && c < mat.length) total += mat[r][c]; return total; }
CS 307 – Midterm 2 – Fall 2007 3 G. What is the worst case Big O of method g ? list is a LinkedList from the Java standard library. N =

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 ]}

### Page1 / 15

Fa07m2 - Exam Number Points off 1 2 3 4 Total off Net Score...

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

View Full Document
Ask a homework question - tutors are online