I have an AVL tree, in which I have to find the closest pair, as in the values of the two nodes that have the least difference. No duplicate values, and has to be completed under O(log n).
Example: Insert(9),Insert(2),Insert(14), Insert(10).
The closest pair in this tree is (9,10).
But I am unsure how to implement this.
I only know that, each node's closest pair can be calculated by by taking the minimum of the largest value on the left and the node, or the smallest value on the right. But if I were to calculate this for every node it will be over logn for sure.
Any ideas?
Edit: forgot to mention that I am designing the insert function myself, so I can make changes to each node so it can contain more info, in regard of the closest pair function