This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Points off 1 2 3 4 5 Total off Net Score CS 307 – Final – Spring 2007 Name__________________________________________ UTEID login name _______________________________ Circle your TA’s name: Alison Aparajit Vineet 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. When code is required, write Java code. 6. Ensure your answers are legible. 7. When answering coding questions, you may add helper methods if you wish . 8. Some questions limit the other classes you may use when answering the question. You will not get full credit if you do not follow these limitations. 9. When answering questions 2  5, assume the preconditions of the methods are met. 1. (2 points 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 Big O function. (Closest without going under.) A. The following numbers are inserted, one at a time, in the order shown, into a binary search tree with no checks to ensure or maintain balance. (i.e. the traditional naïve insertion algorithm.) The tree is initially empty. Draw the resulting tree. 25, 5, 12, 7, 39 CS 307 – Final – Spring 2007 1 For parts B  E consider the following binary tree. For each question assume when a node is processed the value in the node is printed out by the statement: System.out.print( currentNode.getData() + " " ); B. What is the output of a preorder traversal of the above tree? C. What is the output of an inorder traversal of the above tree? D. What is the output of a postorder traversal of the above tree? E. Is the binary tree shown above a binary search tree? Assume characters are compared based on alphabetical order. CS 307 – Final – Spring 2007 2 root of tree 'E' 'M' 'T' 'O' 'U' 'C' 'P' F. What is the output of the following code segment? Stack<Integer> s1 = new Stack<Integer>(); Stack<Integer> s2 = new Stack<Integer>(); Stack<Integer> s3 = new Stack<Integer>(); int data = {3, 1, 4, 1, 5, 9}; for(int i = data.length  1; i >= 0; i) s1.push( data[i] ); while( !s1.isEmpty() ){ if( s1.top() % 3 == 0 ) s2.push( s1.pop() ); else s3.push( s1.pop() ); } while( !s2.isEmpty() ) System.out.print( s2.pop() ); while( !s3.isEmpty() ) System.out.print( s3.pop() ); G. What is the average case Big O for inserting N items into a redblack tree that is initially...
View
Full
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.
 Spring '08
 SCOTT

Click to edit the document details