0

Data structure

Description: Data structure questions for GATE aspirants
Number of Questions: 25
Created by:
Tags: Data-Structure Programming and Data Structures Computer Science & Information Technology - CS
Attempted 0/25 Correct 0 Score 0

How many null branches are there in a binary tree with 20 nodes?

  1. 5

  2. 21

  3. 18

  4. 22


Correct Option: B
Explanation:

A binary tree with n nodes has exactly n+1 null nodes. So, if number of nodes are 20 then number of null nodes will be 21. So, 21 is correct.  

The total number of binary trees possible with three unlabelled nodes is

  1. 5

  2. 6

  3. 7

  4. 8


Correct Option: A
Explanation:

Follow the following formula to calculate number of nodes.2nCn / (n+1) where n is the number of nodes.2*3C3 / (3+1)=5

Which one of the following sorting algorithms is using divide and conquer method?

  1. Bubble sort

  2. Selection sort

  3. Quick sort

  4. All of the above


Correct Option: C
Explanation:

Quick sort choose one element and divide the list into two. It uses divide and conquer method. A key element is chosen then it is compared and the element is placed in such a way that all smaller elements as compared to key are on one side and larger than key are on other side. Then likewise list is broken into two, again algorithm is applied.

For height H and root at level 0, how many number of nodes will be there in a binary tree?

  1. 2H+1 - 1

  2. 2H-1

  3. 2H+1 + 1

  4. 2H+1


Correct Option: A
Explanation:

2H+1 - 1, gives total number of nodes present in any binary tree for tree at level 0. 2H gives the total number of nodes at any level. If root is at level zero, 2H+1 will give the same, e.g. at level 3, total no. of nodes will be 8 and total number of nodes at level 2 if root is at level 0, is 7. So this relation works here 2H+1 - 1.

For static memory location which of the following data structures is used?

  1. Stack

  2. Link list

  3. Tree

  4. Graph


Correct Option: A
Explanation:

  For static memory location, stack is used. Stack is used because size of memory is known.

Insert the following elements as binary search tree, 10, 11, 12, 13, 14, 15, 16, 17 and build AVL tree.

  1. 15

  2. 14

  3. 13

  4. 16


Correct Option: B
Explanation:

While inserting the element make sure the difference of height of  left subtree and right sub tree must be -1, 0 and +1. Insert 10 as a root, then 11 as right child. Here, tree is balanced. Now Insert 12, tree became unbalanced as the height of left sub tree from root and right sub tree is -2, 0 = -2. So do RR rotation on tree. Now 11 is as root and 10 as left child and 12 as right child. Again insert 13 as left child of 12, then 14 right child of 13 again it unbalanced. So do again RR rotation and so on.

Which of the following data structures allows deletion of element from both the ends and insertion at only one end?

  1. Stack

  2. Priority queue

  3. Input restricted queue

  4. Output restricted queue


Correct Option: C
Explanation:

Input restricted queue allows input data from one end, and delete data from both ends.

In-order traversal of a tree will yield a sorted list of elements of tree in

  1. binary trees

  2. binary search trees

  3. heaps

  4. None of the above


Correct Option: B
Explanation:

Binary search tree has all the small data in left and all big data in right. So, when inorder traversal is made, it gives sorted list. Suppose tree is having data 1, 2, 3, 4 and 5, if 3 is the root element then 4 and 5 will be on right side of the root. 1 and 2 will get place in left side of 3. So, inorder traversel of BST will give sorted elements.

For height H and root at level 1, how many number of nodes will be there in a binary tree?

  1. 2H - 1

  2. 2H+1

  3. 2H+1 - 1

  4. None of the above


Correct Option: A
Explanation:

2H - 1, gives total number of nodes present in any binary tree. 2H gives the total number of nodes at any level. So for height H, total number of nodes will be one less than next level. For example at level 3, the number of nodes is 8, for height 3 the total number of nodes is 7. This is the way how this expression works.

Which of the following data structures is used to perform recursion?

  1. Queue

  2. Stack

  3. Tree

  4. Linked list


Correct Option: B
Explanation:

Stack is used to perform recursion. It stores the function call in stack. then call each function in LIFO order. Let a function is called from its own body then for to track the function call, each call is pushed into stack till the end of counter then one by one each function call is executed. So, stack is a correct answer.

Identify the correct sequence for stack, if the input sequence is 1, 2, 3, 4 and 5.

  1. 4, 3, 5, 1 and 2

  2. 4, 3, 5, 2 and 1

  3. 5, 4, 1, 2 and 3

  4. 5, 4, 3, 1 and 2


Correct Option: B
Explanation:

In stack, the element is inserted in last which should be taken out first. For example, for sequence 4, 3, 5, 2 and 1, first insert 1, 2, 3, 4 then take out 4 and 3; here stack content is 2 and 1, again insert 5 and take out 5, 2 and 1. After insertion of 5 stack content is 5, 2, 1 then take out 5, 2 and 1. At last, we got the sequence 4, 3, 5, 2 and 1.

Which of the following data structures is used for locating memory at run time?

  1. Stack

  2. Queue

  3. Heap

  4. Link list


Correct Option: C
Explanation:

 For run time memory location, heap is used. As we don't know the size of memory required to allocate. So, heap is used to allocate memory.

Calculate the number of distinct trees possible for 5 unlabelled NODE.

  1. 34

  2. 39

  3. 42

  4. 45


Correct Option: C
Explanation:

2nCn/n+1 where n are the number of nodes.  2nCn/n+1 where n are the number of nodes. For 3 unlabelled nodes it will work as follows 2*3C3 / 4= 6C3 / 4. So on solving this we get 5, and answer for 5 unlabelled nodes will be 42, so answer 42 is correct.

