Explore topic-wise MCQs in Data Structures and Algorithms.

This section includes 161 Mcqs, each offering curated multiple-choice questions to sharpen your Data Structures and Algorithms knowledge and support exam preparation. Choose a topic below to get started.

1.

What does ‘stack underflow’ refer to?

A. accessing item from an undefined stack
B. adding items to a full stack
C. removing items from an empty stack
D. index out of bounds exception
Answer» D. index out of bounds exception
2.

If memory for the run-time stack is only 150 cells(words), how big can N be in Factorial(N) before stack overflow?

A. 12
B. 66
C. 60
D. 26
Answer» C. 60
3.

Expression1 * 2 ^ 3 * 4 ^ 5 * 6is evaluated as -

A. 32^30
B. 173458
C. 162^30
D. 49152
Answer» E.
4.

Which of the following permutations can be obtained in the output(in the same order),using a stack assuming that the input is the sequence 1,2,3,4,5 in that order?

A. 1,5,2,3,4
B. 3,4,5,2,1
C. 3,4,5,1,2
D. 5,4,3,2,1
Answer» C. 3,4,5,1,2
5.

An item that is read as input can be either pushed to a stack and later popped and printed, or printed directly. Which of the following will be the output if the input is the sequence of items 1, 2, 3, 4, 5 ?

A. 5 4 3 1 2
B. 3 4 5 1 2
C. 3 4 5 2 1
D. 1 5 2 3 4
Answer» D. 1 5 2 3 4
6.

The postfix equivalent of the prefix * + a b - c d is

A. ab+cd-*
B. ab + cd * -
C. ab + - cd *
D. ab cd + - *
Answer» B. ab + cd * -
7.

After performing these set of operations, what does the final list look contain?InsertFront(10);InsertFront(20);InsertRear(30);DeleteFront();InsertRear(40);InsertRear(10);DeleteRear();InsertRear(15);display();

A. 10 30 10 15
B. 20 30 40 15
C. 20 30 40 10
D. 10 30 40 15
Answer» E.
8.

Using Pop (S1,Item) ,Push(S1, Item), Getlist(Item), Pop(S2,Item), and the variables S1,S2(stacks with Top1 and Top2) and Item and given the input file: A,B,C,D,E,F Which stack are possible?

A. No possible stacks with A,B,C,D,E and F
B. All possible stacks with A,B,C,D,E and F
C. Twice as many stacks as can be produced with S1 alone
D. Exact and only those stacks which can be produced with S1 alone
Answer» B. All possible stacks with A,B,C,D,E and F
9.

A priority queue is used to implement a stack S that stores characters PUSH(C)is implemented as INSERT(Q,C,K)where K is an appropriate integer key chosen by the implementation.POP is implemented as DELETEMIN(Q)(Q). For a sequence of operations, the keys chosen are in

A. Non-increasing order
B. Non-decreasing order
C. Strictly increasing order
D. Strictly decreasing order
Answer» E.
10.

What will be the postfix form of the above expression -(A+B)∗(C∗D-E)∗F/G

A. A B + C D E ∗ − F G / ∗ ∗
B. A B + C D ∗ E − F G / ∗ ∗
C. A B + C D ∗ E − F G ∗ / ∗
D. None of these
Answer» C. A B + C D ∗ E − F G ∗ / ∗
11.

If the sequence of operations -push(1)push(2)poppush(1)push(2)poppoppoppush(2)popare performed on a stack, the sequence of popped out values are ?

A. 2 2 1 2 2
B. 2 2 1 1 2
C. 2 1 2 2 1
D. 2 1 2 2 2
Answer» C. 2 1 2 2 1
12.

Post fix form of following infix expression is -(A + B) * (C + D - E) * F

A. AB + CDE + - * F *
B. ABCDEF*-+*+
C. AB + CD - EF + - * *
D. AB + CD + E - * F *
Answer» B. ABCDEF*-+*+
13.

What does the following piece of code do?

A. Dequeue
B. Enqueue
C. Return the front element
D. None of the mentioned
Answer» D. None of the mentioned
14.

Which of the following represents a dequeue operation? (count is the number of elements in the queue)

A. a
B. b
C. c
D. d
Answer» B. b
15.

Select the appropriate code that inserts elements into the list based on the given key value.(head and trail are dummy nodes to mark the end and beginning of the list, they do not contain any priority or element)

A. a
B. b
C. c
D. d
Answer» B. b
16.

Using stacks, how to obtain the binary representation of the number?

A. a
B. b
C. c
D. d
Answer» D. d
17.

Which of the following code snippet is used to convert decimal to binary numbers?

A. a
B. b
C. c
D. d
Answer» B. b
18.

Select the code snippet which return true if the stack is empty, false otherwise.

A. a
B. b
C. c
D. d
Answer» E.
19.

Making the pop operation costly, select the code snippet which implements the same.

A. a
B. b
C. c
D. d
Answer» D. d
20.

Making the push operation costly, select the code snippet which implements the pop operation.

A. a
B. b
C. c
D. d
Answer» C. c
21.

Select the code snippet which returns the top of the stack.

A. a
B. b
C. c
D. d
Answer» D. d
22.

Which of the following best describes the growth of a linear queue at runtime? (Q is the original queue, size() returns the number of elements in the queue)

