EFI Interview Question

How to find whether two trees are equal?

Interview Answers

Anonymous

Jan 30, 2018

Wrote an algorithm and explained

Anonymous

Jul 7, 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)