You are on page 1of 6

Data Structure Questions & Answers

1)Consider the following structure struct node { int info; struct node *link; }; Suppose ptr is a pointer which is not pointing to the first or the last node. Then if we are going to delete a node after ptr, then the code will be a) ptr=ptr->link; b) ptr->link=ptr; c) ptr->link=ptr->link->link; d) ptr=ptr->link->link;

2) Consider the following structure struct node { int info; struct node *link; }; Suppose start is a pointer pointing to the first node of the linked list. s1 and ptr are the two pointers (they are not pointing to the first or last node). Then if we are going to execute the following code, i) start->link=s1; ii) s1->link=ptr; iii) ptr->link=start; then the list is a) It is having only 3 nodes with start, s1, ptr in the list, having start as the first node b) It is a circular linked list c) It is a doubly linked list d) None of the above

3) In a queue, if rear=front then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) None of the above 4) In a queue, if rear=0, front=0 then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) None of the above 5) a) b) c) d) In a queue, if rear=0, front=1 then what will be the queue Queue is empty Queue is full Queue has only one element Queue is circular

6) In a queue,if rear=-1,front=-1 then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) None of the above 7) In a queue, if rear=max-1, front=0 then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) None of the above 8) The postfix expression is ab+c*d/e-.The values of a, b, c, d, e are 2, 4, 5, 2, 1 respectively. Then the output is a) b) c) d) 14 11 20 15

9) The infix expression is a+b*(c-d)/(e+f)*h then my postfix expression is a) ab+cd-*ef+h*/ b) abcd-ef+*/h* c) abcd-*ef+/h*+ d) abcdef+-*/h*+ 10) In the stack, if top=0 then the stack is a) Stack is empty b) Stack is full c) Stack has only one element d) None of the above

11) Consider the structure struct node { int info; struct node *left; struct node *right; }; We have 10 elements in the list. If the following executes what will be the output? for(ptr=start; ptr; ptr=ptr->right) { if(ptr->data%2==0) printf("%d", ptr->data); } a) Only even numbers are printed b) Only odd numbers are printed c) Compiler error d) Only garbage values 12) struct node { int data; struct node *left,*right; };

Suppose nd is a node which is not in the beginning and also not in the end. How will you delete a node after nd? a) nd->right=nd->right->left;nd->right->left=nd->left->right; b) nd->right=nd->right->right;nd->right->left=nd; c) nd->right=nd->right->left;nd->right->left=nd->right; d) nd->right=nd->left->right;nd->left->right=nd;

13)

struct node { int data; struct node *left,*right; };

Suppose nd is a node which is not in the beginning and also not in the end. How will you delete a node before nd? a) nd->left=nd->right->left;nd->right->left=nd->left->right; b) nd->left=nd->right->right;nd->left->right=nd->right; c) nd->left=nd->left->left;nd->left->right=nd; d) nd->left=nd->left->right;nd->left->right=nd; 14) struct node { int data; struct node *left,*right; };

Suppose ptr is a node which is not in the beginning and also not in the end. How will you delete a node ptr? a) ptr->left->right=ptr->right;ptr->right->left=ptr->left;free(ptr); b) ptr->left->right=ptr->right->right;ptr->left->right=ptr->right;free(ptr); c) ptr->left->right=ptr->left->left;ptr->left->right=ptr;free(ptr); d) ptr->left->right=ptr->left;ptr->left->right=ptr->left;free(ptr);

15)

struct node { int data; struct node *left,*right; };

Suppose ptr is a node which is not in the beginning and also not in the end. nd is the new node. Here is the coding: i) ptr->right->left=nd; ii) nd->left=ptr; iii) ptr->right=nd; iv) nd->right=ptr->right; Then what sequence does it follows for inserting nd after ptr? a) i,ii,iii,iv b) ii,iv,i,iii c)iv,iii,ii,i d) ii,iii,i,iv 16) In the Given Infix expression which is the root node for your expression tree (A+B)-(C*D)+G/H*I a) + b) c) * d) /

17) Consider a binary search tree insert(10,root); insert(25,root); insert(5,root); insert(8,root); insert(13,root); insert(45,root); insert(70,root); insert(32,root); delete(13,root);

insert(66,root); insert(13,root); insert(36,root); What will be the preorder traversal is a) 5,8,10,13,25,32,36,45,66,70 b) 10,5,8,25,13,45,32,36,70,66 c) 10,8,5,13,32,45,36,66,32,70 d) 8,5,32,36,10,66,45,70,25,13

19) The preorder traversal is 5, 3, 66, 30, 77, 70 .What will be the root node a) 5 b) 66 c) 70 d) 30 20) Which one of the following is true for the binary tree i) root is greater than the left sub tree and lesser than the right sub tree ii) root is lesser than the left sub tree and greater than the right sub tree a) only i b) only ii c) both i and ii d) Neither i nor ii

You might also like