Fa06Final - Points off 1 2 3 4 5 6 Total off Net Score CS...

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

View Full Document Right Arrow Icon
Points off 1 2 3 4 5 6 Total off Net Score CS 307 – Final – Fall 2006 Name__________________________________________ UTEID login name _______________________________ Circle your TA’s name: Alison Tekin Vineet Instructions: 1. Please turn off your cell phones. 2. There are 6 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. When answering questions 2 - 6, 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. 19, 12, 21, 14, -5 CS 307 – Final – Fall 2006 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 – Fall 2006 2 root of tree 'S' 'I' 'R' 'T' 'E' 'K' 'N'
Background image of page 2
What is the output of the following code segment? Queue<Integer> q = new Queue<Integer>(); Stack<Integer> s = new Stack<Integer>(); for(int i = 1; i < 20; i += 3){ if( i % 2 == 0 ) q.enqueue(i); else s.push( i ); } System.out.print( s.pop() + " " ); System.out.print( q.dequeue() + " " ); } For questions G. and H. consider the following Queue class public class Queue<AnyType>{ private ArrayList<AnyType> myCon; public Queue(){ myCon = new ArrayList<AnyType>(); } public AnyType front(){ return myCon.get( myCon.size() - 1 ); } public AnyType dequeue(){ return myCon.remove( myCon.size() - 1 ); } public boolean isEmpty(){ return myCon.size() == 0;
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 / 22

Fa06Final - Points off 1 2 3 4 5 6 Total off Net Score CS...

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