MIDTERM
CS203, Spring 2006


Please upload your source code and other files using CSNS at the end of the exam. Note that file uploading will be disabled automatically after 4:10PM, so please turn in your work on time. Before turn in your programs, try to compile and run them and make sure they work correctly. If your program does not even compile, you receive an automatic 50% credit deduction for that problem, no matter how "close" the program seems to be correct.

[Q&A] For the following questions, please put your answers in a text file midterm.txt or an MS Word file midterm.doc. For questions that could have multiple correct answers, giving one of the correct answers is enough.

1. (10pt) Given logN < N for any N > 1, prove 2000N*logN + 2N2 = O(N2).

2.

[Binary Search Tree]

Figure 1. A Binary Search Tree

a. (5pt) Suppose we want to insert values 1,2,3,4,5,6,7 into an empty binary search tree. How can we order the insertions so that after the insertions, the resulting tree will be identical to the one shown in Figure 1?

b. (10pt) After removing 4 and 5 from the tree shown in Figure 1 using the Remove algorithm discussed in the lecture notes, we traverse the tree in

For each case, list the nodes in the order in which they are visited.

[Programming] Consider an OrderedLinkedList class, which is similar to the DoubleLinkedList class we implemented in Homework 1, except that the nodes in the list are always sorted based on the value field in the ListNode class. Note that there is a class variable order in the OrderedLinkedList class, which indicates whether the nodes are sorted in ascending order or descending order. For this problem, you must complete the OrderedLinkedList class by implementing the following two methods:

(+30pt) For extra credit, rewrite the insert() method using recursion.