Loading...
Engaged Employer
Code to check if a Binary tree is symmetrical.
Anonymous
Try something like huffman coding. 0 for left, 1 for right. Traverse and check for palindrome :D
Or you could prepare a string representation of the in order transversal, a symmertrial BST will have a palindrom-ic string representation.
typedef struct _Tree { struct _Tree *left, *right; ... } Tree; int count_nodes(Tree *t) { if (t == NULL) return 0; return 1 + count_nodes(t->left) + count_nodes(t->right); } int is_symmetrical(Tree *t) { if (t == NULL) return 1; return is_symmetrical(t->left) && is_symmetrical(t->right) && count_nodes(t->left) == count_nodes(t->right); }
Check out your Company Bowl for anonymous work chats.
Get actionable career advice tailored to you by joining more bowls.
Stay ahead in opportunities and insider tips by following your dream companies.
Get personalized job recommendations and updates by starting your searches.