Google News
logo
Data Structures - Quiz(MCQ)
A)
Array is not a data structure
B)
Arrays are immutable once initialised
C)
Container of objects of similar types
D)
A data structure that shows a hierarchical behavior

Correct Answer :   Container of objects of similar types

A)
int arr[3] = {1,2,3};
B)
int arr[3] = (1,2,3);
C)
int arr(3) = {1,2,3};
D)
int arr(3) = (1,2,3);

Correct Answer :   int arr[3] = {1,2,3};

A)
array
B)
tree
C)
stack
D)
queue

Correct Answer :   tree

A)
Loop
B)
Case
C)
Switch
D)
Array

Correct Answer :   Array

A)
int arr[];
B)
int arr[] = new int[3];
C)
int arr() = new int(3);
D)
int arr[] = new int(3);

Correct Answer :   int arr[] = new int[3];


Explanation : Note that int arr[]; is declaration whereas int arr[] = new int[3]; is to instantiate an array.

6 .
What is the output of the following Java code?
public class array
{
	public static void main(String args[])
	{
		int []arr = {1,2,3,4,5};
		System.out.println(arr[2]);
		System.out.println(arr[4]);
	}
}
A)
2 and 4
B)
4 and 2
C)
3 and 5
D)
5 and 3

Correct Answer :   3 and 5

7 .
What is the output of the following Java code?
public class array
{
	public static void main(String args[])
	{
		int []arr = {1,2,3,4,5};
		System.out.println(arr[5]);
	}
}
A)
4
B)
5
C)
InavlidInputException
D)
ArrayIndexOutOfBoundsException

Correct Answer :   ArrayIndexOutOfBoundsException

A)
Stack
B)
Queue
C)
Binary Tree
D)
Double linked list

Correct Answer :   Stack

9 .
int nums[ ] = {2, 3, 5, 8, 9, 11};
 
How would you access the fourth element in nums
A)
nums(3)
B)
nums(4)
C)
nums[3]
D)
nums[8]

Correct Answer :   nums[3]

A)
Arrays
B)
Variables
C)
Algorithms
D)
Abstract Data Types

Correct Answer :   Abstract Data Types

A)
Circular Queue
B)
Linear Queue
C)
Priority Queue
D)
None of the above

Correct Answer :   Circular Queue

A)
Trees
B)
Pointer
C)
Link List
D)
Variable

Correct Answer :   Link List

A)
Caching
B)
Spatial locality
C)
Binary trees
D)
Scheduling of processes

Correct Answer :   Spatial locality


Explanation : Whenever a particular memory location is referred to, it is likely that the locations nearby are also referred, arrays are stored as contiguous blocks in memory, so if you want to access array elements, spatial locality makes it to access quickly.

A)
11
B)
15
C)
19
D)
60

Correct Answer :   60


Explanation : Since there are 15 int elements and each int is of 4bytes, we get 15*4 = 60bytes.

A)
randomly
B)
sequentially
C)
exponentially
D)
logarithmically

Correct Answer :   randomly


Explanation : Elements in an array are accessed randomly. In Linked lists, elements are accessed sequentially.

A)
List of Outputs
B)
Last in First Out
C)
First in Last Out
D)
None of the above

Correct Answer :   Last in First Out

A)
Polling
B)
Popping
C)
Pushing
D)
None of the above

Correct Answer :   Pushing

A)
Push
B)
Create
C)
Evaluation
D)
Pop

Correct Answer :   Pop


Explanation : Elements in the stack are removed using pop operation. Pop operation removes the top most element in the stack i.e. last entered element.

A)
Overflow
B)
Underflow
C)
Empty collection
D)
Garbage Collection

Correct Answer :   Underflow


Explanation : Underflow occurs when the user performs a pop operation on an empty stack. Overflow occurs when the stack is full and the user performs a push operation. Garbage Collection is used to recover the memory occupied by objects that are no longer used.

A)
-18
B)
1
C)
40
D)
70

Correct Answer :   -18


Explanation : Postfix Expression is (6*(3-(2+4))) which results -18 as output.

A)
Queue
B)
Tree
C)
Stack
D)
Linked list

Correct Answer :   Queue


Explanation : Linear list of elements in which deletion is done at front side and insertion at rear side is called Queue. In stack we will delete the last entered element first.

