Amazon Interview Question

How would you test if a binary tree were symmetrical and balanced.

Interview Answers

Anonymous

Apr 5, 2011

Could you please elaborate on your solution. I was thinking you can do an inorder traversal and then compare the result with 2 pointers starting from the extreme ends. Is that what you are suggesting ?

Anonymous

Apr 5, 2011

Well, the tree has to be balanced and symmetrical, so after the head node, the left must equal right on down. 1 2 2 3 4 4 3 78 67 76 87 I think my answer detected this, but he asked if I thought there were any problems with my answer and I couldn't think of any, but he sure seemed to!

Anonymous

Jun 15, 2011

I don't see any mention in your answer of checking whether it's balanced. Is that what you were missing?

Anonymous

Mar 18, 2011

Recursion, test if left->right equal to right->left, for example.

1