EFI interview question

How to find whether two trees are equal?

Interview Answers

Anonymous

30 Jan 2018

Wrote an algorithm and explained

Anonymous

7 Jul 2021

We can solve the answer through recursion. At each step we check if the parent element are equals or not & their left and right child are equals or not. def sameTree(t1, t2): if t1 is None and t2 is None: return True return sameTree(t1.root, t2.root) and sameTree(t1.left, t2.left) and sameTree(t1.right, t2.right)