If you implement their definition of "equality" with flip-invariance, you will violate the definition of equality. The definition doesn't even make sense, because that's not how binary search trees are equal (unless each node has a pointer to which subtree is "greater" and which is "lesser").
You have two choices of reasonable definitions:
topological (flip-agnostic) equivalence (in which case you can't call it a "binary search tree" because it's not sorted):
tree1==tree2
means set(tree1.children)==set(tree2.children)
normal search tree (flip-caring) equivalence:
tree1==tree2
means list(tree1.children)==list(tree2.children)
For binary trees, the above definitions will work as-written in any language which supports the list
and set
datatypes (python sets will choke however on unhashable datatypes). Nevertheless, below are some more verbose and ugly C/Java-like definitions:
topological equivalence:
t1==t2
means (t1.left==t2.left and t1.right==t2.right) or (t1.left==t2.right and t1.right==t2.left)
sorted tree equivalence:
t1==t2
means (t1.left==t2.left and t1.right==t2.right)
The definitions above are recursive; that is, they assume equality has been defined for the subtrees and base-cases already, which it has.
sidenote:
quote: tree1->child == tree2->child
This is not a valid statement, because a tree node does not have a single child.