### Data Structures - MCQs from AMIE exams (Winter 2018)

1. Time complexity of insertion sort algorithm in the best case is
(a) O(n)
(b) O(n log2n)
(c) O(n2)
(d) None of the above

2. The prefix equivalent of the following infix expression is:
a/b – c + d * e – a * c
(a) - + - / a b c * d e * a c
(b) - - + / a b c * d e * a c
(c) + - - / a b c * d e * a c
(d) None of the above

3. In linked list representation, a node contains at least
(a) Node address field, data field
(b) Node number, data field
(c) Next address field, information field
(d) None of the above

4. The following sequence of operations is performed on a stack
push(1) push(2), pop, push(1), push(2), pop, pop, pop, push(2), pop.
The sequences of popped out values are
(a) 2, 2, 1, 2, 1
(b) 2, 2, 1, 1, 2
(c) 2, 1, 2, 2, 1
(d) 2, 1, 2, 2, 2

5. For the following statement find the values generated for p and q?
int p = 0, q = 1;
p = q++;
p = ++q;
p = q--;
p = --q;
The value of p & q is
(a) 1 1
(b) 0 0
(c) 3 2
(d) 1 2

6. The break statement causes an exit
(a) Only from the innermost loop
(b) Only from the innermost switch
(c) From the innermost loop or the switch
(d) None of the above

7. The && and || operators
(a) Compare two numeric values
(b) Combine two numeric values
(c) Compare two Boolean values
(d) Combine two Boolean values

8. Infix expression can be converted to postfix expression using a data structure called
(a) Stack
(b) Queue
(c) Both Stack and Queue
(d) None of the above

9. The number of swappings needed to sort the numbers 8, 22, 7, 9, 31, 5, 13 in ascending order, using bubble sort is
(a) 11
(b) 12
(c) 13
(d) 10

10. An ordered set of items from which items may be deleted at either end and into which items may be inserted at either end is called
(a) Queue
(b) Stack
(c) Heap
(d) Deque

1. (a)

2. (a)  Algorithm for conversion from prefix to infix:
STEP 1: Start scanning the expression from RHS. Push the operators on the top of the stack by ensuring that only high priority operator can be pushed over a low priority operator.

STEP 2: If a low priority operator is encountered in expression and if the top of the stack is a high priority operator, then pop it and after that push the low priority operator on the top of the stack.

STEP 3: Print each operand.

Given expression is : a/b – c + d * e – a * c
⇒ /ab-c+d*e-a*c
⇒ -/abc+d*e-a*c
⇒ +-/abcd*e-a*c
⇒ +-/abc*de-a*c
⇒ +-/abc*de-*ac
⇒ -+-/abc*de*ac

3. (c)

4. (b) The pop sequence can be seen in the following table:

5. (a)

6. (c)

7. (d) Logical operators are used to combine and evaluating boolean expressions.
&& called Logical AND operator. If both the operands are non-zero, then the condition becomes true.
|| called Logical OR Operator. If any of the two operands are non-zero, then the condition becomes true.

8. (a) The conversion of infix notation to postfix notation is done by using Stack.
Infix Expression is in form <Operand><Operator><Operand>, Eg: A + B
Postfix Expression is in form <Operand><Operand><Operator>, Eg: AB+

9. (d) Bubble sort repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass of the list is repeated until no swaps are needed, which indicates that the list is sorted.

Array elements: 8, 22, 7, 9, 31, 5, 13
1st pass = 8, 7, 9, 22, 5, 13, 31
4 swaps

2nd pass = 7, 8, 9, 5, 13, 22, 31
3 swaps

3rd pass = 7, 8, 5, 9, 13, 22, 31
1 swap

4th pass = 7, 5, 8, 9, 13, 22, 31
1 swap

5th pass = 5, 7, 8, 9, 13, 22, 31
1 swap

Since the array is sorted after the 5th pass
∴ no further swaps are possible.

Total number of swaps = 4 + 3 + 1 + 1 + 1 = 10

10. (d) A deque (pronounced deck) is an ordered set of items from which items may be deleted at either end and into which items may be inserted at either end.  In a sense, this hybrid linear structure provides all the capabilities of stacks and queues in a single data structure.

It is important to note that even though the deque can assume many of the characteristics of stacks and queues, it does not require the LIFO and FIFO orderings that are enforced by those data structures. It is up to you to make consistent use of the addition and removal operations.

---
• The study material for AMIE/B Tech/Junior Engineer exams is available at https://amiestudycircle.com
• If you like the post please share your thoughts in the comment section