This preview shows pages 1–4. Sign up to view the full content.
CS 307 – Final – Spring 2009
1
Points off
1
2
3
4
5
Total off
Net Score
CS 307 – Final – Spring 2009
Name__________________________________________
UTEID login name _______________________________
Instructions:
1.
Please turn off your cell phones.
2.
There are 5 questions on this test.
3.
You have 3 hours to complete the test.
4.
You may not use a calculator on the test.
5.
You may add helper methods if you wish when answering coding questions.
6.
When answering coding questions assume the preconditions of the methods are met.
1. (1.5
point each, 30 points total) Short answer. Place you answers on the attached answer sheet.
For questions that ask what is the output:
•
If the code contains a syntax error or other compile error, answer “Compiler error”.
•
If the code would result in a runtime error or exception answer “Runtime error”.
•
If the code results in an infinite loop answer “Infinite loop”.
On questions that ask for the Big O of a method or algorithm, recall that when asked for Big O your
answer should be the most restrictive Big O function. For example Selection Sort has an expected
case Big O of O(N^2), but per the formal definition of Big O it is correct to say Selection Sort also
has a Big O of O(N^3). Give the most restrictive, correct function. (Closest without going under.)
Short answer questions that refer to
ArrayList
s and
LinkedList
s are referring to the Java
standard library classes unless otherwise noted.
A.
The following values are inserted one at a time in the order shown into an initially empty
binary search tree using the traditional, naïve insertion algorithm. Draw the resulting tree.
22
63
8
20
49
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document CS 307 – Final – Spring 2009
2
Consider the following binary tree.
A
is the root of the tree.
A
/
\
G
I
/
/
A
S
/ \
N
O
B.
What is the result of a preorder traversal of the binary tree?
C.
What is the result of a inorder traversal of the binary tree?
D.
What is the result of a postorder traversal of the binary tree?
E.
What is the result of a levelorder traversal of the binary tree?
F.
Is the tree shown above a binary search tree?
G.
What is the best case Big O for the following method?
list
contains N elements.
public int count(int cutoff, LinkedList<Integer> list){
int count = 0;
for(int i = 0; i < list.size(); i++){
if( list.get(i) > cutoff ){
count++;
}
}
return count;
}
H.
What is the worst case Big O for adding N elements, one at a time to an initially empty
red black tree?
I.
What is output by the following code?
String name = "WILKINSON";
Stack<Character> st = new Stack<Character>();
for(int i = 0; i < name.length(); i++)
st.push( name.charAt(i) );
st.pop();
st.pop();
st.push( st.peek() ); // peek returns top item without removing
for(int i = 0; i < 4; i++)
System.out.print( st.pop() );
CS 307 – Final – Spring 2009
3
J.
What is the worst case Big O of the following method? Assume the
println
method is
O(1) and that
list
contains N elements.
public void clearPrint(double cutoff, ArrayList<Double>
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.
 Spring '08
 SCOTT

Click to edit the document details