Data Structure Mcqs 110

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 24

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

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);

3. How do you instantiate an array in Java?


a) int arr[] = new int(3);
b) int arr[];
c) int arr[] = new int[3];
d) int arr() = new int(3);

4. Which of the following is a correct way to declare a multidimensional array in Java?


a) int[] arr;
b) int arr[[]];
c) int[][]arr;
d) int[[]] arr;

5. What is the output of the following piece of 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) 3 and 5
b) 5 and 3
c) 2 and 4
d) 4 and 2

6. What is the output of the following piece of 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) ArrayIndexOutOfBoundsException
d) InavlidInputException

7. When does the ArrayIndexOutOfBoundsException occur?


a) Compile-time
b) Run-time
c) Not an error
d) Not an exception at all

8. Which of the following concepts make extensive use of arrays?


a) Binary trees
b) Scheduling of processes
c) Caching
d) Spatial locality

9. 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

10. What are the disadvantages of arrays?


a) Data structure like queue or stack cannot be implemented
b) There are chances of wastage of memory space if elements inserted in an array are lesser than the
allocated size
c) Index value of an array can be negative
d) Elements are sequentially accessed

11. Assuming int is of 4bytes, what is the size of int arr[15];?


a) 15
b) 19
c) 11
d) 60

12. In general, the index of the first element in an array is __________


a) 0
b) -1
c) 2
d) 1

13. Elements in an array are accessed _____________


a) randomly
b) sequentially
c) exponentially
d) logarithmically

14. Process of inserting an element in stack is called ____________

a) Create

b) Push

c) Evaluation

d) Pop

15. Process of removing an element from stack is called __________

a) Create

b) Push

c) Evaluation

d) Pop

16. In a stack, if a user tries to remove an element from empty stack it is called _________
a) Underflow

b) Empty collection

c) Overflow

d) Garbage Collection

17. Pushing an element into stack already having five elements and stack size of 5, then stack becomes

a) Overflow

b) Crash

c) Underflow

d) User flow

18. Entries in a stack are “ordered”. What is the meaning of this statement?

a) A collection of stacks is sortable

b) Stack entries may be compared with the ‘<‘ operation

c) The entries are stored in a linked list

d) There is a Sequential entry that is one by one

19. Which of the following applications may use a stack?

a) A parentheses balancing program

b) Tracking of local variables at run time

c) Compiler Syntax Analyzer

d) Data Transfer between two asynchronous process

20. Consider the usual algorithm for determining whether a sequence of parentheses is balanced.

The maximum number of parentheses that appear on the stack AT ANY ONE TIME when the algorithm
analyzes: (()(())(())) are:
a) 1

b) 2

c) 3

d) 4 or more

21. Consider the usual algorithm for determining whether a sequence of parentheses is balanced.

Suppose that you run the algorithm on a sequence that contains 2 left parentheses and 3 right
parentheses (in some order).The maximum number of parentheses that appear on the stack AT ANY
ONE TIME during the computation?

a) 1

b) 2

c) 3

d) 4 or more

22. What is the value of the postfix expression 6 3 2 4 + – *:

a) 1

b) 40

c) 74

d) -18

23. The postfix form of the expression (A+ B)*(C*D- E)*F / G is?

