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

This preview shows pages 1–3. 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 2009 2 B. What is the worst case Big O of the following method? N = data.length public int methodB(int[] data){ int count = 0; for(int i = 0; i < data.length; i++){ if( data[i] % 2 == 0 ) count++; } for(int i = 1; i < data.length; i++){ if( data[i] % 10 == 0 ) count++; } return count; } C. What is the worst case Big O of the following method? N = data.length . The length method from the String class is O(1). public int methodC(String[] data){ int sum = 0; for(int i = 0; i * i < data.length; i++){ int temp = i * i; if( data[temp] != null ) sum += data[temp].length(); } return sum; } D. What is the worst case Big O of the following method? N = data.length . public boolean methodD(int[] data, int tgt){ int temp; boolean found = false; int index = 0; int limit = data.length - 4; while( index < limit && !found ){ temp = 0; for(int off = 0; off < 5; off++) temp += data[index + off]; found = temp == tgt; index++; } return found; } E. A method is O(2 N ). It takes 5 seconds for the method to complete when given a data set with 100 elements. What is the expected time for the method to complete when given a data set with 104 elements? F.
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 / 15

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

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

View Full Document
Ask a homework question - tutors are online