Data Structure MCQ Questions
Data Structure MCQ Questions
Answer: b
Explanation: Array contains elements only of the same type.
Answer: c
Explanation: This is the syntax to initialize an array in C.
Answer: c
Explanation: The syntax to declare multidimensional array in java is
either int[][] arr; or int arr[][];
a) 3 and 5
b) 5 and 3
c) 2 and 4
d) 4 and 2
View Answer
Answer: a
Explanation: Array indexing starts from 0.
a) 4
b) 5
c) ArrayIndexOutOfBoundsException
d) InavlidInputException
View Answer
7. When does the ArrayIndexOutOfBoundsException occur?
a) Compile-time
b) Run-time
c) Not an error
d) Not an exception at all
View Answer
Answer: b
Explanation: ArrayIndexOutOfBoundsException is a run-time
exception and the compilation is error-free.
Answer: d
Explanation: Whenever a particular memory location is referred, it is
likely that the locations nearby are also referred, arrays are stored as
contigous blocks in memory, so if you want to access array elements,
spatial locality makes it to access quickly.
Answer: d
Explanation: Arrays stores elements of same data type and present in
continuous memory locations.
Answer: b
Explanation: Arrays are of fixed size. If we insert elements less than
the allocated size, unoccupied positions can’t be used again. Wastage
will occur in memory.
Answer: d
Explanation: Since there are 15 int elements and each int is of 4bytes,
we get 15*4 = 60bytes.
Answer: a
Explanation: In general, Array Indexing starts from 0. Thus, the index
of the first element in an array is 0.
Answer: b
Explanation: Push operation allows users to insert elements in stack.
If stack is filled completely and trying to perform push operation
stack – overflow can happen.
Answer: d
Explanation: Elements in stack are removed using pop operation. Pop
operation removes the top most element in the stack i.e. last entered
element.
Answer: a
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.
Answer: a
Explanation: The stack is filled with 5 elements and pushing one more
element causes a stack overflow. This results in overwriting memory,
code and loss of unsaved work on the computer.
Answer: d
Explanation: In stack data structure, elements are added one by one
using push operation. Stack follows LIFO Principle i.e. Last In First
Out(LIFO).
Answer: d
Explanation: Data transfer between the two asynchronous process
uses the queue data structure for synchronisation. The rest are all
stack applications.
7. 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
View Answer
Answer: c
Explanation: In the entire parenthesis balancing method when the
incoming token is a left parenthesis it is pushed into stack. A right
parenthesis makes pop operation to delete the elements in stack till we
get left parenthesis as top most element. 3 elements are there in stack
before right parentheses comes. Therefore, maximum number of
elements in stack at run time is 3.
Answer: b
Explanation: In the entire parenthesis balancing method when the
incoming token is a left parenthesis it is pushed into stack. A right
parenthesis makes pop operation to delete the elements in stack till we
get left parenthesis as top most element. 2 left parenthesis are pushed
whereas one right parenthesis removes one of left parenthesis. 2
elements are there before right parenthesis which is the maximum
number of elements in stack at run time.
9. What is the value of the postfix expression 6 3 2 4 + – *:
a) 1
b) 40
c) 74
d) -18
View Answer
Answer: d
Explanation: Postfix Expression is (6+(3-(2*4))) which results -18 as
output.
Answer: d
Explanation: When we perform the conversion from infix to postfix
expression +, *, (, * symbols are placed inside the stack. A maximum
of 4 symbols are identified during the entire conversion.
Answer: b
Expression: Two stacks are required for evaluation of infix expression
– one for operands and one for operators.
2. How many passes does the evaluation of infix expression algorithm
makes through the input?
a) One
b) Two
c) Three
d) Four
View Answer
Answer: a
Explanation: Evaluation of infix expression algorithm is linear and
makes only one pass through the input.
3. Identify the infix expression from the list of options given below.
a) a/b+(c-d)
b) abc*+d+ab+cd+*ce-f-
c) ab-c-
d) +ab
View Answer
Answer: a
Explanation: a/b+(c-d) is an infix expression since the operators are
placed in between the operands.
Answer: b
Explanation: If the precedence of the operator is higher than the stack
operator, then it is pushed on to the stack operator.
Answer: c
Explanation: According to precedence of operators, * is evaluated
first. + and – have equal priorities. Hence, 1+6-2= 5.
Answer: a
Explanation: During evaluation of infix expression, the operators with
higher precedence are evaluated first, followed by operators with
lower precedence.
7. Of the following choices, which operator has the lowest precedence?
a) ^
b) +
c) /
d) #
View Answer
Answer: d
Explanation: The operator with the lowest precedence is #, preceded by +, / and then ^.
Answer: b
Explanation: The algorithm holds good for infix expression with parentheses. The system
does not throw error.
Answer: b
Explanation: * and / have higher priority. Hence, they are evaluated first. Then, + is
evaluated. Hence, 2+2=4.
10. Evaluate the following statement using infix evaluation algorithm and choose the correct
answer. 4*2+3-5/5
a) 10
b) 11
c) 16
d) 12
View Answer
Answer: a
Explanation: 4*2 and 5/5 are evaluated first and then, 8+3-1 is evaluated and the result is
obtained as 10.
11. Using the evaluation of infix expression, evaluate a^b+c and choose the correct answer.
(a=2, b=2, c=2)
a) 12
b) 8
c) 10
d) 6
View Answer
Answer: d
Explanation: ^ has the highest precedence. Hence, 2^2 is evaluated and then 4+2 gives 6.
12. Evaluate the following infix expression using algorithm and choose the correct answer.
a+b*c-d/e^f where a=1, b=2, c=3, d=4, e=2, f=2.
a) 6
b) 8
c) 9
d) 7
View Answer
Answer: a
Explanation: ^ has the highest order of precedence. Hence, 2^2 is evaluated first, and then,
2*3 and 4/4 are evaluated. Therefore, 1+6-1=6.
13. From the given expression tree, identify the infix expression, evaluate it and choose the
correct result.
a) 5
b) 10
c) 12
d) 16
View Answer
Answer: c
Explanation: From the given expression tree, the result of the infix expression is evaluated to
be 12.