CIS 2168 / 2: Lab-Assignment #6: Performance comparison of Arrays and Binary Search Trees
THIS IS A 1 WEEK ASSIGNMENT !
No graphics this time. Pure, simple, dry: data structure performance evaluation:
Build your own Binary Search Tree data structure class 'BST'. BST should contain:
The node-class NodeBST you have to provide consists of:
- field: NodeBST root; // the tree's root.
- method: public void insert(double v); // inserts a value into the tree
- method: public NodeBST find(double v); // finds a value in the tree and returns reference to node(or returns null)
- method: public void traversePre(); // traverses the tree in pre-order and prints the value of each node
- field: double value; // the node's value
- field: NodeBST ChildL; // left child
- field: NodeBST ChildR; // right child
- Insert the numbers 14,16,19,3,1,2,4,7 (in this order!) into the tree.
- make a test print using your traversePre() function. It must show the numbers in the following order: 14,3,1,2,4,7,16,19.
If it does not: go back to task 1 and fix your bug.
- check if your find routine works: call "NodeBST n = find(7)" and see if n.value == 7. If it isn't: go back to task 1 and fix your bug.
Check how fast the tree performs:
- for each number (14,3,..,19) call find() 10000 times and store the total time for all 80000 searches(time measure: see below).
- since i didn't try this: if it's too slow, try 1000 times, if it's too fast, try 100000 times for each number. print the result for each number
(e.g.: "10000 times searching for 14.0: xxx seconds")
- now store the numbers in an array, and do the same search in the array, also storing the time.
- compare the timing results (print total time for tree and array).
Check again how fast the tree performs, but this time the order of numbers is different:
- erase the old tree, and create a new tree inserting the same
numbers, but in a different order: 1,2,3,4,7,16,19
- perform the timing comparison of Task 3.
How to measure time in JAVA
The method "static long System.currentTimeMillis()" returns the current time in milli seconds. To check how long a task needs, call that function
before and after the task and store the time difference.