Create two hash sets and store elements both BSTs in them .
HashSet < Integer > s1 = new HashSet < Integer > ( ) ; HashSet < Integer > s2 = new HashSet < Integer > ( ) ; insertToHash ( root1 , s1 ) ; insertToHash ( root2 , s2 ) ;