Fa08Final - Points off 1 2 3 4 5 Total off Net Score CS 307...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 307 – Final – Fall 2008 1 Points off 1 2 3 4 5 Total off Net Score CS 307 – Final – Fall 2008 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. 17 -12 5 0 20 15
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 307 – Final – Fall 2008 2 Consider the following binary tree. M is the root of the tree. M / \ D R / \ / \ A K P T \ Z B. What is the result of a pre-order traversal of the binary tree? C. What is the result of a in-order traversal of the binary tree? D. What is the result of a post-order traversal of the binary tree? E. What is the result of a level-order traversal of the binary tree? F. Is the tree shown above a binary search tree? G. What is the height of the tree shown above? H. What is the worst case Big O for adding N elements, one at a time to an initially empty binary search tree using the traditional, naïve insertion algorithm? I. What is the Big O of the following method? Assume Math.random is O(1). list is initially empty. public void randFill(int N, LinkedList<Double> list ){ assert list.size() == 0; for(int i = 0; i < N; i++) list.add(Math.random()); double total = 0.0; for(int i = 0; i < list.size(); i++) total += list.get(i); } J. What is the Big O of the following method? public ArrayList<Integer> createAndFill(int N){ ArrayList<Integer> result = new ArrayList<Integer>(); for(int i = 0; i < N; i++) result.add(i); return result; }
Background image of page 2
CS 307 – Final – Fall 2008 3 K. An UnsortedSet class uses a Java ArrayList as its internal storage container.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 18

Fa08Final - Points off 1 2 3 4 5 Total off Net Score CS 307...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online