a) AB+ CD*E – FG /**

b) AB + CD* E – F **G /

c) AB + CD* E – *F *G /

d) AB + CDE * – * F *G /

24. The data structure required to check whether an expression contains balanced parenthesis is?

a) Stack

b) Queue

c) Array

d) Tree
25. What data structure would you mostly likely see in a non recursive implementation of a recursive
algorithm?

a) Linked List

b) Stack

c) Queue

d) Tree

26. The process of accessing data stored in a serial access memory is similar to manipulating data on a
________

a) Heap

b) Binary Tree

c) Array

d) Stack

27. The postfix form of A*B+C/D is?

a) *AB/CD+

b) AB*CD/+

c) A*BC+/D

d) ABCD+/*

28. Which data structure is needed to convert infix notation to postfix notation?

a) Branch

b) Tree

c) Queue

d) Stack

29. The prefix form of A-B/ (C * D ^ E) is?

a) -/*^ACBDE

b) -ABCD*^DE

c) -A/B*C^DE
d) -A/BC*^DE

30. What is the result of the following operation?

Top (Push (S, X))

a) X

b) X+S

c) S

d) XS

View Answer

31. Which data structure is used for implementing recursion?

a) Queue

b) Stack

c) Array

d) List

32. Convert the following infix expressions into its equivalent postfix expressions

(A + B ⋀D)/(E – F)+G

a) (A B D ⋀ + E F – / G +)

b) (A B D +⋀ E F – / G +)

c) (A B D ⋀ + E F/- G +)

d) (A B D E F + ⋀ / – G +)

33. Which of the following statement(s) about stack data structure is/are NOT correct?

a) Linked List are used for implementing Stacks

b) Top of the Stack always contain the new node

c) Stack is the FIFO data structure

d) Null link is present in the last node at the bottom of the stack
34. Which of the following is not an inherent application of stack?

a) Reversing a string

b) Evaluation of postfix expression

c) Implementation of recursion

d) Job scheduling

35. The type of expression in which operator succeeds its operands is?

a) Infix Expression

b) Prefix Expression

c) Postfix Expression

d) Both Prefix and Postfix Expressions

36. If the elements “A”, “B”, “C” and “D” are placed in a stack and are deleted one at a time, what is the
order of removal?

a) ABCD

b) DCBA

c) DCAB

d) ABDC

37. 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

38. The data structure required for Breadth First Traversal on a graph is?

a) Stack

b) Array

c) Queue

d) Tree
39. A queue follows __________

a) FIFO (First In First Out) principle

b) LIFO (Last In First Out) principle

c) Ordered array

d) Linear tree

40. Circular Queue is also known as ________

a) Ring Buffer

b) Square Buffer

c) Rectangle Buffer

d) Curve Buffer

41. 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

42. 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

43. 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


44. Which of the following is not the type of queue?

a) Ordinary queue

b) Single ended queue

c) Circular queue

d) Priority queue

45. 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

View Answer

46. 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 II

b) I and III

c) I, II and III

d) I, II and IV

View Answer

47. In linked list each node contain minimum of two fields. One field is data field to store the data
second field is?

a) Pointer to character

b) Pointer to integer
c) Pointer to node

d) Node

48. What would be the asymptotic time complexity to add a node at the end of singly linked list, if the
pointer is initially pointing to the head of the list?

a) O(1)

b) O(n)

c) θ(n)

d) θ(1)

49. 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)

50. What would be the asymptotic time complexity to find an element in the linked list?

a) O(1)

b) O(n)

c) O(n2)

d) O(n4)

51. What would be the asymptotic time complexity to insert an element at the second position in the
linked list?

a) O(1)

b) O(n)

c) O(n2)

d) O(n3)

52. The concatenation of two list can performed in O(1) time. Which of the following variation of linked
list can be used?
a) Singly linked list

b) Doubly linked list

c) Circular doubly linked list

d) Array implementation of list

53. Consider the following definition in c programming language

struct node

int data;

struct node * next;

typedef struct node NODE;

NODE *ptr;

54. 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));

55. 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

56. Linked lists are not suitable to for the implementation of?

a) Insertion sort

b) Radix sort
c) Polynomial manipulation

d) Binary search

57. Linked list is considered as an example of ___________ type of memory allocation.

a) Dynamic

b) Static

c) Compile time

d) Heap

58. In Linked List implementation, a node carries information regarding ___________

a) Data

b) Link

c) Data and Link

d) Node

59. Linked list data structure offers considerable saving in _____________

a) Computational Time

b) Space Utilization

c) Space Utilization and Computational Time

d) Speed Utilization

60. Which of the following points is/are not true about Linked List data structure when it is compared
with array?

a) Arrays have better cache locality that can make them better in terms of performance

b) It is easy to insert and delete elements in Linked List

c) Random access is not allowed in a typical implementation of Linked Lists

d) Access of elements in linked list takes less time than compared to arrays

61. 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

62. Which of the following sorting algorithms can be used to sort a random linked list with minimum
time complexity?

a) Insertion Sort

b) Quick Sort

c) Heap Sort

d) Merge Sort

63. Given pointer to a node X in a singly linked list. Only one pointer is given, pointer to head node is not
given, can we delete the node X from given linked list?

a) Possible if X is not last node

b) Possible if size of linked list is even

c) Possible if size of linked list is odd

d) Possible if X is not first node

64. You are given pointers to first and last nodes of a singly linked list, which of the following operations
are dependent on the length of the linked list?

a) Delete the first element

b) Insert a new element as a first element

c) Delete the last element of the list


d) Add a new element at the end of the list

65. How many children does a binary tree have?

a) 2

b) any number of children

c) 0 or 1 or 2

d) 0 or 1

66. 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

67. What must be the ideal size of array if the height of tree is ‘l’?

a) 2l-1

b) l-1

c) l

d) 2l

68. If the tree is not a complete binary tree then what changes can be made for easy access of children
of a node in the array?

a) every node stores data saying which of its children exist in the array

b) no need of any changes continue with 2w and 2w+1, if node is at i

c) keep a seperate table telling children of a node

d) use another array parallel to the array with tree

69. Consider a situation of writing a binary tree into a file with memory storage efficiency in mind, is
array representation of tree is good?
a) yes because we are overcoming the need of pointers and so space efficiency

b) yes because array values are indexable

c) No it is not efficient in case of sparse trees and remaning cases it is fine

d) No linked list representation of tree is only fine

70. What is the time complexity of pre-order traversal in the iterative fashion?

a) O(1)

b) O(n)

c) O(logn)

d) O(nlogn)

71. 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)

72. To obtain a prefix expression, which of the tree traversals is used?

a) Level-order traversal

b) Pre-order traversal

c) Post-order traversal

d) In-order traversal

73. 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

74. Consider the following data and specify which one is Preorder Traversal Sequence, Inorder and
Postorder sequences.

S1: N, M, P, O, Q

S2: N, P, Q, O, M

S3: M, N, O, P, Q

a) S1 is preorder, S2 is inorder and S3 is postorder

b) S1 is inorder, S2 is preorder and S3 is postorder

c) S1 is inorder, S2 is postorder and S3 is preorder

d) S1 is postorder, S2 is inorder and S3 is preorder

75. In postorder traversal of binary tree right subtree is traversed before visiting root.

a) True

b) False

76. What is the possible number of binary trees that can be created with 3 nodes, giving the sequence N,
M, L when traversed in post-order.

a) 15

b) 3

c) 5

d) 8

77. The post-order traversal of a binary tree is O P Q R S T. Then possible pre-order traversal will be
________

a) T Q R S O P

b) T O Q R P S

c) T Q O P S R

d) T Q O S P R
78. A binary search tree contains values 7, 8, 13, 26, 35, 40, 70, 75. Which one of the following is a valid
post-order sequence of the tree provided the pre-order sequence as 35, 13, 7, 8, 26, 70, 40 and 75?

a) 7, 8, 26, 13, 75, 40, 70, 35

b) 26, 13, 7, 8, 70, 75, 40, 35

c) 7, 8, 13, 26, 35, 40, 70, 75

d) 8, 7, 26, 13, 40, 75, 70, 35

79. Which of the following pair’s traversals on a binary tree can build the tree uniquely?

a) post-order and pre-order

b) post-order and in-order

c) post-order and level order

d) level order and preorder

80. A full binary tree can be generated using ______

a) post-order and pre-order traversal

b) pre-order traversal

c) post-order traversal

d) in-order traversal

81. The maximum number of nodes in a tree for which post-order and pre-order traversals may be equal
is ______

a) 3

b) 1

c) 2

d) any number

82. The steps for finding post-order traversal are traverse the right subtree, traverse the left subtree or
visit the current node.

a) True

b) False
83. The pre-order and in-order are traversals of a binary tree are T M L N P O Q and L M N T O P Q.
Which of following is post-order traversal of the tree?

a) L N M O Q P T

b) N M O P O L T

c) L M N O P Q T

d) O P L M N Q T

84. For a binary tree the first node visited in in-order and post-order traversal is same.

a) True

b) False

his set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Graph”.

85. Which of the following statements for a simple graph is correct?

a) Every path is a trail

b) Every trail is a path

c) Every trail is a path as well as every path is a trail

d) Path and trail have no relation

86. In the given graph identify the cut vertices.

data-structure-questions-answers-graph-q2

a) B and E

b) C and D

c) A and E

d) C and B

87. For the given graph(G), which of the following statements is true?

data-structure-questions-answers-graph-q3

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

88. What is the number of edges present in a complete graph having n vertices?

a) (n*(n+1))/2

b) (n*(n-1))/2

c) n

d) Information given is insufficient

89. The given Graph is regular.

data-structure-questions-answers-graph-q5

a) True

b) False

90. In a simple graph, the number of edges is equal to twice the sum of the degrees of the vertices.

a) True

b) False

View Answer

91. A connected planar graph having 6 vertices, 7 edges contains _____________ regions.

a) 15

b) 3

c) 1

d) 11

View Answer

92. If a simple graph G, contains n vertices and m edges, the number of edges in the Graph
G'(Complement of G) is ___________
a) (n*n-n-2*m)/2

b) (n*n+n+2*m)/2

c) (n*n-n-2*m)/2

d) (n*n-n+2*m)/2

93. Which of the following properties does a simple graph not hold?

a) Must be connected

b) Must be unweighted

c) Must have no loops or multiple edges

d) Must have no multiple edges

94. What is the maximum number of edges in a bipartite graph having 10 vertices?

a) 24

b) 21

c) 25

d) 16

95. Which of the following is true?

a) A graph may contain no edges and many vertices

b) A graph may contain many edges and no vertices

c) A graph may contain no edges and no vertices

d) A graph may contain no vertices and many edges

96. 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
97. Which of the following statements for a simple graph is correct?

a) Every path is a trail

b) Every trail is a path

c) Every trail is a path as well as every path is a trail

d) Path and trail have no relation

98. In the given graph identify the cut vertices.

data-structure-questions-answers-graph-q2

a) B and E

b) C and D

c) A and E

d) C and B

View Answer

99. For the given graph(G), which of the following statements is true?

data-structure-questions-answers-graph-q3

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

View Answer

100. What is the number of edges present in a complete graph having n vertices?

a) (n*(n+1))/2

b) (n*(n-1))/2

c) n

d) Information given is insufficient


101. The given Graph is regular.

data-structure-questions-answers-graph-q5

a) True

b) False

102. In a simple graph, the number of edges is equal to twice the sum of the degrees of the vertices.

a) True

b) False

103. A connected planar graph having 6 vertices, 7 edges contains _____________ regions.

a) 15

b) 3

c) 1

d) 11

104 If a simple graph G, contains n vertices and m edges, the number of edges in the Graph
G'(Complement of G) is ___________

a) (n*n-n-2*m)/2

b) (n*n+n+2*m)/2

c) (n*n-n-2*m)/2

d) (n*n-n+2*m)/2

105. Which of the following properties does a simple graph not hold?

a) Must be connected

b) Must be unweighted

c) Must have no loops or multiple edges

d) Must have no multiple edges


106. What is the maximum number of edges in a bipartite graph having 10 vertices?

a) 24

b) 21

c) 25

d) 16

107. Which of the following is true?

a) A graph may contain no edges and many vertices

b) A graph may contain many edges and no vertices

c) A graph may contain no edges and no vertices

d) A graph may contain no vertices and many edges

108. 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

109. 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)

110. 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

You might also like