The questions below are some sample problems to help you prepare for the final. While they are representative of the types of questions that will be answered they are not necessarily comprehensive in covering all of the material that could be covered (for example, there are no graph questions below). T/F: - A binary tree with $n$ nodes has at most height $O(\log_2 n)$ - searching for a value in binary tree is $O(\log_2 n)$ - balanced binary trees make sure that the height of the tree is $O(\log_2 n)$. - Heapsort is always $O(n \log_2 n)$ - Comparison-based sorting methods are $\omega(n \log n)$. - A complete graph is connected. - Assume we have some method that has checked that two binary trees have the same tree structure. We'd like to write a method called equalValues that takes two binary trees that are structurally the same and see if they contain the same values. You may assume the standard binary tree methods are available, such as isEmpty(), accessor methods, etc. public static boolean equalValues(BinaryTree t, BinaryTree t2) // solution public static boolean equalValues(BinaryTree t1, BinaryTree t2){ if( t1.isEmpty() ) return true; } else if( data.equals(t.data) ){ return equalValues(t1.left(), t2.left()) && equalvalues(t1.right(), t2.right()); }else{ return false; } } - write a method for a binary search tree that takes a value and an ArrayList and populates the ArrayList with all data items in the tree that are less than the value passed in. Assume that the data item stored in the tree is a string and that the strings are unique. - which of the following are valid heaps? - draw the heap corresponding to the following array - Insert the following keys into a hashtable using linear probing - Assuming that BinaryTree t is a full binary search tree and that it is not a leaf, what does the method below do? public static String mystery(BinaryTree t){ BinaryTree temp = t.right(); while( !temp.left().isEmpty() ){ temp = temp.left(); } return temp.data(); } - C++ - why do we need pass-by constant reference? - Write a C++ method greaterThanCount which takes two an int value and a vector or ints that returns the number of entries in the vector that are greater than the value passed in. Make sure to use appropriate parameter passing. - The following code has two errors (a compiler error and a logic error). What are they?: void print(const vector& v){ for( vector::iterator it = v.begin(); it != v.end(); it++ ){ cout << it << endl; } } - The following C++ code attempts to calculate the nth fibonacci number but has two errors. What are they? int fib(const int n){ vector v = new vector(); v.push_back(1); v.push_back(1); n = n - 2; while( n >= 0 ){ int size = v.size(); v.push_back(v[size-1] + v[size-2]); n--; } return v[v.size()-1]; } Are code segments A and B equivalent? A: public void method(MyObject* a, MyObject* b){ a = b; } MyObject a; MyObject b; // some more code method(&a, &b); \end{verbatim} B: public void method(MyObject& a, MyObject& b){ a = b; } MyObject a; MyObject b; // some more code method(a, b);