{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Fa08m2 - Exam Number Points off 1 2 3 4 5 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 – Fall 2008 2 B. What is the best case Big O of the following method? N = data.length public int b(int[] data, int tgt){ int count = 0; for(int i = 0; i < data.length; i++){ for(int j = 0; j < data.length; j++){ if( data[i] * data[j] == tgt ) count++; } } for(int i = 0; i < data.length; i++){ if( data[i] == tgt ) count++; } return count; } C. What is the Big O of the following method? N = data.size() public int c(ArrayList<Integer> data){ int sum = 0; for(int i = 1; i < data.size(); i *= 3) sum += data.get(i); return sum; } D. What is the Big O of the following method? N = data.length . Method numPresent is O(N). public int d(int[] data){ int sum = 0; for(int i = 1; i <= data.length; i *= 2) sum += numPresent(data, i); return sum; } E. What is the Big O of adding an element at position 0 to an array based list that already contains N elements? F. What is the Big O of adding an element at position 0 to a linked list that already contains N elements? G. What is the Big O of the following method? N = data.length . public int g(LinkedList<Integer> data){ int total = 0; for(int i = 0; i < data.size(); i++) for(int j = i; j < data.size(); j++) total += data.get(i) * data.get(j); return total; }
CS 307 – Midterm 2 – Fall 2008 3 H. What is the T(N) of the following method? N = data.length . data is a square matrix with the same number of columns as rows. other will be the same size as data .

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

Fa08m2 - Exam Number Points off 1 2 3 4 5 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