Hy there, i’m new in java and I need to implement a dictionary over a Binary Search Tree but I really have no idea where to start from.
I have to store in this dictionary some Students having a name and age.
So in the BST i will store the ages but where do I store the name of the student and how do I connect a name with a age field.
I would appreciate if you have an exemple of implementation for something like this, not necessairly all the code, but just the begining, so I cand start. If you don’t have it in java, a c++ code is also good.
A dictionary is a datastructure that maps keys to values and allows querying the value for a given key. A binary search tree also has keys (which are used for the search) and can also have further payload data (the values). So a BST with payload data is actually already a dictionary.
So, start by writing a usual BST implementation (cf. Wikipedia for simple implementations, e.g., http://en.wikipedia.org/wiki/Binary_search_tree). Add a payload attribute to the nodes. Add a function
lookup(key)that will first search the node with keykey(using usual BST lookup) and return the payload attribute of that node. Et voila, there you have your dictionary.