Let us create trees shown in above diagram
n1 = Node ( 1 ) NEW_LINE n1 . left = Node ( 2 ) NEW_LINE n1 . right = Node ( 3 ) NEW_LINE n1 . left . left = Node ( 4 ) NEW_LINE n1 . left . right = Node ( 5 ) NEW_LINE n1 . right . left = Node ( 6 ) NEW_LINE n1 . left . right . left = Node ( 7 ) NEW_LINE n1 . left . right . right = Node ( 8 ) NEW_LINE n2 = Node ( 1 ) NEW_LINE n2 . left = Node ( 3 ) NEW_LINE n2 . right = Node ( 2 ) NEW_LINE n2 . right . left = Node ( 4 ) NEW_LINE n2 . right . right = Node ( 5 ) NEW_LINE n2 . left . right = Node ( 6 ) NEW_LINE n2 . right . right . left = Node ( 8 ) NEW_LINE n2 . right . right . right = Node ( 7 ) NEW_LINE print " Yes " if ( isIsomorphic ( n1 , n2 ) == True ) else " No " NEW_LINE