{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
Points off 1 2 3 4 Total off Net Score CS 307 – Final – Fall 2005 Name__________________________________________ UTEID login name _______________________________ TA’s Name ___________________________ Instructions: 1. Please turn off your cell phones. 2. There are 4 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 1. (2 points each, 40 points total) Short answer. Place you answers on the attached answer sheet. 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”. Recall that when asked for Big O your answer should be the most precise Big O function. For example Selection Sort has an average 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 precise 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. 72, 33, 9, 12, 38, 101 CS 307 – Final – Fall 2005 1
Image of page 1

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

View Full Document Right Arrow Icon
For parts B - F 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. What is the output of a level order traversal of the above tree? F. Is the binary tree shown above a binary search tree? G. If 1000 elements are inserted into a Binary Search Tree using the naïve insertion algorithm, what is the expected (average case) height of the resulting tree? (The height of a tree is the number of links from the root to the deepest leaf. The height of the tree on this page is 3.) CS 307 – Final – Fall 2005 2 root of tree 37 13 17 9 77 97 70 75 85
Image of page 2
Recall the following methods from the ArrayList class: boolean add (Object x) Add x to the end of list. returns true . Object set (int index, Object x) Replaces the element at the specified position in this list with the specified element. void add (int index, Object x) Inserts x at position index , sliding elements at position index and higher to the right (adds 1 to their indices) and adjusts size Object remove (int index) Removes element from position index , sliding elements at position index + 1 and higher to the left (subtracts 1 from their indices) and adjusts size returns the element formerly at the specified position Object get (int index) return the element at the given index H. What is the output of the following code?
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern