# Sp08m2 - Exam Number: Points off 1 2 3 4 Total off Net...

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 – Spring 2008 2 C. What is the output when method c is called? public void c(){ int[] data = {5, 3, 2, 6, 1, -5, 3}; System.out.println( helper(data, 0) ); } public int helper(int[] list, int p){ if( p == list.length - 1 ) return list[p]; else return Math.max( helper(list, p + 1), list[p] ); } D. What is the worst case Big O of method d ? N = nums.length . public int d(int[] nums){ int total = 0; for(int i = 0; i < nums.length; i++) for(int j = nums.length - 1; j >= 0; j--) if( nums[i] == nums[j] ) total++; return total; } E. What is the Big O of method e ? N = nums.length . public int e(int[] nums){ int total = 0; for(int i = 0; i < nums.length; i++) total += nums[i]; int limit = nums.length / 2; for(int j = 0; j < limit; j++) total += nums[j] * nums[j]; return total; } F. What is the Big O of method f ? N = mat.length // pre: mat is a square matrix, mat.length > 0 public int f(int[][] mat){ int row = 1; int col = 1; int total = 0; while( row < mat.length ){ total += mat[row][col]; row *= 3; col *= 3; } return total; }
CS 307 – Midterm 2 – Spring 2008 3 G. What is the best case Big O of method g ? N = numbers.length public static void g(int[] numbers) { int limit = numbers.length; for (int pass = 1; pass < limit; pass++) {

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 at Austin.

### Page1 / 14

Sp08m2 - Exam Number: Points off 1 2 3 4 Total off Net...

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

View Full Document
Ask a homework question - tutors are online