Stack Flashcards
What is a stack in C++?
A stack is a data structure that follows the Last In First Out (LIFO) principle.
Which C++ standard library provides stack functionality?
The <stack> library provides stack functionality in C++.</stack>
True or False: A stack can be implemented using a linked list.
True.
What is the primary operation for adding an element to a stack?
The primary operation is called ‘push’.
What is the primary operation for removing an element from a stack?
The primary operation is called ‘pop’.
Fill in the blank: In a stack, the top element can be accessed using the ______ operation.
top
What is the time complexity of the push operation in a stack implemented using a linked list?
O(1)
What does ‘infix’ notation refer to?
Infix notation is a mathematical notation where operators are placed between operands.
In the context of expressions, what is ‘postfix’ notation?
Postfix notation is a mathematical notation where operators follow their operands.
What is the purpose of converting an infix expression to postfix?
The purpose is to eliminate the need for parentheses and operator precedence rules during evaluation.
Which algorithm is commonly used to convert infix expressions to postfix?
The Shunting Yard algorithm.
True or False: A stack is used to check for balanced parentheses in an expression.
True.
What is the condition to check for balanced parentheses using a stack?
Every opening parenthesis must have a corresponding closing parenthesis, and they must be in the correct order.
What happens if a closing parenthesis is encountered without a matching opening parenthesis?
The expression is considered unbalanced.
What data structure is typically used to implement a stack?
A linked list or an array.
What is the function of ‘top()’ in stack operations?
The ‘top()’ function returns the element at the top of the stack without removing it.
Fill in the blank: The stack is often used in ______ algorithms.
recursive
What does it mean if a stack is empty?
It means there are no elements in the stack.
What is the time complexity of the pop operation in a stack?
O(1)
True or False: You can access elements in a stack randomly.
False.
What is the purpose of the ‘size()’ function in stack operations?
The ‘size()’ function returns the number of elements currently in the stack.
What is the output of converting the infix expression ‘A + B * C’ to postfix?
A B C * +
True or False: A stack can dynamically grow and shrink in size.
True.
What is a common application of stacks in programming?
Function call management and expression evaluation.