Espresso: A Concentrated Introduction to Java
Summary: In this laboratory, you will have an opportunity to enhance your understanding of the dictionary by exploring two implementations of dictionaries: a simple, array-based implementation and, more importantly, a form of binary search tree.
Contents:
Required Code Files:
NewDict.java (the interface)
NewDictTester.java (a generic tester for NewDict)
ArrayBasedNewDict.java (an array-based implementation of NewDict)
TestABND.java (a tester for ArrayBasedNewDict)
BST.java (a binary-search-tree implementation of NewDict)
BSTNode.java (the nodes for BST)
TestBST.java (a tester for BST)
a. Create a package named
username.dict.
b. Put all of the files linked above in that package.
c. Make sure to change the package name in each file.
Read through
NewDict.java.
a. What purpose does I serve in this interface?
b. What purpose does V serve in this interface?
c. What other methods would you suggest adding to the interface?
Look at
ArrayBasedNewDict.java, an array-based implementation of NewDict.
a. Describe, in your own words, how this implementation works.
b. What is the purpose of find in this code?
Look at
NewDictTester.java, a generic tester for NewDict, and
TestABND.java, a tester customized for ArrayBasedNewDict.
a. Explain what the tests do.
b. Compile and run TestABND and confirm that it
produces the results you expect.
Give an approximate but close upper bound on the running time
of put and get.
Sketch an algorithm that one could use to delete an element from the dictionary. (You can assume that we provide only the index as a parameter to this method.)
Look at
BST.java and
BSTNode.java.
a. Explain the differences between the two classes.
b. Explain, in your own words, how binary search trees are structured.
a. Sketch the binary search trees that would be created by adding the following lists of indices (each list creates a separate tree, assume the elements are added in order).
b. Is there a better or worse order to put values into a binary search tree?
c. Estimate the running time of put and get
in terms of the number of elements in the tree or the depth of the
tree.
Look at
NewDictTester.java, a generic tester for NewDict, and
TestBST.java, a tester customized for binary search trees.
a. Explain what the tests do.
b. Compile and run TestBST and confirm that it
produces the results you expect.
a. Write a new tester for binary search trees that lets you specify the index on the command line and then prints out the try. Assume that the value associated with each index is the uppercase version of that index. For example, we might use this tester as follows.
ji NewTestBST d a b c e d => D L a => A L R b => B L R R c => C R e => E
b. Use the tester to check your answers from exercise 7.
As you may have noted, binary search trees only work well when elements are split nearly evenly between subtrees. (Similarly, each subtree should have about the same number of elements in each of its sub-subtrees, and so on and so forth.)
Design (but do not implement) a strategy for keeping the number of elements in each subtree approximately equivalent.
a. Design (but do not implement) a strategy for deleting indices from binary search trees.
b. Starting with a mostly balanced tree of size 9, see what happens if you repeatedly delete the index at the root using your strategy.
Monday, 11 April 2005 [Samuel A. Rebelsky]
Tuesday, 12 April 2005 [Samuel A. Rebelsky]
Wednesday, 13 April 2005 [Samuel A. Rebelsky]
extra timequestions.
This page was generated by
Siteweaver on Thu Mar 30 15:24:34 2006.
The source to the page was last modified on Wed Apr 13 11:18:12 2005.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Espresso/Labs/bst.html.
You may wish to
validate this page's HTML
;
;
Check with Bobby