Question: I was able to do the class OrderedKeyVakue but I'm still confused with the BST. To clarify, the keys are words that we have in
I was able to do the class OrderedKeyVakue but I'm still confused with the BST. To clarify, the keys are words that we have in different files, so we need to tokenize the words in the files in order to know the number of times a word appears. The words should appear in alphabetical order and the value would be the number of times that word appeared throughout the files. Example: Word car: 23 times I will rank you as a LIFESAVER!
[Java - Balanced / Unbalanced Trees]
In this section, you need to first implement a class OrderedKeyValue to store an ordered pair of a String key and its Integer value. Then, you should implement the class Unbal- ancedTreeMap which stores objects of class OrderedKeyValue in the unbalanced binary search tree.
Class OrderedK/eyValue implements Comparable must include the following members: 1. String key; 2. int value; 3. A constructor for creating a new object with key and value initialized by the input parameters. 4. int comareTo(Object o) that implements Comparable interface by comparing the keys of two OrderedKeyValues based on the alphabetical order and in a case-insensitive way.
Class UnbalancedTreeMap must include the following members: 1. BinaryNode root; you can define BinaryNode class with the following instance fields:OrderedKeyValue keyValue; BinaryNode leftChild, and BinaryNode rightChild The binary search tree that you're supposed to construct uses the instances of BinaryNode as its nodes.
2. A constructor to create an empty tree map; 3. public int get(String key): searches through the tree to see whether any node stores an object of OrderedKeyValue which matches the input key. If such OrderedKeyValue is found, the method returns its value; otherwise, it returns 0. 4. public int put(String key, int value): searches through the tree to see whether any node stores an object of OrderedKeyValue which matches the input key. If such Ordered- KeyValue is found, the method sets its value to the one given by the second input parameter and returns the previous value as the method output; otherwise, it inserts a new node to the tree to store the given key and value and returns 0.
5.public String [] keySet(): By visiting the nodes of BST using in-order traversal, you should store the keys in an array of strings and return the array at the end. The return array contains all the keys in alphabetical order.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