Which of the following is not self referential structure?

  1. Link list

  2. Graph

  3. Tree

  4. Stack


Correct Option: B
Explanation:

The data structure which is used to manipulate data is called self referential structure. Graph is a self referential structure. So answer is correct as in Graph structure, we cannot refer all the vertices in some order.

A link list contains following items:

The first item in link list is A, second is B, third is C, fourth is D and fifth is E. Here, A is pointing to B, B is pointing to C, C is pointing to D and D is pointing to E and E is the last item. Its link part contains NULL. What will be the output after the following sequence of steps? (First is the pointer pointing to first element)

  1. struct NODE*P;
  2. P=First->next->next;
  3. First->next->next=P->next;
  4. P->next->next=P;
  5. printf(%d,First->next->next->next->info);
  1. C

  2. A

  3. D

  4. E


Correct Option: A
Explanation:

In link list, when value is assigned, its link part is updated. As after step 2, P is pointing to C, after third step, B is pointing to D, after 4th step, D's link is updated with C and in 5th step, P is pointing to C, so C will be printed. In linklist when value is assigned, Its link part is updated.

As After step 2 P is pointing to C.After third step B is pointing to DAfter 4th step D's link is updated with CAnd 5th step P is pointing to C So C is printed.

Calculate the minimum number of nodes in AVL tree where height (H) is 8 and root at level 1.

  1. 56

  2. 54

  3. 58

  4. 64


Correct Option: B
Explanation:

N(H min)=1+N(H-1)+N(H-2). For N(1)=1, for N(2)=2 , for N(3)= 1 + N(2 )+ N(1), it will become 1+2+1 = 4 and so on. So for N(8) it will be 54 and answer 54 is correct.  

If A [2] [2] [2] contains element 1 2 3 4 5 6 7 8. Then A [0] [0] [1] contains which element?

  1. 1

  2. 2

  3. 4

  4. 7


Correct Option: B
Explanation:

Three dimensional array consists of 2D array. First 2 is indicating there are two matrices. So A(0)(0)(1 ) is indicating to 2. A(1)(1)(1) can be written as (((*a +1)+ 1)+1 ), so A(0)(0)(1 ) is referring to second memory location, which is 2. So option as 2 is correct.

From which end of queue, elements are deleted?

  1. Front

  2. Rear

  3. Top

  4. None of the above


Correct Option: A
Explanation:

In queue, deletion takes place from front end, and rear end is used to insert the element into queue. So this option is correct one.

In stack, insertion of element takes place from which end?

  1. Front

  2. Rear

  3. Top

  4. None of the above


Correct Option: C
Explanation:

In stack, insertion and deletion takes place from top.

The In-order traversal of a tree is given as B C A E D F and pre-order traversal of tree is given as A B C D E F. What will be the post order traversal order?

  1. C B F E D A

  2. C B E F A D

  3. B C F E D A

  4. C B E F D A


Correct Option: D
Explanation:
  1. In POST order traversal, first traverse left, then right and then print node. 2. If the sequence to traversal is given then it is easy to predict the tree. In preorder, the node which is traversed first is the root of the tree. So, here A is the root. Now take each node from preorder list and now from list in order the node which is right side of A is right and the node which is on left will come in left. Now traverse one by one each element from the list and make a tree and then find post order traversal from first step. On traversing the tree, we get following sequence for post order: C B E F D A. So the option C B E F D A is correct.

In queue, from which end elements are inserted?

  1. Front

  2. Rear

  3. Top

  4. None of the above


Correct Option: B
Explanation:

In queue, deletion takes place from front end, and rear end is used to insert the element into queue. So this option is correct.

If a binary search tree contains numbers and tree is traversed in order then in which order, numbers will be printed?

  1. Ascending order

  2. Random order

  3. Descending order

  4. None of the above


Correct Option: A
Explanation:

 It will be printed in ascending order as a root node has all the smaller elements in its left side and all the larger elements in its right side. Likewise it is arranged for each node, always left child is smaller and right child is larger. So, it will arrange all elements in ascending order. So it is correct option.

If a binary tree contains either two or zero children, then it is called as

  1. strictly binary tree

  2. binary tree

  3. AVL tree

  4. none of the above


Correct Option: A
Explanation:

 If a binary tree contains either zero or two child, then it is called as strict binary tree.

Fill in the blank. Where 'i' is the stack no. and 'x' is the item to be inserted. void Push( int i, int x ) {
if(-------) printf(Stackoverflow); elseS[++Top]=x;
}

  1. Top[i]=Top[i+1]

  2. Top[i]=Bottom[i+1]

  3. Top[i]=Bottom[i]

  4. Top[i]=Bottom[i-1]


Correct Option: B
Explanation:

Here 'i' is the stack number, if stack i is full then bottom of new stack begins from there, applicable for multilevel queue. For multilevel queue (n/m)*i - 1, where n is the size of array, m is the size of stack and i is the stack number, let n =9, m=3, then three stacks can be implemented on it. So i = 0, 1, 2. Put i in formula (n/m)*i - 1 for 0 we get -1, -1 is bottom of first stack. Put i=1, we get 2, and 2 is the top for first stack and bottom for second stack. Option says top of first queue is equal to bottom of second queue. So, it is the correct option. As first stack is full, this satisfies the overflow condition.

Fill in the blank in the following code, where DOM is counting the number of nodes in link list.
int DOM() {
struct NODE *M= First;
int count=0;
while( _____ ) {
++count;
P=P->next; }
return count;
}

  1. P

  2. !P

  3. P->next

  4. !P->next


Correct Option: A
Explanation:

If (P), then P is pointing to link list, where P is the first pointer. If (!P), then P is pointing to nothing. So, in the while condition, P is satisfying the condition.

- Hide questions