Synopsys R&D Interview Question for Senior Software Development Engineers


Country: India




Comment hidden because of low score. Click to expand.
3
of 3 vote

If we are talking about a binary tree shape similarity, then the below code does it (descriptions inlined):

bool issame(node* root, node* root1)
{
    // special case when the two nodes are NULL at the same time
    if (root == root1)
        return true;
    
    // if we have differing shapes at this level    
    if ((NULL == root && NULL != root1)  
        || (NULL == root1 && NULL != root) )
        return false;
    
    // recurse into subtrees
    return (root->data == root1->data && issame(root->left, root1->left) &&  issame(root->right, root1->right));
}

- ashot madatyan June 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Good one. The below condition, however, needs a small change

if (root == root1 && root == NULL) // instead of if (root == root1) 
        return true;

- Murali Mohan July 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

What does this even mean?!

what kind of tree?
similar to what?
what does "structurally similar" mean?

- oOZz June 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think the question should be asking to check if two (binary) trees are structurally similar, in which case you can use recursion to solve the problem.

- Murali Mohan June 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Equal number of left and right nodes ?

- Sadhish June 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. do tree traversal
2. if any of them hits the NULL after the leaf node then chek for another one doing the same or not.

int  flag = 0;

bool  chekSimilatTree( tree1 root1, tree2 root2) {

if( (root1==NULL && root2!=NULL) || (root2==NULL && root1!=NULL) ) {

flag=1; return ;

}

if (root1==NULL && root2==NULL )

return ;

chekSimilarTree ( root1->left, root2->left);

chekSimilarTree( root1->right, root2->right );

if( flag==1 )

return false;

else  return true;

}

- Zzenith June 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

flag should be global

- anonymous June 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If structurally similar means : in binary tree the alignment of tree is same but values can be different then...

int strSimilar(struct node *root1,struct node *root2)
{
    if(root1==NULL && root2==NULL)
        return 1;
    if(root1==NULL || root2== NULL)
        return 0;
    return strSimilar(root1->left,root2->left) && strSimilar(root1->right,root2->right);

}

- Joey June 27, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More