I came up with an algorithm to check if two trees are structurally similar i.e. the data at the corresponding nodes in the two trees may be different but if a node in tree1 has one left child then it's corresponding node in tree2 must have one left child as well.
Algorithm(node * root1, node * root2) :
1. Create 2 queues Q1,Q2 and enqueue root1 and root2.
2. while(Q1 and Q2 are not empty)
2.a temp1 = deQ(Q1);
2.b temp2 = deQ(Q2);
2.c if temp1 has left child then enqueue temp1's left child in Q1
2.d if temp2 has left child then enqueue temp2's left child in Q2
2.e if temp1 has right child then enqueue temp1's right child in Q1
2.f if temp2 has right child then enqueue temp2's right child in Q2
2.g now check if the size of Q1 and Q2 is equal
2.h if the size is equal then continue else the two trees are not similar
3. End
Is this algorithm correct?