A. a
B. b
C. c
D. d
Answer» B. b
23.

Which of the following can be used to delete an element from the rear end of the queue?

A. a
B. b
C. c
D. None of the mentioned
Answer» D. None of the mentioned
24.

What is the output of the following piece of code?

A. 3 3
B. 3 6
C. 6 6
D. 10 6
Answer» B. 3 6
25.

Which of the following can be used to delete an element from the front end of the queue?

A. a
B. b
C. c
D. d
Answer» C. c
26.

Select the function which performs insertion at the front end of the dequeue?

A. a
B. b
C. c
D. d
Answer» B. b
27.

What is the functionality of the following piece of Java code?Assume: ‘a’ is a non empty array of integers, the Stack class creates an array of specified size and provides a top pointer indicating TOS(top of stack), push and pop have normal meaning.

A. print alternate elements of array
B. duplicate the given array
C. parentheses matching
D. reverse the array
Answer» E.
28.

Making the push operation costly, select the code snippet which implements the same.(let q1 and q2 be two queues)

A. a
B. b
C. c
D. d
Answer» B. b
29.

Given below is the Node class to perform basic list operations and a Stack class with a no arg constructor. Select from the options the appropriate push() operation that can be included in the Stack class. Also ‘first’ is the top-of-the-stack.

A. a
B. b
C. c
D. d
Answer» B. b
30.

What does the following function do?

A. pop
B. delete the top-of-the-stack element
C. retrieve the top-of-the-stack element
D. none of the mentioned
Answer» D. none of the mentioned
31.

Given below is the Node class to perform basic list operations and a Stack class with a no arg constructor.Select from the options the appropriate pop() operation that can be included in the Stack class. Also ‘first’ is the top-of-the-stack.

A. a
B. b
C. c
D. d
Answer» B. b
32.

What does the following function check for? (all necessary headers to be included and function is called from main)

A. full stack
B. invalid index
C. empty stack
D. infinite stack
Answer» D. infinite stack
33.

Stack can't be used to

A. Implement recursion
B. Evaluate an arithmetic expression in postfix form
C. Allocate resources(like CPU)by the operating system
D. Convert a given arithmetic expression in infix form to its evaluate postfix form
Answer» D. Convert a given arithmetic expression in infix form to its evaluate postfix form
34.

List of data in which element can be inserted and removed at the same end is called as __________.

A. List
B. Stack
C. Queue
D. Array
Answer» C. Queue
35.

Stack is useful for implementing

A. Radix
B. Recursion
C. Breadth first search
D. None of these
Answer» C. Breadth first search
36.

Process of Removing element from the stack is called as __________.

A. Push
B. Pop
C. Create
D. Postfix Expression
Answer» C. Create
37.

Consider Stack is implemented using the array. What will be the initial value with which top is initialized.

A. 0
B. -1
C. Garbage
D. 1
Answer» C. Garbage
38.

User push 1 element in the stack having already five elements and having stack size as 5 then stack becomes ___________.

A. Overflow
B. Underflow
C. User Flow
D. Crash
Answer» B. Underflow
39.

In the stack process of inserting an element in the stack is called as ___________.

A. Pop
B. Evaluation
C. Create
D. Push
Answer» E.
40.

Consider Stack is implemented using the array. In this implementation of stack maximum value of top which cannot cause overflow will _________.

A. 10
B. 9
C. 11
D. Any Other
Answer» C. 11
41.

Which of the following types of expressions do not require precedence rules for evaluation?

A. fully parenthesised infix expression
B. postfix expression
C. partially parenthesised infix expression
D. more than one of the above
Answer» B. postfix expression
42.

The data structure needed to convert a recursion to an iterative procedure is ............

A. Queue
B. Graph
C. Stack
D. Tree
Answer» D. Tree
43.

A data structure in which an element is added and removed only from one end, is known as

A. Queue
B. Stack
C. In-built structure
D. None of the above
Answer» C. In-built structure
44.

An infix expression can be converted to a postfix expression using a .................

A. Stack
B. Queue
C. Dequeue
D. None of these
Answer» B. Queue
45.

The postfix form of the following infix notation is : (A + B)* (C*D − E)* F

A. AB + CD*E − *F*
B. AB+ CDE + − * F*
C. AB+ CD − EF + − **
D. ABCDEF* − + * +
Answer» B. AB+ CDE + − * F*
46.

What happens when the stack is full and there is no space for a new element, and an attempt is made to push a new element?

A. Overflow
B. Underflow
C. Top
D. None of the above
Answer» B. Underflow
47.

What is one of the common examples of a stack?

A. A pile of books
B. Bus stop
C. A basket of fruits
D. A carat of eggs
Answer» B. Bus stop
48.

push() and pop() functions are found in ...............

A. queues
B. lists
C. stacks
D. trees
Answer» D. trees
49.

Which of the following is useful in the implementation of quick sort ?

A. List
B. Set
C. Queue
D. Stack
Answer» E.
50.

Which of the following is a collection of items into which items can be inserted arbitrarity and from which only the smallest item can be removed?

A. Fifo queue
B. Ascending priority queue
C. Descending priority queue
D. None of these
Answer» C. Descending priority queue