A)
Load Balancing
B)
When a resource is shared among multiple consumers.
C)
When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes
D)
All of the above

Correct Answer :   All of the above

A)
Heap Sort
B)
Quick Sort
C)
Merge Sort
D)
Insertion Sort

Correct Answer :   Merge Sort

A)
In adjacency list representation, space is saved for sparse graphs.
B)
Adding a vertex in adjacency list representation is easier than adjacency matrix representation.
C)
DFS and BSF can be done in O(V + E) time for adjacency list representation. These operations take O(V^2) time in adjacency matrix representation. Here is V and E are number of vertices and edges respectively.
D)
All of the above

Correct Answer :   All of the above

A)
Full: REAR == FRONT, empty: (REAR+1) mod n == FRONT
B)
Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT
C)
Full: (FRONT+1) mod n == REAR, empty: REAR == FRONT
D)
Full: (REAR+1) mod n == FRONT, empty: (FRONT+1) mod n == REAR

Correct Answer :   Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT


Explanation :

Suppose we start filling the queue.
 
Let the maxQueueSize ( Capacity of the Queue) is 4.
So the size of the array which is used to implement 
this circular queue is 5, which is n.
 
In the beginning when the queue is empty, FRONT and REAR 
point to 0 index in the array.
 
REAR represents insertion at the REAR index.
FRONT represents deletion from the FRONT index.
 
enqueue("a"); REAR = (REAR+1)%5; ( FRONT = 0, REAR = 1)
enqueue("b"); REAR = (REAR+1)%5; ( FRONT = 0, REAR = 2)
enqueue("c"); REAR = (REAR+1)%5; ( FRONT = 0, REAR = 3)
enqueue("d"); REAR = (REAR+1)%5; ( FRONT = 0, REAR = 4)
 
Now the queue size is 4 which is equal to the maxQueueSize. 
Hence overflow condition is reached.
 
Now, we can check for the conditions.
 
When Queue Full :
 
( REAR+1)%n = (4+1)%5 = 0
 
FRONT is also 0.
 
Hence ( REAR + 1 ) %n is equal to FRONT.
 
When Queue Empty :
 
REAR was equal to FRONT when empty ( because in the starting 
before filling the queue FRONT = REAR = 0 )

A)
An array of 50 numbers
B)
An array of 100 numbers
C)
An array of 500 numbers
D)
A dynamically allocated array of 550 numbers

Correct Answer :   An array of 50 numbers

A)
Arrays are immutable.
B)
Container that stores the elements of similar types
C)
The Array is not a data structure
D)
The Array shows a hierarchical structure.

Correct Answer :   Container that stores the elements of similar types


Explanation : The answer is c because array stores the elements in a contiguous block of memory of similar types. Therefore, we can say that array is a container that stores the elements of similar types.

A)
int arr[2]=(10, 20)
B)
int arr(2)={10, 20}
C)
int arr[2] = {10, 20}
D)
int arr(2) = (10, 20)

Correct Answer :   int arr[2] = {10, 20}

30 .
What is the output of the below code?
#include <stdio.h>  
int main()  
{  
   int arr[5]={10,20,30,40,50};  
   printf("%d", arr[5]);  
  
    return 0;  
} 
A)
10
B)
50
C)
Garbage value
D)
None of the above

Correct Answer :   Garbage value


Explaination : The answer is a because the indexing in an array starts from 0, so it starts from arr[0] to arr[4]. If we try to access arr[5] then the garbage value will be printed.

A)
9
B)
15
C)
24
D)
36

Correct Answer :   36


Explanation : The answer is b because the size of int type data is 4 bytes. The array stores 9 elements, so the size of the array is 9*4=36 bytes.

A)
The size of the structure is fixed
B)
The data structure can also double as TNT
C)
Memory is allocated to the data structure as the program executes.
D)
Memory is allocated to the data structure at compile time.

Correct Answer :   Memory is allocated to the data structure as the program executes.

A)
The Name of the list
B)
The meaning of life
C)
The address of the current data entry
D)
The address of the next data entry in the list

Correct Answer :   The address of the next data entry in the list

A)
Curve Buffer
B)
Ring Buffer
C)
Square Buffer
D)
Rectangle Buffer

Correct Answer :   Ring Buffer


