You are on page 1of 5

NPTEL Online Certification Courses

Indian Institute of Technology

Data Structure and Algorithms Using Java


Assignment 5
TYPE OF QUESTION: MCQ
Stack and Queue
______________________________________________________________________________

QUESTION 1:
Which of the following statements about a stack data structure is true?

a. Elements are removed from the front (or head) of the stack.
b. Elements are removed from the rear (or tail) of the stack.
c. The last element added to the stack is the first one to be removed.
d. The first element added to the stack is the first one to be removed.

Correct Answer: c

Detailed Solution:

The correct answer is C. In a stack data structure, the last element added (pushed) to the stack is the first
one to be removed (popped). This property is known as Last In, First Out (LIFO) order. Option A is
incorrect because stacks remove elements from the top, not the front. Option B is incorrect because stacks
remove elements from the top, not the rear. Option D is incorrect because stacks follow the LIFO order,
so the first element added is the last to be removed.
______________________________________________________________________________

QUESTION 2:
Which operation in a stack data structure can lead to an "underflow" condition?

a. Push
b. Pop
c. Peek.
d. Clear

Correct Answer: b

Detailed Solution:
The correct answer is B. An "underflow" condition in a stack occurs when attempting to pop an element
from an empty stack. In other words, trying to pop an element when the stack is already empty leads to
underflow. Options A, C, and D do not lead to an underflow condition. Pushing an element onto an empty
stack (Option A) will result in a non-empty stack, peeking (Option C) will retrieve the top element
without modifying the stack, and clearing (Option D) will empty the stack.
______________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology

QUESTION 3:

Which of the following applications is best suited for utilizing a stack data structure?

a. Implementing a queue for a printing system.


b. Storing the file system structure on a computer.
c. Evaluating arithmetic expressions.
d. Managing a sorted list of items.

Correct Answer: c

Detailed Solution:

The correct answer is C. A stack is commonly used to evaluate arithmetic expressions, where
operators and operands are pushed onto the stack and popped as the expression is processed. The
Last In, First Out (LIFO) nature of stacks helps maintain the correct order of operations. Option A
is incorrect because queues are better suited for implementing printing systems. Option B is
incorrect because file systems are typically organized as hierarchical structures, not stacks. Option
D is incorrect because managing a sorted list is better suited for other data structures like arrays or
linked lists, not stacks.

______________________________________________________________________________

QUESTION 4:

Which of the following expressions is correctly written in prefix notation?

a. 4 * 7 + 2.
b. +*472
c. *+472
d. 47*+2

Correct Answer: b

Detailed Solution:

The correct answer is B. In prefix notation, the expression "4 * 7 + 2" is written as "+ * 4 7 2".
The correct placement of the operator is before the operands. Option A is in infix notation.
Option C is a valid prefix expression, but it represents "* (4 + 7) 2" rather than "4 * 7 + 2".
Option D is not a valid prefix expression; it lacks the placement of the operators.
NPTEL Online Certification Courses
Indian Institute of Technology

Prefix notation requires that the operator comes before its operands, and the operands are read from left to
right. This notation is useful for evaluating expressions without the need for parentheses to indicate the
order of operations.
______________________________________________________________________________

QUESTION 5:

Evaluate the following arithmetic expression written in prefix notation:

+/*63284

a. 18
b. 24
c. 12
d. 15
Correct Answer: b

Detailed Solution:

The correct answer is B. Let's break down the expression step by step:

1. × 6 3 equals 18.
2. ÷ 18 2 equals 9.
3. + 9 8 equals 17.
4. + 17 4 equals 21.

So, the value of the given prefix expression is 21, which corresponds to option B.

______________________________________________________________________________

QUESTION 6:

Which of the following operations is NOT typically performed using a stack data structure?

a. Reversing a string.
b. Evaluating postfix expressions.
c. Searching for an element in an unsorted array.
d. Implementing a recursive algorithm.

Correct Answer: c
NPTEL Online Certification Courses
Indian Institute of Technology

Detailed Solution:
The correct answer is C. A stack is not typically used for searching elements in an unsorted array.
Stacks are commonly used for operations that involve Last In, First Out (LIFO) behavior, such as
reversing a string (Option A), evaluating postfix expressions (Option B), and implementing recursive
algorithms (Option D).
___________________________________________________________________________

QUESTION 7:
Which of the following statements represent "circular queue is full” condition an array is used to
implement a queue?

a. FRONT = 0
REAR = 0
b. FRONT = (REAR +1 MOD LENGTH)
c. CQ[FRONT] = ITEM
d. CQ[REAR] = ITEM

Correct Answer: b

Detailed Solution:
(a) represents condition for empty circular queue. (b) represent circular queue is full, since no
empty slot is available in the queue. © represents insertion in circular queue in case initially the
queue is empty. (d) represents insertion in circular queue in case queue is neither empty nor full.
___________________________________________________________________________

QUESTION 8:
When implementing a function to check for balanced parentheses in an expression, which data
structure is best suited for the task?

a. Queue
b. Linked List
c. Stack
d. Binary Tree.

Correct Answer: c
Detailed Solution:

The correct answer is C. A stack is the most suitable data structure for checking balanced
parentheses in an expression. As parentheses are encountered, they can be pushed onto the stack.
When encountering a closing parenthesis, you can pop the top element from the stack and check
if it matches the expected opening parenthesis. If the stack is empty at the end of processing, the
parentheses are balanced. Options A, B, and D are not well-suited for this task.

______________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology

QUESTION 9:

Consider a scenario where you need to reverse the order of elements in an array using a stack. Which
approach best describes the algorithm?

a. Push all elements onto the stack and then pop them back into the array.
b. Pop elements from the array and push them onto the stack.
c. Iterate through the array and swap elements from the beginning with elements from the end.
d. Create a new array and copy elements from the original array in reverse order.

Correct Answer: a

Detailed Solution:

The correct answer is A. The algorithm involves pushing all elements onto the stack first and then
popping them back into the original array. This process effectively reverses the order of elements.
Options B and C do not correctly describe the approach for using a stack. Option D involves
creating a new array, which is not required when using a stack to reverse the elements.

______________________________________________________________________________

QUESTION 10:
An array of size 15 whose index starts from 0 is used to implement a circular queue. Currently
FRONT is at index 10 and REAR is at index 14. At which index insertion of the next element would
take place?

a. 11
b. 10
c. 15
d. 0

Correct Answer: d

Detailed Solution:
Rear = (14+1) % 15
______________________________________________________________________________

You might also like