What is a stack? Write down any two applications of it.
2025
What is a stack? Write down any two applications of it.
Show answer & explanation
Concept
A stack is a linear data structure in which insertion and deletion take place at the same end, called the top.
It follows the Last-In, First-Out (LIFO) principle: the element inserted most recently is removed first. The basic operations are push (insert), pop (remove), and peek/top (inspect).
Application
Function calls and recursion: each call pushes an activation record containing the return address, parameters, and local state. When a function returns, its record is popped, so nested calls unwind in reverse order.
Expression and delimiter processing: compilers and calculators use stacks for infix-to-postfix conversion and expression evaluation; parsers push opening brackets and pop them when matching closing brackets appear.
Cross-check
Both examples obey LIFO: the most recent unfinished function returns first, and the most recently opened unmatched bracket must close first.
Therefore, a stack is a LIFO structure, and function-call management and expression or delimiter processing are two valid applications.