Explanation : Circular Queue is also called as Ring Buffer. Circular Queue is a linear data structure in which last position is connected back to the first position to make a circle. It forms a ring structure.

A)
Simulation of recursion
B)
Simulation of heap sort
C)
Simulation of arbitrary linked list
D)
Simulation of limited resource allocation

Correct Answer :   Simulation of limited resource allocation


Explanation : Simulation of recursion uses stack data structure. Simulation of arbitrary linked lists uses linked lists. Simulation of resource allocation uses queue as first entered data needs to be given first priority during resource allocation. Simulation of heap sort uses heap data structure.

38 .
Consider an implementation of unsorted singly linked list. Suppose it has its representation with a head pointer only. Given the representation, which of the following operation can be implemented in O(1) time?
 
i) Insertion at the front of the linked list
ii) Insertion at the end of the linked list
iii) Deletion of the front node of the linked list
iv) Deletion of the last node of the linked list
A)
I and III
B)
I and II
C)
I, II and III
D)
I, II and IV

Correct Answer :   I and III


Explaination : We know the head node in the given linked list. Insertion and deletion of elements at the front of the linked list completes in O (1) time whereas for insertion and deletion at the last node requires to traverse through every node in the linked list. Suppose there are n elements in a linked list, we need to traverse through each node. Hence time complexity becomes O(n).

A)
Singly linked list
B)
Doubly linked list
C)
Array implementation of linked list
D)
Circular linked list

Correct Answer :   Array implementation of linked list


Explanation : Arrays provide random access to elements by providing the index value within square brackets. In the linked list, we need to traverse through each element until we reach the nth position. Time taken to access an element represented in arrays is less than the singly, doubly and circular linked lists. Thus, array implementation is used to access the item at the position n.

A)
Underflow
B)
Overflow
C)
Garbage collection
D)
None of the above

Correct Answer :   Underflow


Explanation : Underflow is a condition that occurs when user tries to implement the pop operation in the empty stack.

A)
Overflow
B)
Underflow
C)
Garbage collection
D)
None of the above

Correct Answer :   Overflow

A)
Recursion
B)
Backtracking
C)
String reversal
D)
Asynchronous data transfer

Correct Answer :   Asynchronous data transfer


Explanation : The first three options are the stack applications, but option d is not a stack application. The queue data structure is used for synchronization between the processes.

A)
ABC+*
B)
A+B*C
C)
+A*BC
D)
None of the above

Correct Answer :   A+B*C


Explanation : A+B*C because, in infix notation, all the operators appear between the operands.

A)
ABC+*
B)
+AB*C
C)
+A*BC
D)
A+(BC*)

Correct Answer :   +A*BC


Explanation :

The prefix notation means all the operators that appear before operand.
 
To convert the infix expression into a prefix expression, we will move the operator to the left of the parenthesis as shown in the below figure.

A)
Stack follows FIFO
B)
Elements are stored in a sequential manner
C)
Arrays can be used to implement the stack
D)
Top of the stack contains the last inserted element

Correct Answer :   Stack follows FIFO

A)
1
B)
2
C)
3
D)
5

Correct Answer :   2


Explanation : In Queue, one stack is required for the enqueue operation, and another stack will be used for the dequeue operation. The first stack is considered as the input stack whereas the second stack is considered as the output stack.

A)
Linear Queue
B)
Circular Queue
C)
Double ended Queue
D)
Single ended Queue

Correct Answer :   Single ended Queue


Explanation : single ended queue. Queue has two ends in which one end is used for the insertion and another end is used for the deletion. Therefore, it is not possible for the Queue to have a single ended queue.

A)
rear = front
B)
rear = MAX_SIZE
C)
rear = front+1
D)
rear=MAX_SIZE -1

Correct Answer :   rear=MAX_SIZE -1


Explanation : rear=MAX_SIZE-1. As the size of the array is MAX_SIZE, so we can insert the elements till MAX_SIZE-1. If we try to insert the elements of size MAX_SIZE or more than MAX_SIZE in a queue, then it leads to the overflow condition.

A)
rear=MAX
B)
rear= MAX-1
C)
front=(rear+1) mod max
D)
None of the above

Correct Answer :   front=(rear+1) mod max


