Chronus Interview Question for Software Engineer / Developers






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

struct Node {
int *prev;
int *right;
int *left;
int value;
};
root Modified_BFS(Node *root){
    if(root == NULL) return;

    deque<Node *> q;
    Node *prev = NULL;
    q.push_back(root);
    
    while(!q.empty()){

       Node *r = q.pop_front();
       r->prev = prev;
       prev = r;
       
       if(r->left) q.push_back(r->left);
       if(r->right) q.push_back(r->right);
    }
}

- Dev August 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Please explain it .
thanks in advance :)

- codex September 02, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Almost right , but the left most node in a level will point to right most node of previous level ,,,

- iatbst January 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

make root->sibling=root and call this function:

void func(node *root)
{
if(node->left!=NULL && node->right !=NULL)
{
node->right->sibling=node->left;
node->left->sibling=node->right;
func(node->left);
func(node->right);
}
}

- lakshmi August 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void binary_tree::update_left_sibling()
{
queue<node *> * q1 = new queue<node *>;
queue<node *> * q2 = new queue<node *>;
queue<node *> * cur_q;
queue<node *> * other_q;
//ya parvar digar
node * first_popped ;
node * cur_node ;
q1->push(root);
// cur_q = q1;
while(!q1->empty()||!q2->empty())
{
if(!q1->empty())
{
cur_q = q1 ;
other_q = q2 ;
}
else
{
cur_q = q2 ;
other_q = q1 ;
}
first_popped = cur_q->front();
do
{
cur_node = cur_q->front();
cur_q->pop();
if(cur_node->child[1]!=NULL)
other_q->push(cur_node->child[1]);
if(cur_node->child[0]!=NULL)
other_q->push(cur_node->child[0]);
if(!cur_q->empty())
{
cur_node->left = cur_q->front();
//cur_node = cur_node->left;
//cur_q->pop();
}
}while(!cur_q->empty());
cur_node->left = first_popped;
}
}

- Abhinav Atul August 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void AddSibling( Node *root )
{
Queue<int> que;
Node *temp;
Node *previous = root;
Node *levelFirst = root;

que.push( root ); /* Enqueue */
que.push( NULL ); /* NULL serve as level delimitor */

while ( !que.empty() )
{
temp = que.pop() ;

if ( temp == NULL )
{
levelFirst->sibling = previous ;
que.push( NULL );
temp = que.pop();
levelFirst = temp;
}

temp.sibling = previous ;
previous = temp;

if (temp->left )
que.push( temp->left );
if (temp->right )
que.push( temp->right );

}
}

- iatbst January 25, 2012 | 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