DOC PREVIEW
UT CS 307 - Final Exam

This preview shows page 1-2-19-20 out of 20 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 307 – Final – Fall 2007 1 Points off 1 2 3 4 5 6 Total off Net Score CS 307 – Final – Fall 2007 Name__________________________________________ UTEID login name _______________________________ 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. You may add helper methods if you wish when answering coding questions. 8. When answering coding questions assume the preconditions of the methods are met. 9. There is a quick reference sheet with some of the classes from the Java standard library attached to the test. 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 Big O function. (Closest without going under.) A. The following values are inserted 1 at a time in the order shown into an initially empty binary search tree using the traditional algorithm. Draw the resulting tree. 16 7 -5 0 25CS 307 – Final – Fall 2007 2 Consider the following binary tree: 3 / \ 7 8 / / \ 0 5 2 / 1 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? Consider the following Huffman code tree. Characters only exist in nodes that are leaves. Nodes with characters are represented with a dash. '-' - / \ - - / \ / \ - e i h / \ g l E. Given the above Huffman code tree, what is the binary code for the word "lie"? F. What is output by the following code? Stack<Character> s1 = new Stack<Character>(); String name = "isabelle"; for(int i = 0; i < name.length(); i++) if( name.charAt(i) > 'c' ) s1.push( name.charAt(i) ); while( !s1.isEmpty() ) System.out.print( s1.pop() ); G. Consider a linked list that uses singly linked nodes and maintains a reference to the first node and last node in the list. What is the Big O of removing the last element of the list? The list has N elements in it.CS 307 – Final – Fall 2007 3 H. What is the worst case height of a binary search tree that contains N elements and was created using the naïve insertion algorithm. I. What is the worst case height of a binary search tree that contains N elements and was created using the red-black tree insertion algorithm. J. What is output by the following code? int[] data = {5, 8, 2, 5}; Queue<Integer> q1 = new Queue<Integer>(); for(int i = 0; i < data.length; i++){ if( data[i] % 2 != 0 ) q1.enqueue( data[i] ); q1.enqueue( data[i] ); } while( !q1.isEmpty() ) System.out.print( q1.dequeue() ); K. You are developing a program and you need to represent 60 distinct elements of a new data type. What is the minimum number of bits necessary to represent 60 distinct items? L. The following code results in a syntax error. Briefly explain why. ArrayList<String> ns = new ArrayList<String>(); ns.add( "A" ); ns.add( "B" ); ns.add( 12 ); ns.add( 0, "C" ); M. What is output by the following code? ArrayList<Character> nums = new ArrayList<Character>(); nums.add( 'a' ); nums.add( 'c' ); nums.add( 0, 'e' ); // first parameter is position to add at. nums.add( 'a' ); nums.add( 2, 'b' ); nums.remove( 3 ); for( Character c : nums ) System.out.print( c );CS 307 – Final – Fall 2007 4 For questions N and O consider an array based List class and the add method for that class. public class List{ private Object[] myCon; private int mySize; public void add(Object x){ if( mySize == myCon.length ) resize(); myCon[mySize] = x; mySize++; } //other methods not shown } The Big O of the System.arraycopy method is equal to the last parameter in the method call. N. Given the following resize method for the List class, what is the average case Big O of the add method for a list that contains N items? private void resize(){ Object[] temp = new Object[ (mySize * 3) / 2 ]; System.arraycopy(myCon, 0, temp, 0, myCon.length); //(source, source-pos, destination, dest-pos, num elements) myCon = temp; } O. Given the following resize method for the List class, what is the average case Big O of the add method for a list that contains N items? private void resize(){ Object[] temp = new Object[ mySize + 50 ]; System.arraycopy(myCon, 0, temp, 0, myCon.length); //(source, source-pos, destination, dest-pos, num elements) myCon = temp; }CS 307 – Final – Fall 2007 5 P. What is the T(N) of method hen ? Recall T(N) is a function that describes the actual number of executable statements in terms of the amount of data. Assume N = list.length. public void hen(int[] list){ for(int i = 0; i < list.length; i += 4) list[i] = list[i] * 2; for(int i = 0; i < list.length; i += 3) list[i] = list[i] / 2; } Q. What is output by the following code? Set<Integer> st = new TreeSet<Integer>(); st.add( 3 ); st.add( 2 ); st.add( 5 ); st.add( 2 ); st.add( 6 ); for(int i : st ) System.out.print( i ); R. Name a data structures that is typically used as the internal storage container when implementing a Stack. S. What is the


View Full Document

UT CS 307 - Final Exam

Documents in this Course
Midterm 2

Midterm 2

15 pages

Midterm 1

Midterm 1

15 pages

Syllabus

Syllabus

24 pages

s

s

8 pages

Midterm 1

Midterm 1

14 pages

Midterm 2

Midterm 2

14 pages

Recursion

Recursion

14 pages

Midterm 1

Midterm 1

16 pages

Load more
Download Final Exam
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Final Exam and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Final Exam 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?