Explanation : front=(rear+1) mod max. The overflow condition for the linear queue is rear =MAX-1 as there is no space left in the Queue if rear = MAX-1. On the other hand, in a circular queue, the overflow condition is front=(rear+1) mod max because the last element is connected to the first element in a circular queue.

A)
Space Utilization and Computational Time
B)
Speed Utilization
C)
Space Utilization
D)
Computational Time

Correct Answer :   Space Utilization and Computational Time

51 .
What does the following function do for a given Linked List with first node as head?
void fun1(struct node* head)
{
    if(head == NULL)
    return;
    fun1(head->next);
    printf("%d  ", head->data);
}
A)
Prints all nodes of linked lists
B)
Prints all nodes of linked list in reverse order
C)
Prints alternate nodes of Linked List
D)
Prints alternate nodes in reverse order

Correct Answer :   Prints all nodes of linked list in reverse order


Explaination :

fun1() prints the given Linked List in reverse manner.
For Linked List 1->2->3->4->5, fun1() prints 5->4->3->2->1.

A)
0 1 2 3 4 5 6 7 8 9
B)
0 2 4 3 1 6 5 9 8 7
C)
7 5 1 0 3 2 4 6 8 9
D)
9 8 6 4 2 3 0 1 5 7

Correct Answer :   0 1 2 3 4 5 6 7 8 9


Explanation : In-order traversal of a BST gives elements in increasing order. So answer A is correct without any doubt.

A)
Follows the FIFO principle
B)
Avoid wastage of memory
C)
Access the Queue using priority
D)
None of the above

Correct Answer :   Avoid wastage of memory


Explanation : Avoid wastage of memory. In a linear queue, there are chances of wastage of memory because if the rear is pointing to the last element whereas the front is pointing to the element other than the first element; it means that spaces allocated before the front are free, but it cannot be reused as rear cannot be incremented. In contrast, the last element is connected to the first element in a circular queue; if initial spaces are vacant, then rear can be incremented by using the statement (rear+1) mod max where max is the size of the array. Therefore, we conclude that the circular queue avoids wastage of memory.

A)
rear =rear+1
B)
(rear % max) + 1
C)
(rear+1) % max
D)
None of the above

Correct Answer :   (rear+1) % max


Explanation : It ensures that the rear will have the value from 0 to max-1; if the rear end points to the last position, and we increment the rear end using (rear+1) % max, then rear will point to the first position in the queue.

A)
At the head position of the linked list
B)
At the middle position of the linked list
C)
Both (A) and (B)
D)
At the tail position of the linked list

Correct Answer :   At the tail position of the linked list

A)
In enqueue operation, new nodes are inserted from the beginning and in dequeue operation, nodes are removed from the end.
B)
In enqueue operation, new nodes are inserted from the end and in dequeue operation, nodes are deleted from the beginning.
C)
Both (A) and (B)
D)
In enqueue operation, new nodes are inserted from the end and in dequeue operation, nodes are deleted from the end.

Correct Answer :   Both (A) and (B)


Explanation : As we know that Queue has two ends, i.e., one for the insertion and another one for the deletion. If Queue is implemented using Linked list then it can be done in either of the ways.

A)
FIFO
B)
LIFO
C)
Linear tree
D)
None of the above

Correct Answer :   FIFO


Explanation : FIFO. In a priority queue, if two or more elements have the same priority then they are arranged based on the FIFO principle.

A)
Easy to implement
B)
Deletion is easier
C)
Processes with different priority can be easily handled
D)
None of the above

Correct Answer :   Deletion is easier


Explanation : In worst case, the deletion is not easier as we have to traverse to the n elements until the element to be removed is not found.

59 .
What would be the output after performing the following operations in a Deque?
Insertfront(10);  
Insertfront(20);  
Insertrear(30);  
Insertrear(40);  
Deletefront();  
Insertfront(50);  
Deleterear();  
Display();
A)
40, 20, 30
B)
50, 10, 30
C)
10, 20, 30
D)
None of the above

Correct Answer :   50, 10, 30


Explaination :

Let's dry run the above code.
 
When insertfront(10) is called, deque would be:
 
10
 
When insertfront(20) is called, the deque would be:
 
20 10
 
When insertrear(30) is called, the deque would be:
 
20 10 30
 
When insertrear(40) is called, the deque would be:
 
20 10 30 40
 
When deletefront() is called, the deque would be:
 
10 30 40
 
