Adobe Interview Question
Developer Program EngineersCountry: India
Interview Type: In-Person
levelBst(strcut node *root)
{
struct Queue *Q=CreateQueue();
if(!root)
retun;
Enqueue(Q,root);
Enqueue(Q,NULL);
while(!isEmpty(Q))
{
root=Dequeue(Q);
if(!root)
{
if(!isEmpty(Q))
Enqueue(Q,NULL);
}
else
{
printf("%d",root->data);
if(root->left)
Enqueue(Q,root->left);
if(root->right)
Enqueue(Q,root->right);
}
}
return;
}
Level order traversal in a binary search tree can be done using breadth first search with starting at root of the BST then it will print all the nodes in a level at one time. You can watch the solution and wonderful explanation of this at
- Anonymous July 03, 2012youtu.be/5pNIul92cj0