Algorithms and Data Structures · Junior · Question 19 of 75
Which task is a natural fit for a stack?
- 1Finding the shortest path in a road network
- 2Serving requests in the order they arrived
- ✓Correct answer: Checking that brackets in an expression are balanced
Explanation
Push every opening bracket; on a closing bracket pop and check that it matches. The last opened bracket must be closed first, which is exactly LIFO. Serving requests in order is a queue.