Sample questions
Question 1Medium
The postfix equivalent of the prefix * + a b - c d is
- ab+cd-*
- ab cd + - *
- ab + cd * -
- ab + - cd *
Answer: A. ab+cd-*
Explanation
The tree whose preorder traversal yields * + A B - C D, is given in fig 6.18. Writer the post-order traversal of the tree. That is the postfix form.
Step-by-step solution
- Prefix expression is * + a b - c d.
- Convert to infix: (a + b) * (c - d).
- Postfix of (a + b) is ab+
- Postfix of (c - d) is cd-
- Combine both postfixes with : ab+cd-.
Why the other options are wrong
- B. Incorrect order of operations and parentheses placement.
- C. Misplaced multiplication operator after addition.
- D. Incorrect subtraction order and missing multiplication.
Tip: Convert prefix to infix first, then apply postfix rules.
Question 2Medium
Which of the following name does not relate to stacks?
- FIFO lists
- LIFO list
- Piles
- Push-down lists
Answer: A. FIFO lists
Explanation
FIFO is concept of Queue. LIFO(Last In First Out) is concept of Stack.
Items are added to and removed from the top of the stack (the most recently added items are at the top of the stack). The last item to be added is the first to be removed (LIFO: Last In, First Out).
Step-by-step solution
- FIFO stands for First In First Out, which is a queue concept.
- Stacks use LIFO (Last In First Out) principle.
- Piles and Push-down lists are synonyms for stacks.
- FIFO lists do not relate to stacks.
Why the other options are wrong
- B. LIFO is the core principle of stacks.
- C. Piles are another name for stacks.
- D. Push-down lists are synonymous with stacks.
Tip: Remember: Stacks = LIFO; Queues = FIFO.
Question 3Medium
The data structure which is one ended is ....
- queue
- stack
- tree
- graph
Answer: B. stack
Explanation
A stack is a basic data structure that can be logically thought as linear structure represented by a real physical stack or pile, a structure where insertion and deletion of items takes place at one end called top of the stack.
Step-by-step solution
- Stack allows operations only at one end called top.
- Insertion and deletion happen at the same end.
- Queue has two ends for insertion and deletion.
- Tree and graph have multiple connections.
- So, stack is one ended.
Why the other options are wrong
- A. Queue has both ends for operations.
- C. Tree has multiple branches and nodes.
- D. Graph has multiple edges and vertices.
Tip: Remember stack is one ended, queue is two ended.
Question 4Medium
Which one of the following permutations can be obtained the output using stack assuming that the input is the sequence 1,2,3,4,5 in that order?
- 3,4,5,1,2
- 3,4,5,2,1
- 1,5,2,3,4
- 5,4,3,1,2
Answer: B. 3,4,5,2,1
Explanation
As it can be verified as- push(1) push(2) push(3) pop push(4) pop push(5) pop pop pop
Step-by-step solution
- Push 1, 2, 3 and pop 3.
- Push 4, pop 4. Push 5, pop 5.
- Now pop 2, then pop 1.
- That gives 3,4,5,2,1, so option B is correct.
Why the other options are wrong
- A. After 5 is popped, the top is 2, so 1 cannot come next.
- C. After 1 and 5 come out, 4 must come out before 2.
- D. After 3 is popped, 2 is above 1, so 1 cannot come before 2.
Tip: Stack output is last in first out: check the top element after each pop.
Question 5Medium
Which of the following is an application of stack?
- finding factorial
- tower of Hanoi
- infix to postfix conversion
- all of the above
Answer: D. all of the above
Explanation
The Tower of Hanoi (also called the Tower of Brahma or Lucas' Tower,[1] and sometimes pluralised) is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.
The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1.Only one disk can be moved at a time.
2.Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
3.No disk may be placed on top of a smaller disk.
With three disks, the puzzle can be solved in seven moves. The minimum number of moves required to solve a Tower of Hanoi puzzle is 2n - 1, where n is the number of disks.
Step-by-step solution
- A stack is used for recursion and for reversing or matching operators.
- Factorial uses recursion, and the Tower of Hanoi is solved by recursion, which uses a stack.
- Infix to postfix conversion uses an operator stack.
- All three are stack applications, so the answer is option D.
Why the other options are wrong
- A. Factorial is a stack use, but it is only one of the three; the full answer is all of the above.
- B. Tower of Hanoi is a stack use, but it is only one of the three; the full answer is all of the above.
- C. Infix to postfix is a stack use, but it is only one of the three; the full answer is all of the above.
Tip: If 'all of the above' is an option, check every listed item; if each is true, it is the answer.
Question 6Medium
The term "push" and "pop" is related to the
- array
- lists
- stacks
- all of above
Answer: C. stacks
Explanation
PUSH is used for inserting an element into the stack and POP is used for deleting an elements from the stack.
Step-by-step solution
- PUSH adds an item to the top of a stack.
- POP removes an item from the top of a stack.
- These operations are specific to stacks only.
- Arrays and lists do not have dedicated PUSH and POP functions.
- Thus, PUSH and POP relate only to stacks.
Why the other options are wrong
- A. Arrays use indexes for insertion and deletion, not PUSH/POP.
- B. Lists use append/remove methods, not PUSH/POP.
Tip: Remember: PUSH and POP are unique to stacks in data structures.
Question 7Medium
Which is/are the application(s) of stack
- Function calls
- Large number Arithmetic
- Evaluation of arithmetic expressions
- All of the above
Answer: D. All of the above
Explanation
A stack is used in function calls to manage return addresses and local variables. It is also used in evaluating arithmetic expressions and performing large number arithmetic. Therefore, all the given options are applications of a stack.
Step-by-step solution
- Function calls are a stack application.
- Large number arithmetic and evaluation of arithmetic expressions are also listed as stack applications.
- Each option is a stack application, so the correct answer is option D, All of the above.
Why the other options are wrong
- A. Function calls are a correct application, but 'All of the above' covers it and the others.
- B. Large number arithmetic is a correct application, but it is not the full answer.
- C. Expression evaluation is a correct application, but it is not the full answer.
Tip: When 'All of the above' is an option and every listed item is true, choose it.
Question 8Medium
In eveluating the arithmetic expression 2*3-(4+5),using stacks to evaluate its equivalent postfix form, which of the following stack configuration is not possible?
- 4 6
- 5 4 6
- 9 6
- 9 3 2
Answer: D. 9 3 2
Explanation
The postfix form is 2 3 * 4 5 + -. After 2 and 3 are pushed, * pops both and pushes 6, so 2 and 3 can never sit in the stack together with 9. Option D is therefore not possible.
Step-by-step solution
- Postfix form of 2*3-(4+5) is 2 3 * 4 5 + -.
- Scan left to right: push operands; on an operator, pop two, apply it, and push the result.
- Stack after each token, bottom to top: [2], [2 3], [6], [6 4], [6 4 5], [6 9], [-3].
- Option D (9 3 2, read top first) needs 9 above 3 and 2, but 9 never sits above 3 and 2. It is not possible. Marked answer: option D.
Why the other options are wrong
- A. '4 6' (top first) is the stack [6, 4] after pushing 4 onto 6, which does occur.
- B. '5 4 6' is the stack [6, 4, 5] after pushing 5, which does occur.
- C. '9 6' is the stack [6, 9] after the + step, which does occur.
Tip: Trace the postfix expression with a stack; any configuration that never appears in the trace is the impossible one.
Question 9Medium
---- is very useful in situation when data have to stored and then retrieved in reverse order.
- Stack
- Queue
- List
- Link list
Answer: A. Stack
Explanation
Stack is an ordered group of homogeneous items. Items are added to and removed from the top of the stack (the most recently added items are at the top of the stack). The last item to be added is the first to be removed (LIFO: Last In, First Out). A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted at one end called the TOP of the stack
Step-by-step solution
- Data that must come back in reverse order is handled last in, first out (LIFO).
- A stack adds and removes items only at its top, so the last item in is the first out.
- A queue returns items in the order they arrived, not in reverse.
- So the correct answer is option A, Stack.
Why the other options are wrong
- B. A queue returns items in the order they arrived, not in reverse.
- C. A list does not by itself give reverse order.
- D. A linked list does not by itself give reverse order; a stack does.
Tip: Reverse order means LIFO, so think stack.
Question 10Medium
- Last in first out
- First in last out
- Last in last out
- First in first out
Answer: A. Last in first out
Explanation
If you always take the job on top, you are following a Last-In-First-Out principle (LIFO for short): Always take the job that has been in the pile for the shortest period of time. A data structure that implements this principle is called a stack. However, this principle may not be appropriate for a job-pile; some jobs may sit on the bottom of the stack for days.
Step-by-step solution
- A stack always removes the most recently added item first.
- That principle is Last In, First Out (LIFO).
- Marked answer: Last in first out (option A).
Why the other options are wrong
- B. 'First in last out' is not a standard principle.
- C. 'Last in last out' is not a stack rule.
- D. 'First in first out' describes a queue, not a stack.
Tip: Stack is LIFO; queue is FIFO.
Practise all 10 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →