{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Sp10Final - Points off 1 2 3 4 5 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
CS 307 – Final – Spring 2010 1 Points off 1 2 3 4 5 Total off Net Score CS 307 – Final – Spring 2010 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, correct 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.) 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. 37 42 13 101 -12
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
CS 307 – Final – Spring 2010 2 Consider the following binary tree. 17 is the root of the tree. 17 / \ 19 20 \ \ 25 30 / / \ 10 7 15 B. What is the result of a pre-order traversal of the binary tree shown above? C. What is the result of a in-order traversal of the binary tree shown above? D. What is the result of a post-order traversal of the binary tree above? E. Is the tree shown above a binary search tree? F. On the answer sheet, fill in the nodes of the given binary tree with integer values between 1 and 10 to make the tree shown a binary search tree. G. What is the result of the following postfix expression? For subtraction the operand closest to the subtraction symbol is the infix equivalent of the right hand side operand. 10 5 11 3 - + * H. What is output by the following code? String data = "BINARY"; Stack<Character> st = new Stack<Character>(); for(int i = 0; i < data.length(); i++) st.push( data.charAt(i) ); st.pop(); st.pop(); for(int i = 0; i < 3; i++) System.out.print( st.pop() ); I. What is the Big O of method total ? N = list.size() public int total(LinkedList<Integer> list) { int total = 0; for(int i = 0; i < list.size(); i++) total += list.get(i); return total; }
Image of page 2
CS 307 – Final – Spring 2010 3 J. What is the worst case Big O of printRev ? Assume the println and length methods are O(1). N = list.size() public void printRev(ArrayList<String> list) { for(int i = list.size() - 1; i >= 0; i--) if(list.get(i).length() < 5) System.out.println(list.get(i)); } K. What is the Big O of method empty if list is a Java LinkedList ?
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