Stack Flashcards

1
Q

What is a stack in C++?

A

A stack is a data structure that follows the Last In First Out (LIFO) principle.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which C++ standard library provides stack functionality?

A

The <stack> library provides stack functionality in C++.</stack>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

True or False: A stack can be implemented using a linked list.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the primary operation for adding an element to a stack?

A

The primary operation is called ‘push’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the primary operation for removing an element from a stack?

A

The primary operation is called ‘pop’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Fill in the blank: In a stack, the top element can be accessed using the ______ operation.

A

top

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the time complexity of the push operation in a stack implemented using a linked list?

A

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does ‘infix’ notation refer to?

A

Infix notation is a mathematical notation where operators are placed between operands.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In the context of expressions, what is ‘postfix’ notation?

A

Postfix notation is a mathematical notation where operators follow their operands.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the purpose of converting an infix expression to postfix?

A

The purpose is to eliminate the need for parentheses and operator precedence rules during evaluation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which algorithm is commonly used to convert infix expressions to postfix?

A

The Shunting Yard algorithm.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

True or False: A stack is used to check for balanced parentheses in an expression.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the condition to check for balanced parentheses using a stack?

A

Every opening parenthesis must have a corresponding closing parenthesis, and they must be in the correct order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What happens if a closing parenthesis is encountered without a matching opening parenthesis?

A

The expression is considered unbalanced.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What data structure is typically used to implement a stack?

A

A linked list or an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the function of ‘top()’ in stack operations?

A

The ‘top()’ function returns the element at the top of the stack without removing it.

17
Q

Fill in the blank: The stack is often used in ______ algorithms.

18
Q

What does it mean if a stack is empty?

A

It means there are no elements in the stack.

19
Q

What is the time complexity of the pop operation in a stack?

20
Q

True or False: You can access elements in a stack randomly.

21
Q

What is the purpose of the ‘size()’ function in stack operations?

A

The ‘size()’ function returns the number of elements currently in the stack.

22
Q

What is the output of converting the infix expression ‘A + B * C’ to postfix?

23
Q

True or False: A stack can dynamically grow and shrink in size.

24
Q

What is a common application of stacks in programming?

A

Function call management and expression evaluation.

25
What do you call the structure that contains both the data and a pointer to the next node in a linked list stack?
A node.
26
What is the result of the postfix expression 'AB+C*' if A=2, B=3, and C=4?
20.