When insertfront(50) is called, the deque would be:
 
50 10 30 40
 
When deleterear() is called, the deque would be:
 
50 10 30

A)
5
B)
2
C)
1
D)
0

Correct Answer :   0


Explanation : 0. As it is mentioned in the question that the size of the array is 5; therefore, the range would be from 0 to 4. In a circular queue, the last element is connected to the first element; the value of rear is 4 so when we increment the value then it will point to the 0th position of the array.

A)
Inorder traversal
B)
Preorder traversal
C)
Randomized traversal
D)
Postorder traversal

Correct Answer :   Randomized traversal

A)
It requires extra space
B)
We can traverse in both the directions.
C)
It stores the addresses of the next and the previous node
D)
Implementation of doubly linked list is easier than the singly linked list

Correct Answer :   Implementation of doubly linked list is easier than the singly linked list


Explanation : The implementation of doubly linked list is complex as compared to singly linked list as it needs to store the addresses of the two nodes, i.e., the previous and the next node. If we insert or delete the node from the doubly linked list then it needs to adjust two pointers, previous and the next pointer.

63 .
Consider the following code
struct node  
{  
   int data;  
   struct node *next;  
}  
node ptr; ​
Which one of the following is the correct option to create a new node?
A)
ptr=(node*)malloc(sizeof(node))
B)
ptr=(node)malloc(sizeof(node))
C)
ptr= (node*)malloc(sizeof(node*))
D)
None of the above

Correct Answer :   ptr=(node*)malloc(sizeof(node))


Explaination : ptr=(node*)malloc(sizeof(node)). In this statement, we have used a malloc() function for allocating the memory to the node and ptr is a pointer variable that will point to the newly created node.

A)
n
B)
n/2
C)
log 2 n
D)
log 2 n – 1

Correct Answer :   n


Explanation : In the worst case, the element to be searched has to be compared with all elements of linked list.

A)
0.0125
B)
80
C)
1.25
D)
8000

Correct Answer :   80


Explanation : load factor = (no. of elements) / (no. of table slots) = 2000/25 = 80

A)
the lengths of the paths from the root to all leaf nodes are all equal.
B)
the number of records in any two leaf nodes differ by at most 1.
C)
the number of children of any two non-leaf sibling nodes differ by at most 1.
D)
the lengths of the paths from the root to all leaf nodes differ from each other by at most 1.

Correct Answer :   the lengths of the paths from the root to all leaf nodes are all equal.


Explanation : In both B Tree and B+ trees, depth (length of root to leaf paths) of all leaf nodes is same. This is made sure by the insertion and deletion operations. In these trees, we do insertions in a way that if we have increase height of tree after insertion, we increase height from root. This is different from BST where height increases from leaf nodes. Similarly, if we have to decrease height after deletion, we move the root one level down. This is also different from BST which shrinks from bottom. The above ways of insertion and deletion make sure that depth of every leaf node is same.

A)
64
B)
128
C)
35
D)
5040

Correct Answer :   35


Explanation :

There are two set of values, smaller than 60 and greater than 60. Smaller values 10, 20, 40 and 50 are visited, means they are visited in order. Similarly, 90, 80 and 70 are visited in order.
= 7!/(4!3!)
= 35

A)
&A[0][0][0] + w(x * y * p + z * q+ r)
B)
&A[0][0][0] + w(y * z * q + z * p + r)
C)
&A[0][0][0] + w(y * z * p + z*q + r)
D)
&A[0][0][0] + w(x * y * q + z * p + r)

Correct Answer :   &A[0][0][0] + w(y * z * p + z*q + r)


Explanation : According to above question we have to find the address of A[p][q][r] To reach pth row we must have to cross 0 to p-1 row i.e. p rows and each rows contains y∗z elements Hence , = y∗z∗p Now to reach qth element in pth row we have to cross q rows and each row contains z(total columns) elements =z∗q to reach rth elements we have to cross r elements in (p+1)th row Total elements to cross =(y∗z∗p+z∗q+r) Now each element occupies m amount of space in memory Therefore total space occupied by these elements = m(y∗z∗p+z∗q+r) Hence , address of A[p][q][r]=base address+ Space Occupied by the Elements Before it. =&A[0][0][0]+m(y*z*p+z*q+r) Hence Option (C) is correct.