## CS:3330:001 Algorithms Project 2: Due 10/22/2019

Computer Science is both a theoretic and experimental science. Theoretic analysis tells us whether an algorithm is efficient or not in theory. Experiments can help us to identify whether an idea is useful or not in practice. To conduct an experiment, we may learn from how a clinical trial is conducted. Basically, you need to use random examples, not to choose examples in your favour, and compare different ideas in the same environment.

In this project, we will study binary search trees. To help you get started, we provide the following java code bst.zip which contains the implementations of normal binary search tree (treeNode.java), AVL tree (avltree.java), red-black tree (redblacktree.java), and splay tree (splaytree.java). Study these codes and have them run on your computer is the first step of your project.

• The following methods in treeNode.java
```       public treeNode predecessor( int x )
public treeNode successor( int x )
```
are not implemented. Please complete the implementation of both methods.

A recursive version of the insert and remove methods are given in treeNode.java. Please provide a non-recursive implementation of both the insert and remove methods and name the new methods as insert1 and remove1 (see find0 and find for an example of recursive and non-recursive implementations). Please create a method called question1 in the style of question0 in bst.java, to compare the performances of both recursive and non-recursive methods by running them on the same set of 500 examples with 5,000,000 mixed operations as shown in the method question0 (and used by test) in bst.java. Summerize the total running times for both cases and draw your conclusions from the experiment.

• You are asked to create the method question2 in bst.java to compare the performances of AVL tree, red-black tree, and splay tree by running them on the same set of 100 examples with 5,000,000 mixed operations as we did in the method question0 (and used by test) in bst.java. Summerize the total running times for each tree and draw your conclusions from the experiment.

• Suppose we want to sort the array keys[] in bst.java by using binary search trees. That is, we will insert each number in keys[] into a search tree and then vist the tree in in-order traversal, collecting the numbers along the way into another array, say res[] (you may reuse ops[] in bst.java for res[]). To fulfil this goal, you are asked to provide the method inorder in treeNode.java, with the interface
```           public int inorder(int i, int[] res)
```
where i is the first position available in res[], and the method inorder returns the next available position in res[] after it adds all the numbers in the subtree rooted by the current (this) node into res[]. In a similar way as in the method test, create another method in bst.java with the following interface:
```           public static void sort(int[] keys, int[] res, long[] times)
```
which collects the running time of creating a binary search tree (i.e., avl, rbt, or spt), inserting all N keys in keys[] into the tree and collecting all numbers in the tree in the sorted order into res[]. Create 100 arrays of random numbers of size 500,000 to test the performance of each tree, summarize the total running time (the same set of arrays is used by each tree). You are asked to create the method question3 to contain the code for collecting running times in bst.java.

For all the tasks, please give a summary of your experiments and draw conclusions from the experimental data.

Submit everything in the ICON dropbox for Project 2 before the deadline.

Thank you!