The get method returns the value associated with a key or null if the key is not in the BST.
To compute the value associated with a key in a BST:
- If the BST is empty, return null
- Else compare key with the root node
- if key is smaller than root.key, the key has to be in the left subtree if it is present. So get the value from the left subtree.
- else if the key is greater than root.key, the key has to be in the right subtree if it is present. So get the value from the right subtree.
- else key is equal to root.key, so the value is root.val.