Saturday, May 15, 2010

Data structure interview questions Part 11

Data structure interview question:What do you mean by: Syntax Error, Logical Error, Run time Error?  
Answer:
Syntax Error-Syntax Error is due to lack of knowledge in a specific language. It is due to somebody does not know how to use the features of a language.We can know the errors at the time of compilation.logical 
Error-It is due to the poor understanding of the requirement or problem.
Run time Error-The exceptions like divide a number by 0,overflow and underflow comes under this.

Data structure interview question
:What is the maximum total number of nodes in a tree that has N levels? Note that the root is level (zero).
Answer:2^(N+1)-1..

if N=0; it is 2-1=1,1 is the max no of node in the tree

if N=1; it is 4-1=3, 3 is the max no of nodes in the tree
if N=2; it is 8-1=7, 7 is the max.

Data structure interview question:Explain about the types of linked lists?
Answer:Their are three linked lists1)linear or simple linked lists2)doubly linked lists3)circular linked listssimple linked list :This contains a node which has two parts, see that a node is a STRUCTURE.one is data and other one is a pointer which is called self reference pointers, so we must make it to point to the next location of second node created dynamically.double linked lists :A node will consists of previous node address , a data & next node address which can move backwards to the very first address.circular linked list :Here we will have the node consists of same thing but default when it finishes the last node and come to the first node.

Data structure interview question:What are the parts of root node?  
Answer:A root node contains data part and has link part. i.e links to its child. If it is binary tree it has two links i.e left child and right child.

Data structure interview question:How will inorder, preorder and postorder traversals printthe elements of a tree?
Answer: 
voidinorder(node * tree) 
{
 if(tree!=NULL)
 { 
inorder(tree->leftchild); 
printf("%d",tree->data); 
inorder(tree->rightchild);
 } 
else
return; 
} 
void postorder(node * tree) 
{ 
if(tree!=NULL) 
{ 
postorder(tree->leftchild); 
postorder(tree->rightchild); 
printf("%d",tree->data);
 } 
else
return; 
} 
void preorder(node * tree)
 { 
if(tree!=NULL) 
{ 
printf("%d",tree->data); 
preorder(tree->leftchild); 
preorder(tree->rightchild); 
} 
else 
return; 
}

No comments:

Post a Comment