Data StructuresMCQ
Data StructuresMCQ
Data StructuresMCQ
MCQ
UNIT I
1. Which of these best describes an array?
a) A data structure that shows a hierarchical behaviour
b) Container of objects of similar types
c) Arrays are immutable once initialised
d) Array is not a data structure
Answer: b
2. How do you initialize an array in C?
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);
Answer: c
3. Which of the following concepts make extensive use of arrays?
a) Binary trees
b) Scheduling of processes
c) Caching
d) Spatial locality
Answer: d
4. What are the advantages of arrays?
a) Objects of mixed data types can be stored
b) Elements in an array cannot be sorted
c) Index of first element of an array is 1
d) Easier to store elements of same data type
Answer: d
5.Assuming int is of 4bytes, what is the size of int arr[15];?
a) 15
b) 19
c) 11
d) 60
Answer: d
6. In general, the index of the first element in an array is __________
a) 0
b) -1
c) 2
d) 1
Answer: a
7. Elements in an array are accessed _____________
a) randomly
b) sequentially
c) exponentially
d) logarithmically
Answer: a
8. Which matrix has most of the elements (not all) as Zero?
a) Identity Matrix
b) Unit Matrix
c) Sparse Matrix
d) Zero Matrix
Answer: c
9. Which of the following is not the method to represent Sparse Matrix?
a) Dictionary of Keys
b) Linked List
c) Array
d) Heap
Answer: d
10. A linear collection of data elements where the linear node is given by means of pointer is
called?
a) Linked list
b) Node list
c) Primitive list
d) Unordered list
Answer: a
11. What would be the asymptotic time complexity to insert an element at the front of the linked
list (head is known)?
a) O(1)
b) O(n)
c) O(n2)
d) O(n3)
Answer: a
12. Consider the following definition in c programming language
struct node
{
int data;
struct node * next;
}
typedef struct node NODE;
NODE *ptr;
Which of the following c code is used to create new node?
a) ptr = (NODE*)malloc(sizeof(NODE));
b) ptr = (NODE*)malloc(NODE);
c) ptr = (NODE*)malloc(sizeof(NODE*));
d) ptr = (NODE)malloc(sizeof(NODE));
Answer: a
13. What differentiates a circular linked list from a normal linked list?
a) You cannot have the ‘next’ pointer point to null in a circular linked list
b) It is faster to traverse the circular linked list
c) You may or may not have the ‘next’ pointer point to null in a circular linked list
d) Head node is known in circular linked list
Answer: c
14. What is the time complexity of searching for an element in a circular linked list?
a) O(n)
b) O(nlogn)
c) O(1)
d) O(n2)
Answer: a
15. Which of the following application makes use of a circular linked list?
a) Undo operation in a text editor
b) Recursive function calls
c) Allocating CPU to resources
d) Implement Hash Tables
Answer: c
16. Which of the following is false about a doubly linked list?
a) We can navigate in both the directions
b) It requires more space than a singly linked list
c) The insertion and deletion of a node take a bit longer
d) Implementing a doubly linked list is easier than singly linked list
Answer: d
17. What is a memory efficient double linked list?
a) Each node has only one pointer to traverse the list back and forth
b) The list has breakpoints for faster traversal
c) An auxiliary singly linked list acts as a helper list to traverse through the doubly linked list
d) A doubly linked list that uses bitwise AND operator for storing addresses
Answer: a
18. What is the worst case time complexity of inserting a node in a doubly linked list?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(1)
Answer: c
19. What kind of linked list is best to answer question like “What is the item at position n?”
a) Singly linked list
b) Doubly linked list
c) Circular linked list
d) Array implementation of linked list
Answer: d
20. Linked list is considered as an example of ___________ type of memory allocation.
a) Dynamic
b) Static
c) Compile time
d) Heap
Answer: a
UNIT II
21. The data structure required to evaluate a postfix expression is
a. queue
b. stack
c. array
d. linked-list
Answer Option B
22. The data structure required to check whether an expression contains balanced parenthesis is
a. Stack
b. Queue
c. Tree
d. Array
Answer Option A
23. Which data structure is needed to convert infix notation to postfix notation?
a. Branch
b. Queue
c. Tree
d. Stack
Answer: Option D
24. Which data structure is used for implementing recursion?
a. Queue
b. Stack
c. Arrays
d. List
Answer: Option B
25. The result of evaluating the postfix expression 5,4,6,+,*,4,9,3,/,+,* is
a. 600
b. 350
c. 650
d. 588
e. Answer: Option B
26. Let S be the original stack and S1 and S2 the two additional stacks then the following pseudo
code is to reverse the stack S:
while (S not empty)
{
push(S1,pop(S));
}
while(S1 not empty)
{
push(S2,pop(S1));
}
while(S2 not empty)
{
push(S,pop(S2));
}?
a. TRUE
b. False
c. Not Answer
Answer: Option A
27. The data structure required to check whether an expression contains balanced parenthesis is
a. Stack
b. Queue
c. Tree
d. Array
e. Answer: Option A
28. Let ' s' be a stack and push and pop be functions implementing the Insertion and Deletion
operations in a Stack. push takes 2 parameters: the stack and the element to be inserted , pop
takes a single parameter: the stack. What will be the contents of the stack after the following
operations: push(s,A), push(s,B), push(s,C), pop(s), pop(s), push(s, D), push (s, E), pop(s) ?
a. A D
b. D E
c. C E
d. A E
e. Answer: Option A
29. The term "push" and "pop" is related to the
a. Array
b. Lists
c. stacks
d. all of above
e. Answer: Option C
30. The post fix form of A & B * C-D + E/F/ (G + H) is
a. AB $ C * D - EF/GH +I+
b. AB$* C- D + EF I GH I+
c. AB $ C + D - EF I GH I - +
d. AB $ C - D * EF I GH I ++
i. Answer: Option A
31. A linear list of elements in which deletion can be done from one end (front) and
insertion can take place only at the other end (rear) is known as a ?
a) Queue
b) Stack
c) Tree
d) Linked list
Answer: a
32. A queue follows __________
a) FIFO (First In First Out) principle
b) LIFO (Last In First Out) principle
c) Ordered array
d) Linear tree
Answer: a
33. Circular Queue is also known as ________
a) Ring Buffer
b) Square Buffer
c) Rectangle Buffer
d) Curve Buffer
Answer: a
34. If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a
time, in what order will they be removed?
a) ABCD
b) DCBA
c) DCAB
d) ABDC
Answer: a
35. A data structure in which elements can be inserted or deleted at/from both the ends
but not in the middle is?
a) Queue
b) Circular queue
c) Dequeue
d) Priority queue
View Answer
Answer: c
36. A normal queue, if implemented using an array of size MAX_SIZE, gets full when
a) Rear = MAX_SIZE – 1
b) Front = (rear + 1)mod MAX_SIZE
c) Front = rear + 1
d) Rear = front
Answer: a
37. Queues serve major role in ______________
a) Simulation of recursion
b) Simulation of arbitrary linked list
c) Simulation of limited resource allocation
d) Simulation of heap sort
Answer: c
Answer: d
UNIT III
1. What is/are the disadvantages of implementing tree using normal arrays?
a) difficulty in knowing children nodes of a node
b) difficult in finding the parent of a node
c) have to know the maximum number of nodes possible before creation of trees
d) difficult to implement
Answer: c
7. What is the space complexity of the post-order traversal in the recursive fashion? (d is the tree
depth and n is the number of nodes)
a) O(1)
b) O(nlogd)
c) O(logd)
d) O(d)
Answer: d
9. Consider the following data. The pre order traversal of a binary tree is A, B, E, C, D. The in
order traversal of the same binary tree is B, E, A, D, C. The level order sequence for the binary
tree is _________
a) A, C, D, B, E
b) A, B, C, D, E
c) A, B, C, E, D
d) D, B, E, A, C
Answer: b
10. If binary trees are represented in arrays, what formula can be used to locate a left child, if the
node has an index i?
a) 2i+1
b) 2i+2
c) 2i
d) 4i
Answer: a
11. What is the maximum number of children that a binary tree node can have?
a) 0
b) 1
c) 2
d) 3
Answer: c
12.A binary tree is a rooted tree but not an ordered tree.
a) true
b) false
Answer: b
13. How many common operations are performed in a binary tree?
a) 1
b) 2
c) 3
d) 4
Answer: c
14. What is the traversal strategy used in the binary tree?
a) depth-first traversal
b) breadth-first traversal
c) random traversal
d) Priority traversal
Answer: b
Answer: b
18. The number of edges from the node to the deepest leaf is called _________ of the tree.
a) Height
b) Depth
c) Length
d) Width
Answer: a
Answer: a
Answer: c
UNIT IV Graphs:
Terminology, Sequential and linked Representations of Graphs: Adjacency Matrices, Adjacency
List, Adjacency Multi list, Graph Traversal : Depth First Search and Breadth First Search,
Connected Component, Spanning Trees, Minimum Cost Spanning Trees: Prims and Kruskal
algorithm. Transistive Closure and Shortest Path algorithm: Warshal Algorithm and Dijikstra
Algorithm, Introduction to Activity Networks
a) G is a complete graph
b) G is not a connected graph
c) The vertex connectivity of the graph is 2
d) The edge connectivity of the graph is 1
Answer: c
Explanation: After removing vertices B and C, the graph becomes disconnected.
a) True
b) False
Answer: a
Explanation: In a regular graph, degrees of all the vertices are equal. In the given graph the
degree of every vertex is 3.
5) For a given graph G having v vertices and e edges which is connected and has no cycles,
which of the following statements is true?
a) v=e
b) v = e+1
c) v + 1 = e
d) v = e-1
Answer: b
Explanation: For any connected graph with no cycles the equation holds true.
Answer: c
Explanation: Adjacency Matrix, Adjacency List and Incidence Matrix are used to represent a
graph.
9) What would be the number of zeros in the adjacency matrix of the given graph?
a) 10
b) 6
c) 16
d) 0
Answer: b
Explanation: Total number of values in the matrix is 4*4=16, out of which 6 entries are non zero.
10) Adjacency matrix of all graphs are symmetric.
a) False
b) True
Answer: a
Explanation: Only undirected graphs produce symmetric adjacency matrices.
11) The time complexity to calculate the number of edges in a graph whose information in
stored in form of an adjacency matrix is ____________
a) O(V)
b) O(E2)
c) O(E)
d) O(V2)
Answer: d
Explanation: As V entries are 0, a total of V2-V entries are to be examined.
12) For the adjacency matrix of a directed graph the row sum is the _________ degree and
the column sum is the ________ degree.
a) in, out
b) out, in
c) in, total
d) total, out
Answer: b
Explanation: Row number of the matrix represents the tail, while Column number represents the
head of the edge.
13) What is the maximum number of possible non zero values in an adjacency matrix of a
simple graph with n vertices?
a) (n*(n-1))/2
b) (n*(n+1))/2
c) n*(n-1)
d) n*(n+1)
Answer: c
Explanation: Out of n*n possible values for a simple graph the diagonal values will always be
zero.
14 On which of the following statements does the time complexity of checking if an edge
exists between two particular vertices is not, depends?
a) Depends on the number of edges
b) Depends on the number of vertices
c) Is independent of both the number of edges and vertices
d) It depends on both the number of edges and vertices
Answer: c
Explanation: To check if there is an edge between to vertices i and j, it is enough to see if the
value of A[i][j] is 1 or 0, here A is the adjacency matrix.
15) This set of Data Structures & Algorithms Multiple Choice Questions & Answers
(MCQs) focuses on “Minimum Spanning Tree”.
17) Consider a complete graph G with 4 vertices. The graph G has ____ spanning trees.
a) 15
b) 8
c) 16
d) 13
Answer: c
Explanation: A graph can have many spanning trees. And a complete graph with n vertices has
n(n-2) spanning trees. So, the complete graph with 4 vertices has 4(4-2) = 16 spanning trees.
18) Consider the graph shown below. Which of the following are the edges in the MST of
the given graph?
a) (a-c)(c-d)(d-b)(d-b)
b) (c-a)(a-d)(d-b)(d-e)
c) (a-d)(d-c)(d-b)(d-e)
d) (c-a)(a-d)(d-c)(d-b)(d-e)
Answer: c
Explanation: The minimum spanning tree of the given graph is shown below. It has cost 56.
19) Which of the following is not the algorithm to find the minimum spanning tree of the
given graph?
a) Boruvka’s algorithm
b) Prim’s algorithm
c) Kruskal’s algorithm
d) Bellman–Ford algorithm
Answer: d
Explanation: Every spanning tree has n – 1 edges if the graph has n edges and has no cycles. The
MST follows the cut property, Edge e belonging to a cut of the graph if has the weight smaller
than any other edge in the same cut, then the edge e is present in all the MSTs of the graph.
24) The running time of Bellmann Ford algorithm is lower than that of Dijkstra’s
Algorithm.
a) True
b) False
Answer: b
Explanation: The number of iterations involved in Bellmann Ford Algorithm is more than that of
Dijkstra’s Algorithm.
1) What is the best case and worst case complexity of ordered linear search?
a) O(nlogn), O(logn)
b) O(logn), O(nlogn)
c) O(n), O(1)
d) O(1), O(n)
Answer: d
Explanation: Although ordered linear search is better than unordered when the element is not
present in the array, the best and worst cases still remain the same, with the key element being
found at first position or at last position.
2) Given an array arr = {45,77,89,90,94,99,100} and key = 99; what are the mid
values(corresponding array elements) in the first and second levels of recursion?
a) 90 and 99
b) 90 and 94
c) 89 and 99
d) 89 and 94
Answer: a
Explanation: At first level key = 90
At second level key= 99
Here 90 and 99 are mid values.
4) Given an array arr = {5,6,77,88,99} and key = 88; How many iterations are done until
the element is found?
a) 1
b) 3
c) 4
d) 2
Answer: d
Explanation: Iteration1 : mid = 77; Iteration2 : mid = 88;
6) The given array is arr = {1, 2, 4, 3}. Bubble sort is used to sort the array elements. How
many iterations will be done to sort the array?
a) 4
b) 2
c) 1
d) 0
Answer: a
Explanation: Even though the first two elements are already sorted, bubble sort needs 4 iterations
to sort the given array.
8) Which one of the following sorting algorithm is best suited to sort an array of 1 million
elements?
a) Bubble sort
b) Insertion sort
c) Merge sort
d) Quick sort
Answer: d
Explanation: The Quick sort is best suited to sort the array of 1 million elements. The practical
implementations of Quick sort use randomised version. In practice randomised Quick sort
algorithms rarely shows worst case behaviour and is almost always O(nlogn). And Quick sort
requires little additional space and exhibits good cache locality.
11) Which of the following is good for sorting arrays having less than 100 elements?
a) Quick Sort
b) Selection Sort
c) Merge Sort
d) Insertion Sort
Answer: d
Explanation: The insertion sort is good for sorting small arrays. It sorts smaller arrays faster than
any other sorting algorithm.
12)In insertion sort, the average number of comparisons required to place the 7th element
into its correct position is ____
a) 9
b) 4
c) 7
d) 14
Answer: b
Explanation: On average (k + 1) / 2 comparisons are required to place the kth element into its
correct position. Therefore, average number of comparisons required for 7th element = (7 + 1)/2
= 4.
13) If several elements are competing for the same bucket in the hash table, what is it
called?
a) Diffusion
b) Replication
c) Collision
d) Duplication
Answer: c
Explanation: In a hash table, if sevaral elements are computing for the same bucket then there
will be a clash among elements. This condition is called Collision. The Collision is reduced by
adding elements to a linked list and head address of linked list is placed in hash table.
18) Which of the following traversing algorithm is not used to traverse in a tree?
a) Post order
b) Pre order
c) Post order
d) Randomized
Answer: d
Explanation: Generally, all nodes in a tree are visited by using preorder, inorder and postorder
traversing algorithms.
22) B-tree of order n is a order-n multiway tree in which each non-root node contains
_____
a) at most (n – 1)/2 keys
b) exact (n – 1)/2 keys
c) at least 2n keys
d) at least (n – 1)/2 keys
Answer: d
Explanation: A non-root node in a B-tree of order n contains at least (n – 1)/2 keys. And contains
a maximum of (n – 1) keys and n sons.
23) A B-tree of order 4 and of height 3 will have a maximum of _______ keys.
a) 255
b) 63
c) 127
d) 188
Answer: a
Explanation: A B-tree of order m of height h will have the maximum number of keys when all
nodes are completely filled. So, the B-tree will have n = (mh+1 – 1) keys in this situation. So,
required number of maximum keys = 43+1 – 1 = 256 – 1 = 255.
24) Five node splitting operations occurred when an entry is inserted into a B-tree. Then
how many nodes are written?
a) 14
b) 7
c) 11
d) 5
Answer: c
Explanation: If s splits occur in a B-tree, 2s + 1 nodes are written (2 halves of each split and the
parent of the last node split). So, if 5 splits occurred, then 2 * 5 + 1 , i.e. 11 nodes are written.
25) What is the best case height of a B-tree of order n and which has k keys?
a) logn (k+1) – 1
b) nk
c) logk (n+1) – 1
d) klogn
Answer: a
Explanation: B-tree of order n and with height k has best case height h, where h = logn (k+1) – 1.
The best case occurs when all the nodes are completely filled with keys.
---------------------------------------------------------------------------------------------------------------------