Do a inorder traversal and store elements in HashMap with frequency update on encountering duplicates
public void duplicateNodes(Node head)
{
if(head==null) return;
if(map.containsKey(head.key))
{
map.put(head.key, Integer.parseInt(""+ map.get(head.key) + 1));
}
else
map.put(head.key, 1);
duplicateNodes(head.left);
duplicateNodes(head.right);
}
Map map1 = binarySearchTree.map;
Iterator it = map1.entrySet().iterator();
while(it.hasNext())
{
Map.Entry pairs = (Map.Entry)it.next();
if(Integer.parseInt(""+pairs.getValue()) > 1)
System.out.println("Dup Node " + pairs.getKey());
}