To check if tree has duplicates
public static Boolean checkDup ( Node root ) { HashSet < int > s = new HashSet < int > ( ) ; return checkDupUtil ( root , s ) ; } public static void Main ( String [ ] args ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 2 ) ; root . left . left = new Node ( 3 ) ; if ( checkDup ( root ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }